From c31e3306b60931739f4b10b899a032b3e1326364 Mon Sep 17 00:00:00 2001 From: Benjamin Schimke Date: Mon, 18 Nov 2024 20:25:26 +0100 Subject: [PATCH 1/3] Add cluster config through charm config --- charms/worker/k8s/charmcraft.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/charms/worker/k8s/charmcraft.yaml b/charms/worker/k8s/charmcraft.yaml index c5b3ceab..ea2feee3 100644 --- a/charms/worker/k8s/charmcraft.yaml +++ b/charms/worker/k8s/charmcraft.yaml @@ -163,7 +163,6 @@ config: change or shrink the address range after deployment. local-storage-enabled: type: boolean - default: true description: | Enable local storage provisioning. This will create a storage class named "local-storage" that uses the hostPath provisioner. This is @@ -186,7 +185,6 @@ config: be retained when the PersistentVolumeClaim is deleted. gateway-enabled: type: boolean - default: false description: | Enable/Disable the gateway feature on the cluster. From 81d25f4d7d91e276a524ab8d140a5e488da670da Mon Sep 17 00:00:00 2001 From: Etienne Audet-Cobello Date: Mon, 18 Nov 2024 17:37:20 -0500 Subject: [PATCH 2/3] initial commit --- charms/worker/k8s/charmcraft.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/charms/worker/k8s/charmcraft.yaml b/charms/worker/k8s/charmcraft.yaml index ea2feee3..9b693b65 100644 --- a/charms/worker/k8s/charmcraft.yaml +++ b/charms/worker/k8s/charmcraft.yaml @@ -163,6 +163,7 @@ config: change or shrink the address range after deployment. local-storage-enabled: type: boolean + default: true description: | Enable local storage provisioning. This will create a storage class named "local-storage" that uses the hostPath provisioner. This is @@ -185,8 +186,25 @@ config: be retained when the PersistentVolumeClaim is deleted. gateway-enabled: type: boolean + default: false description: | Enable/Disable the gateway feature on the cluster. + load-balancer-enabled: + type: boolean + load-balancer-cidrs: + type: string + load-balancer-l2-mode: + type: bool + load-balancer-l2-interfaces: + type: string + load-balancer-bgp-mode: + type: bool + load-balancer-bgp-local-asn: + type: int + load-balancer-bgp-peer-address: + type: string + load-balancer-bgp-peer-port: + type: int actions: get-kubeconfig: From 2fcd4816fe3bb23bd0b53f1652558f5c8fc04cd3 Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Wed, 20 Nov 2024 17:01:48 -0600 Subject: [PATCH 3/3] Filled out the charmcraft with the features --- charms/worker/k8s/charmcraft.yaml | 36 +++++++++++++++++-- .../k8s/lib/charms/k8s/v0/k8sd_api_manager.py | 8 ++--- charms/worker/k8s/src/charm.py | 14 ++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/charms/worker/k8s/charmcraft.yaml b/charms/worker/k8s/charmcraft.yaml index 9b693b65..c122dec9 100644 --- a/charms/worker/k8s/charmcraft.yaml +++ b/charms/worker/k8s/charmcraft.yaml @@ -191,20 +191,52 @@ config: Enable/Disable the gateway feature on the cluster. load-balancer-enabled: type: boolean + default: false + description: | + Enable/Disable the load balancer feature on the cluster. load-balancer-cidrs: type: string + default: "" + description: | + Space-separated list of CIDRs to use for the load balancer. This is + only used if load-balancer-enabled is set to true. load-balancer-l2-mode: - type: bool + type: boolean + default: false + description: | + Enable/Disable L2 mode for the load balancer. This is only used if + load-balancer-enabled is set to true. load-balancer-l2-interfaces: type: string + default: "" + description: | + Space-separated list of interfaces to use for the load balancer. This + is only used if load-balancer-l2-mode is set to true. if unset, all + interfaces will be used. load-balancer-bgp-mode: - type: bool + type: boolean + default: false + description: | + Enable/Disable BGP mode for the load balancer. This is only used if + load-balancer-enabled is set to true. load-balancer-bgp-local-asn: type: int + default: 64512 + description: | + Local ASN for the load balancer. This is only used if load-balancer-bgp-mode + is set to true. load-balancer-bgp-peer-address: type: string + default: "" + description: | + Address of the BGP peer for the load balancer. This is only used if + load-balancer-bgp-mode is set to true. load-balancer-bgp-peer-port: type: int + default: 179 + description: | + Port of the BGP peer for the load balancer. This is only used if + load-balancer-bgp-mode is set to true. 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 6b0cf534..12234de1 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 @@ -230,9 +230,9 @@ class LoadBalancerConfig(BaseModel, allow_population_by_field_name=True): Attributes: enabled: Optional flag which represents the status of LoadBalancer. cidrs: List of CIDR blocks for the load balancer. - l2_enabled: Optional flag to enable or disable layer 2 functionality. + l2_mode: Optional flag to enable or disable layer 2 mode. l2_interfaces: List of layer 2 interfaces for the load balancer. - bgp_enabled: Optional flag to enable or disable BGP. + bgp_mode: Optional flag to enable or disable BGP. bgp_local_asn: The local ASN for BGP configuration. bgp_peer_address: The peer address for BGP configuration. bgp_peer_asn: The peer ASN for BGP configuration. @@ -241,9 +241,9 @@ class LoadBalancerConfig(BaseModel, allow_population_by_field_name=True): enabled: Optional[bool] = Field(default=None) cidrs: Optional[List[str]] = Field(default=None) - l2_enabled: Optional[bool] = Field(default=None, alias="l2-enabled") + l2_mode: Optional[bool] = Field(default=None, alias="l2-mode") l2_interfaces: Optional[List[str]] = Field(default=None, alias="l2-interfaces") - bgp_enabled: Optional[bool] = Field(default=None, alias="bgp-enabled") + bgp_mode: Optional[bool] = Field(default=None, alias="bgp-mode") bgp_local_asn: Optional[int] = Field(default=None, alias="bgp-local-asn") bgp_peer_address: Optional[str] = Field(default=None, alias="bgp-peer-address") bgp_peer_asn: Optional[int] = Field(default=None, alias="bgp-peer-asn") diff --git a/charms/worker/k8s/src/charm.py b/charms/worker/k8s/src/charm.py index 7794ac84..a7de170b 100755 --- a/charms/worker/k8s/src/charm.py +++ b/charms/worker/k8s/src/charm.py @@ -46,6 +46,7 @@ JoinClusterRequest, K8sdAPIManager, K8sdConnectionError, + LoadBalancerConfig, LocalStorageConfig, NetworkConfig, UnixSocketConnectionFactory, @@ -418,6 +419,18 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: enabled=self.config.get("gateway-enabled"), ) + load_balancer = LoadBalancerConfig( + enabled=self.config.get("load-balancer-enabled"), + cidrs=str(self.config.get("load-balancer-cidrs")).split(), + l2_mode=self.config.get("load-balancer-l2-mode"), + l2_interfaces=str(self.config.get("load-balancer-l2-interfaces")).split(), + bgp_mode=self.config.get("load-balancer-bgp-mode"), + bgp_local_asn=self.config.get("load-balancer-bgp-local-asn"), + bgp_peer_address=self.config.get("load-balancer-bgp-peer-address"), + bgp_peer_asn=self.config.get("load-balancer-bgp-peer-asn"), + bgp_peer_port=self.config.get("load-balancer-bgp-peer-port"), + ) + cloud_provider = None if self.xcp.has_xcp: cloud_provider = "external" @@ -427,6 +440,7 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: gateway=gateway, annotations=self._get_valid_annotations(), cloud_provider=cloud_provider, + load_balancer=load_balancer, ) def _configure_datastore(self, config: Union[BootstrapConfig, UpdateClusterConfigRequest]):