diff --git a/charms/worker/k8s/charmcraft.yaml b/charms/worker/k8s/charmcraft.yaml index 09ec05cf..0f685cc3 100644 --- a/charms/worker/k8s/charmcraft.yaml +++ b/charms/worker/k8s/charmcraft.yaml @@ -291,6 +291,16 @@ config: default: true description: | Enables or disables the network feature. + ingress-enabled: + type: boolean + default: false + description: | + Determines if the ingress feature should be enabled. + ingress-enable-proxy-protocol: + type: boolean + default: false + description: | + Determines if the proxy protocol should be enabled for ingresses. node-labels: default: "" type: string diff --git a/charms/worker/k8s/src/charm.py b/charms/worker/k8s/src/charm.py index e57809bc..edaaa0cf 100755 --- a/charms/worker/k8s/src/charm.py +++ b/charms/worker/k8s/src/charm.py @@ -41,6 +41,7 @@ CreateClusterRequest, DNSConfig, GatewayConfig, + IngressConfig, InvalidResponseError, JoinClusterRequest, K8sdAPIManager, @@ -439,6 +440,11 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: enabled=self.config.get("network-enabled"), ) + ingress = IngressConfig( + enabled=self.config.get("ingress-enabled"), + enable_proxy_protocol=self.config.get("ingress-enable-proxy-protocol"), + ) + metrics_server = MetricsServerConfig(enabled=self.config.get("metrics-server-enabled")) load_balancer = LoadBalancerConfig( @@ -462,6 +468,7 @@ def _assemble_cluster_config(self) -> UserFacingClusterConfig: cloud_provider=cloud_provider, dns_config=dns_config, gateway=gateway, + ingress=ingress, local_storage=local_storage, load_balancer=load_balancer, metrics_server=metrics_server, diff --git a/charms/worker/k8s/tests/unit/test_config_options.py b/charms/worker/k8s/tests/unit/test_config_options.py index 13bb4f49..7a12be6c 100644 --- a/charms/worker/k8s/tests/unit/test_config_options.py +++ b/charms/worker/k8s/tests/unit/test_config_options.py @@ -50,3 +50,25 @@ def test_configure_network_options(harness): harness.update_config({"network-enabled": True}) ufcg = harness.charm._assemble_cluster_config() assert ufcg.network.enabled, "Network should be enabled" + + +def test_configure_ingress_options(harness): + """Test configuring the ingress options. + + Args: + harness: the harness under test + """ + if harness.charm.is_worker: + pytest.skip("Not applicable on workers") + + harness.disable_hooks() + + enabled = True + proxy_protocol_enabled = True + + harness.update_config({"ingress-enabled": enabled}) + harness.update_config({"ingress-enable-proxy-protocol": proxy_protocol_enabled}) + + ufcg = harness.charm._assemble_cluster_config() + assert ufcg.ingress.enabled == enabled + assert ufcg.ingress.enable_proxy_protocol == proxy_protocol_enabled