Skip to content

Commit

Permalink
Modifications to get flatcar working
Browse files Browse the repository at this point in the history
* Move flatcar config spec into specialised define block
* generic osDistro variable to specify "flatcar" and future other OS
  • Loading branch information
Travis Holton committed Oct 25, 2023
1 parent 023a8f0 commit 8861213
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
8 changes: 8 additions & 0 deletions charts/openstack-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
44 changes: 44 additions & 0 deletions charts/openstack-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,15 @@ 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]
config_path = "/etc/containerd/certs.d"
owner: root:root
permissions: "0644"
append: true
{{- end }}
{{- with .Values.registryMirrors }}
{{- range $registry, $registrySpec := . }}
- path: /etc/containerd/certs.d/{{ $registry }}/hosts.toml
Expand Down Expand Up @@ -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: [email protected]
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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}

Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}}
Expand Down
4 changes: 4 additions & 0 deletions charts/openstack-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8861213

Please sign in to comment.