diff --git a/charms/worker/k8s/charmcraft.yaml b/charms/worker/k8s/charmcraft.yaml index 7e391562..09ec05cf 100644 --- a/charms/worker/k8s/charmcraft.yaml +++ b/charms/worker/k8s/charmcraft.yaml @@ -210,6 +210,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 6a94f591..e57809bc 100755 --- a/charms/worker/k8s/src/charm.py +++ b/charms/worker/k8s/src/charm.py @@ -45,6 +45,7 @@ JoinClusterRequest, K8sdAPIManager, K8sdConnectionError, + LoadBalancerConfig, LocalStorageConfig, MetricsServerConfig, NetworkConfig, @@ -440,6 +441,18 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: metrics_server = MetricsServerConfig(enabled=self.config.get("metrics-server-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" @@ -450,6 +463,7 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: dns_config=dns_config, gateway=gateway, local_storage=local_storage, + load_balancer=load_balancer, metrics_server=metrics_server, network=network, )