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

provide support for the external-cloud-provider relation #307

Merged
merged 4 commits into from
Oct 30, 2023
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
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ requires:
# Indicates that the LB should not be public and should use internal
# networks if available. Intended for control plane and other internal use.
interface: loadbalancer
external-cloud-provider:
interface: external_cloud_provider
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
aiohttp>=3.7.4,<3.8.0
charm-lib-contextual-status @ git+https://github.com/charmed-kubernetes/charm-lib-contextual-status
charm-lib-interface-container-runtime @ git+https://github.com/charmed-kubernetes/charm-lib-interface-container-runtime
charm-lib-interface-external-cloud-provider @ git+https://github.com/charmed-kubernetes/charm-lib-interface-external-cloud-provider
charm-lib-interface-kube-dns @ git+https://github.com/charmed-kubernetes/charm-lib-interface-kube-dns
charm-lib-interface-kubernetes-cni @ git+https://github.com/charmed-kubernetes/charm-lib-interface-kubernetes-cni
charm-lib-kubernetes-snaps @ git+https://github.com/charmed-kubernetes/charm-lib-kubernetes-snaps
Expand Down
13 changes: 9 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from cdk_addons import CdkAddons
from charms import kubernetes_snaps
from charms.interface_container_runtime import ContainerRuntimeProvides
from charms.interface_external_cloud_provider import ExternalCloudProvider
from charms.interface_kube_dns import KubeDnsRequires
from charms.interface_kubernetes_cni import KubernetesCniProvides
from charms.kubernetes_libs.v0.etcd import EtcdReactiveRequires
Expand Down Expand Up @@ -46,6 +47,7 @@ def __init__(self, *args):
self.kube_dns = KubeDnsRequires(self, endpoint="dns-provider")
self.lb_external = LBProvider(self, "loadbalancer-external")
self.lb_internal = LBProvider(self, "loadbalancer-internal")
self.external_cloud_provider = ExternalCloudProvider(self, "external-cloud-provider")
self.reconciler = Reconciler(self, self.reconcile)

def api_dependencies_ready(self):
Expand Down Expand Up @@ -76,6 +78,7 @@ def configure_apiserver(self):
extra_args_config=self.model.config["api-extra-args"],
privileged=self.model.config["allow-privileged"],
service_cidr=self.model.config["service-cidr"],
external_cloud_provider=self.external_cloud_provider,
)

def configure_auth_webhook(self):
Expand Down Expand Up @@ -114,6 +117,7 @@ def configure_controller_manager(self):
extra_args_config=self.model.config["controller-manager-extra-args"],
kubeconfig="/root/cdk/kubecontrollermanagerconfig",
service_cidr=self.model.config["service-cidr"],
external_cloud_provider=self.external_cloud_provider,
)

def configure_kernel_parameters(self):
Expand All @@ -133,8 +137,7 @@ def configure_kube_control(self):
self.kube_control.set_dns_domain(dns_domain)
self.kube_control.set_dns_enabled(dns_enabled)
self.kube_control.set_dns_port(dns_port)
# TODO: external cloud provider support
self.kube_control.set_has_external_cloud_provider(False)
self.kube_control.set_has_external_cloud_provider(self.external_cloud_provider.has_xcp)
self.kube_control.set_image_registry(self.model.config["image-registry"])
# TODO: labels
self.kube_control.set_labels([])
Expand Down Expand Up @@ -163,6 +166,7 @@ def configure_kube_proxy(self):
extra_args_config=self.model.config["proxy-extra-args"],
extra_config=yaml.safe_load(self.model.config["proxy-extra-config"]),
kubeconfig="/root/cdk/kubeproxyconfig",
external_cloud_provider=self.external_cloud_provider,
)

def configure_kubelet(self):
Expand All @@ -172,7 +176,7 @@ def configure_kubelet(self):
dns_ip=self.get_dns_address(),
extra_args_config=self.model.config["kubelet-extra-args"],
extra_config=yaml.safe_load(self.model.config["kubelet-extra-config"]),
has_xcp=False, # TODO: cloud config
external_cloud_provider=self.external_cloud_provider,
kubeconfig="/root/cdk/kubeconfig",
node_ip=self.kube_control.ingress_addresses[0],
registry=self.model.config["image-registry"],
Expand Down Expand Up @@ -209,8 +213,9 @@ def configure_scheduler(self):

def create_kubeconfigs(self):
ca = self.certificates.ca
fqdn = self.external_cloud_provider.name == "aws"
local_server = self.k8s_api_endpoints.local()
node_name = kubernetes_snaps.get_node_name()
node_name = kubernetes_snaps.get_node_name(fqdn)
public_server = self.k8s_api_endpoints.external()

if not os.path.exists("/root/.kube/config"):
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ def test_active(
extra_args_config="",
privileged="auto",
service_cidr="10.152.183.0/24",
external_cloud_provider=harness.charm.external_cloud_provider,
)
configure_controller_manager.assert_called_once_with(
cluster_cidr="192.168.0.0/16",
cluster_name="test-cluster-name",
extra_args_config="",
kubeconfig="/root/cdk/kubecontrollermanagerconfig",
service_cidr="10.152.183.0/24",
external_cloud_provider=harness.charm.external_cloud_provider,
)
configure_kernel_parameters.assert_called_once_with(
{
Expand All @@ -170,7 +172,7 @@ def test_active(
dns_ip="10.152.183.10",
extra_args_config="",
extra_config={},
has_xcp=False,
external_cloud_provider=harness.charm.external_cloud_provider,
kubeconfig="/root/cdk/kubeconfig",
node_ip="10.0.0.10",
registry="rocks.canonical.com:443/cdk",
Expand All @@ -181,6 +183,7 @@ def test_active(
extra_args_config="",
extra_config={},
kubeconfig="/root/cdk/kubeproxyconfig",
external_cloud_provider=harness.charm.external_cloud_provider,
)
configure_scheduler.assert_called_once_with(
extra_args_config="", kubeconfig="/root/cdk/kubeschedulerconfig"
Expand Down