Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Load Balancer configuration through charm config #170

Merged
merged 7 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions charms/worker/k8s/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
addyess marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
8 changes: 4 additions & 4 deletions charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
JoinClusterRequest,
K8sdAPIManager,
K8sdConnectionError,
LoadBalancerConfig,
LocalStorageConfig,
NetworkConfig,
UnixSocketConnectionFactory,
Expand Down Expand Up @@ -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"
Expand All @@ -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]):
Expand Down
Loading