From 873c2637a2d0d43e416661c5a69918a14969e134 Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Sat, 20 Apr 2024 13:10:38 -0500 Subject: [PATCH] Bootstrap with bootstrapConfig -- including registerWithTaints and service-cidr (#43) --- charms/worker/k8s/charmcraft.yaml | 22 ++++++++++++++++++- .../k8s/lib/charms/k8s/v0/k8sd_api_manager.py | 2 ++ charms/worker/k8s/src/charm.py | 2 ++ tests/integration/data/test-bundle.yaml | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/charms/worker/k8s/charmcraft.yaml b/charms/worker/k8s/charmcraft.yaml index f83d801e..c2658e2e 100644 --- a/charms/worker/k8s/charmcraft.yaml +++ b/charms/worker/k8s/charmcraft.yaml @@ -67,7 +67,27 @@ config: type: string description: | Labels can be used to organize and to select subsets of nodes in the - cluster. Declare node labels in key=value format, separated by spaces. + cluster. Declare node labels in key=value format, separated by spaces. + register-with-taints: + type: string + default: "" + description: | + Space-separated list of taints to apply to this node at registration time. + + This config is only used at deploy time when Kubelet first registers the + node with Kubernetes. To change node taints after deploy time, use kubectl + instead. + + For more information, see the upstream Kubernetes documentation about + taints: + https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/ + service-cidr: + type: string + default: 10.152.183.0/24 + description: | + CIDR to use for Kubernetes services. After deployment it is + only possible to increase the size of the IP range. It is not possible to + change or shrink the address range after deployment. actions: get-kubeconfig: diff --git a/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py b/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py index 30adec05..27ef7cfa 100644 --- a/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py +++ b/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py @@ -298,6 +298,7 @@ class BootstrapConfig(BaseModel): Attributes: cluster_config (UserFacingClusterConfig): The cluster configuration settings. + control_plane_taints (List[str]): Register with the following control-plane taints pod_cidr (str): The IP address range for the cluster's pods. service_cidr (str): The IP address range for the cluster services. disable_rbac (bool): Flag to disable role-based access control @@ -312,6 +313,7 @@ class BootstrapConfig(BaseModel): """ cluster_config: Optional[UserFacingClusterConfig] = Field(None, alias="cluster-config") + control_plane_taints: Optional[List[str]] = Field(None, alias="control-plane-taints") pod_cidr: Optional[str] = Field(None, alias="pod-cidr") service_cidr: Optional[str] = Field(None, alias="service-cidr") disable_rbac: Optional[bool] = Field(None, alias="disable-rbac") diff --git a/charms/worker/k8s/src/charm.py b/charms/worker/k8s/src/charm.py index d06d0fca..46f4466f 100755 --- a/charms/worker/k8s/src/charm.py +++ b/charms/worker/k8s/src/charm.py @@ -233,6 +233,8 @@ def _bootstrap_k8s_snap(self): bootstrap_config = BootstrapConfig() self._configure_datastore(bootstrap_config) + bootstrap_config.service_cidr = self.config["service-cidr"] + bootstrap_config.control_plane_taints = self.config["register-with-taints"].split() bootstrap_config.extra_sans = [_get_public_address()] status.add(ops.MaintenanceStatus("Bootstrapping Cluster")) diff --git a/tests/integration/data/test-bundle.yaml b/tests/integration/data/test-bundle.yaml index ce060fce..dcc5710f 100644 --- a/tests/integration/data/test-bundle.yaml +++ b/tests/integration/data/test-bundle.yaml @@ -4,7 +4,7 @@ name: integration-test description: |- Used to deploy or refresh within an integration test model -series: jammy +series: focal applications: k8s: charm: k8s