From 0d0e6becc4e0da5c418b702e010e4aaac4431e3b Mon Sep 17 00:00:00 2001 From: Stefan Chivu Date: Mon, 2 Oct 2023 11:24:34 +0000 Subject: [PATCH] Ignition driver --- devstack/contrib/new-devstack.sh | 3 +- magnum_capi_helm/driver.py | 105 +++++++++++++++++++++++++++++++ setup.cfg | 1 + 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/devstack/contrib/new-devstack.sh b/devstack/contrib/new-devstack.sh index 7a06756..5f8e692 100755 --- a/devstack/contrib/new-devstack.sh +++ b/devstack/contrib/new-devstack.sh @@ -209,11 +209,12 @@ sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl # Install Cluster API resources # using the matching tested values here: # https://github.com/stackhpc/capi-helm-charts/blob/main/dependencies.json +export EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION=true clusterctl init \ --core cluster-api:v1.5.1 \ --bootstrap kubeadm:v1.5.1 \ --control-plane kubeadm:v1.5.1 \ - --infrastructure openstack:v0.7.3 + --infrastructure openstack:v0.8.0 # Install addon manager helm upgrade cluster-api-addon-provider cluster-api-addon-provider \ diff --git a/magnum_capi_helm/driver.py b/magnum_capi_helm/driver.py index 336ed95..7884d71 100644 --- a/magnum_capi_helm/driver.py +++ b/magnum_capi_helm/driver.py @@ -769,3 +769,108 @@ def update_federation(self, context, federation): def delete_federation(self, context, federation): raise NotImplementedError("Will not implement 'delete_federation'") + + +class IgnitionDriver(Driver): + @property + def provides(self): + return [ + { + "server_type": "vm", + "os": "capi-kubeadm-ignition", + "coe": "kubernetes", + }, + ] + + def _update_helm_release(self, context, cluster, nodegroups=None): + # TODO(stefan-chivu) reorganize class structure to keep the code dry + if nodegroups is None: + nodegroups = cluster.nodegroups + + image_id, kube_version = self._get_image_details( + context, cluster.cluster_template.image_id + ) + + network_id = self._get_fixed_network_id(context, cluster) + subnet_id = neutron.get_fixed_subnet_id(context, cluster.fixed_subnet) + + values = { + "kubernetesVersion": kube_version, + "machineImageId": image_id, + "machineSSHKeyName": cluster.keypair or None, + "bootstrappingFormat": "ignition", + "cloudCredentialsSecretName": self._get_app_cred_name(cluster), + "apiServer": { + "enableLoadBalancer": True, + "loadBalancerProvider": self._label( + cluster, "octavia_provider", "amphora" + ), + }, + "clusterNetworking": { + "dnsNameservers": self._get_dns_nameservers(cluster), + "externalNetworkId": neutron.get_external_network_id( + context, cluster.cluster_template.external_network_id + ), + "internalNetwork": { + "networkFilter": ( + {"id": network_id} if network_id else None + ), + "subnetFilter": ({"id": subnet_id} if subnet_id else None), + # This is only used if a fixed network is not specified + "nodeCidr": self._label( + cluster, "fixed_subnet_cidr", "10.0.0.0/24" + ), + }, + }, + "controlPlane": { + "machineFlavor": cluster.master_flavor_id, + "machineCount": cluster.master_count, + }, + "nodeGroups": [ + { + "name": self._sanitized_name(ng.name), + "machineFlavor": ng.flavor_id, + "machineCount": ng.node_count, + } + for ng in nodegroups + if ng.role != NODE_GROUP_ROLE_CONTROLLER + ], + "addons": { + "monitoring": { + "enabled": self._get_monitoring_enabled(cluster) + }, + "kubernetesDashboard": { + "enabled": self._get_kube_dash_enabled(cluster) + }, + # TODO(mkjpryor): can't enable ingress until code exists to + # remove the load balancer + "ingress": {"enabled": False}, + }, + } + + # Sometimes you need to add an extra network + # for things like Cinder CSI CephFS Native + extra_network_name = self._label(cluster, "extra_network_name", "") + if extra_network_name: + values["nodeGroupDefaults"] = { + "machineNetworking": { + "ports": [ + {}, + { + "network": { + "name": extra_network_name, + }, + "securityGroups": [], + }, + ] + } + } + + self._helm_client.install_or_upgrade( + self._get_chart_release_name(cluster), + CONF.capi_helm.helm_chart_name, + values, + repo=CONF.capi_helm.helm_chart_repo, + version=self._get_chart_version(cluster), + namespace=self._namespace(cluster), + ) diff --git a/setup.cfg b/setup.cfg index 17c5fc8..6712c84 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,3 +28,4 @@ packages = [entry_points] magnum.drivers = k8s_capi_helm_v1 = magnum_capi_helm.driver:Driver + k8s_capi_ignition_helm_v1 = magnum_capi_helm.driver:IgnitionDriver