From 88612136c70c143555a95d3518b1ee6ba61898ee Mon Sep 17 00:00:00 2001 From: Travis Holton Date: Sun, 8 Oct 2023 06:48:53 +1300 Subject: [PATCH] Modifications to get flatcar working * Move flatcar config spec into specialised define block * generic osDistro variable to specify "flatcar" and future other OS --- charts/openstack-cluster/README.md | 8 ++++ .../openstack-cluster/templates/_helpers.tpl | 44 +++++++++++++++++++ .../control-plane/kubeadm-control-plane.yaml | 13 ++++-- .../node-group/kubeadm-config-template.yaml | 5 ++- charts/openstack-cluster/values.yaml | 4 ++ 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/charts/openstack-cluster/README.md b/charts/openstack-cluster/README.md index 9d1c73e1..7473e481 100644 --- a/charts/openstack-cluster/README.md +++ b/charts/openstack-cluster/README.md @@ -222,3 +222,11 @@ clusterctl get kubeconfig my-cluster > kubeconfig.my-cluster # Use that kubeconfig to list pods on the workload cluster kubectl --kubeconfig=./kubeconfig.my-cluster get po -A ``` + +## Flatcar + +To deploy clusters which use Ignition such as Flatcar, you will need to override the following setting in your local `values.yaml`: + +```yaml +osDistro: flatcar +``` diff --git a/charts/openstack-cluster/templates/_helpers.tpl b/charts/openstack-cluster/templates/_helpers.tpl index e29b3dae..e7773aa5 100644 --- a/charts/openstack-cluster/templates/_helpers.tpl +++ b/charts/openstack-cluster/templates/_helpers.tpl @@ -203,6 +203,7 @@ files: # This file is created by the capi-helm-chart to ensure that its parent directory exists owner: root:root permissions: "0644" +{{- if ne .Values.osDistro "flatcar" }} - path: /etc/containerd/config.toml content: | [plugins."io.containerd.grpc.v1.cri".registry] @@ -210,6 +211,7 @@ files: owner: root:root permissions: "0644" append: true +{{- end }} {{- with .Values.registryMirrors }} {{- range $registry, $registrySpec := . }} - path: /etc/containerd/certs.d/{{ $registry }}/hosts.toml @@ -275,3 +277,45 @@ Produces the spec for a KubeadmConfig object. include "openstack-cluster.mergeConcatMany" }} {{- end }} + +{{/* +Produces the spec for an Ignition based OS specific KubeadmConfig object conditional on osDistro set to "flatcar". +*/}} +{{- define "openstack-cluster.flatcarKubeadmConfigSpec" -}} +initConfiguration: + nodeRegistration: + name: ${COREOS_OPENSTACK_HOSTNAME} +joinConfiguration: + nodeRegistration: + name: ${COREOS_OPENSTACK_HOSTNAME} +preKubeadmCommands: + - export COREOS_OPENSTACK_HOSTNAME=${COREOS_OPENSTACK_HOSTNAME%.*} + - envsubst < /etc/kubeadm.yml > /etc/kubeadm.yml.tmp + - mv /etc/kubeadm.yml.tmp /etc/kubeadm.yml +format: ignition +ignition: + containerLinuxConfig: + additionalConfig: | + systemd: + units: + - name: coreos-metadata-sshkeys@.service + enabled: true + - name: kubeadm.service + enabled: true + dropins: + - name: 10-flatcar.conf + contents: | + [Unit] + Requires=containerd.service coreos-metadata.service + After=containerd.service coreos-metadata.service + [Service] + EnvironmentFile=/run/metadata/flatcar +{{- end }} + +{{- define "openstack-cluster.osDistroKubeadmConfigSpec" }} +{{- $ctx := index . 0 }} +{{- $osDistro := $ctx.Values.osDistro }} +{{- if eq $osDistro "flatcar" }} +{{- include "openstack-cluster.flatcarKubeadmConfigSpec" $ctx }} +{{- end }} +{{- end }} diff --git a/charts/openstack-cluster/templates/control-plane/kubeadm-control-plane.yaml b/charts/openstack-cluster/templates/control-plane/kubeadm-control-plane.yaml index 70458041..e13fe155 100644 --- a/charts/openstack-cluster/templates/control-plane/kubeadm-control-plane.yaml +++ b/charts/openstack-cluster/templates/control-plane/kubeadm-control-plane.yaml @@ -6,9 +6,13 @@ joinConfiguration: {{ include "openstack-cluster.nodeRegistration.nodeLabels" . {{- end }} {{- define "openstack-cluster.controlplane.kubeadmConfigSpec.kubeProxyConfiguration" -}} -{{- with .kubeProxyConfiguration }} +{{- $ctx := index . 0 }} +{{- $osDistro := index . 1 }} +{{- $kubeProxyConfigurationPath := ternary "/etc/kube-proxy-configuration.yaml" "/run/kubeadm/kube-proxy-configuration.yaml" (eq $osDistro "flatcar") }} +{{- $kubeadmPath := ternary "/etc/kubeadm.yml" "/run/kubeadm/kubeadm.yaml" (eq $osDistro "flatcar") }} +{{- with $ctx.kubeProxyConfiguration }} files: - - path: /run/kubeadm/kube-proxy-configuration.yaml + - path: {{ $kubeProxyConfigurationPath }} content: | --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 @@ -17,7 +21,7 @@ files: owner: root:root permissions: "0644" preKubeadmCommands: - - cat /run/kubeadm/kube-proxy-configuration.yaml >> /run/kubeadm/kubeadm.yaml + - cat {{ $kubeProxyConfigurationPath }} >> {{ $kubeadmPath }} {{- end }} {{- end }} @@ -53,7 +57,8 @@ spec: list (include "openstack-cluster.controlplane.kubeadmConfigSpec.nodeLabels" . | fromYaml) (include "openstack-cluster.kubeadmConfigSpec" (list . .Values.controlPlane.kubeadmConfigSpec) | fromYaml) - (include "openstack-cluster.controlplane.kubeadmConfigSpec.kubeProxyConfiguration" .Values.controlPlane.kubeadmConfigSpec | fromYaml) | + (include "openstack-cluster.osDistroKubeadmConfigSpec" (list . ) | fromYaml) + (include "openstack-cluster.controlplane.kubeadmConfigSpec.kubeProxyConfiguration" (list .Values.controlPlane.kubeadmConfigSpec .Values.osDistro) | fromYaml) | include "openstack-cluster.mergeConcatMany" | fromYaml ) diff --git a/charts/openstack-cluster/templates/node-group/kubeadm-config-template.yaml b/charts/openstack-cluster/templates/node-group/kubeadm-config-template.yaml index bf8d4a78..9ab2b61b 100644 --- a/charts/openstack-cluster/templates/node-group/kubeadm-config-template.yaml +++ b/charts/openstack-cluster/templates/node-group/kubeadm-config-template.yaml @@ -25,8 +25,9 @@ joinConfiguration: {{ include "openstack-cluster.nodeRegistration.nodeLabels" $n {{- list (include "openstack-cluster.nodegroup.kct.spec.nodeLabels" (list $ctx $nodeGroup) | fromYaml) - (include "openstack-cluster.kubeadmConfigSpec" (list $ctx $nodeGroup.kubeadmConfigSpec) | fromYaml) | - include "openstack-cluster.mergeConcat" | + (include "openstack-cluster.kubeadmConfigSpec" (list $ctx $nodeGroup.kubeadmConfigSpec) | fromYaml) + (omit (include "openstack-cluster.osDistroKubeadmConfigSpec" (list $ctx) | fromYaml) "initConfiguration") | + include "openstack-cluster.mergeConcatMany" | fromYaml | toYaml }} diff --git a/charts/openstack-cluster/values.yaml b/charts/openstack-cluster/values.yaml index 77c53fcc..78fbe738 100644 --- a/charts/openstack-cluster/values.yaml +++ b/charts/openstack-cluster/values.yaml @@ -119,6 +119,10 @@ apiServer: # The port to use for the API server port: 6443 + +# Set osDistro used. ubuntu, flatcar, etc. +osDistro: ubuntu + # Settings for the control plane controlPlane: # The failure domains to use for control plane nodes