From 109adea9128d75d9b3ca1b1595b3dc64aa339142 Mon Sep 17 00:00:00 2001 From: eaudetcobello Date: Fri, 22 Nov 2024 12:11:21 -0500 Subject: [PATCH] Add Load Balancer configuration through charm config (#170) * Add cluster config through charm config * initial commit * Filled out the charmcraft with the features --------- Co-authored-by: Benjamin Schimke Co-authored-by: Adam Dyess --- charms/worker/k8s/charmcraft.yaml | 48 +++++++++++++++++++ .../k8s/lib/charms/k8s/v0/k8sd_api_manager.py | 8 ++-- charms/worker/k8s/src/charm.py | 14 ++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/charms/worker/k8s/charmcraft.yaml b/charms/worker/k8s/charmcraft.yaml index 72b2b452..4746bec8 100644 --- a/charms/worker/k8s/charmcraft.yaml +++ b/charms/worker/k8s/charmcraft.yaml @@ -185,6 +185,54 @@ config: default: false description: | 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: 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: 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. local-storage-enabled: type: boolean default: true 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 39b03f25..6936b219 100755 --- a/charms/worker/k8s/src/charm.py +++ b/charms/worker/k8s/src/charm.py @@ -45,6 +45,7 @@ JoinClusterRequest, K8sdAPIManager, K8sdConnectionError, + LoadBalancerConfig, LocalStorageConfig, NetworkConfig, UnixSocketConnectionFactory, @@ -427,6 +428,18 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: enabled=self.config.get("network-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" @@ -437,6 +450,7 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: network=network, annotations=self._get_valid_annotations(), cloud_provider=cloud_provider, + load_balancer=load_balancer, ) def _configure_datastore(self, config: Union[BootstrapConfig, UpdateClusterConfigRequest]):