2022-10-12 16:30:17 +01:00

100 lines
3.4 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{/*
Produces the kubeadm config spec for a controlplane object, with support for the skipPhases
option of InitConfiguration and specifying a KubeProxyConfiguration.
*/}}
{{- define "openstack-cluster.controlplane.kubeadmConfigSpec" -}}
{{- $ctx := index . 0 }}
{{- $kubeadmConfigSpec := omit
(index . 1)
"initConfiguration"
"kubeProxyConfiguration"
"files"
"preKubeadmCommands"
}}
{{- $initConfiguration := omit (index . 1 | dig "initConfiguration" dict) "skipPhases" }}
{{- $skipPhases := index . 1 | dig "initConfiguration" "skipPhases" list }}
{{- $kubeProxyConfiguration := index . 1 | dig "kubeProxyConfiguration" dict }}
{{- $files := index . 1 | dig "files" list }}
{{- $preKubeadmCommands := index . 1 | dig "preKubeadmCommands" list }}
{{- if and $skipPhases (semverCompare "<1.22.0" $ctx.Values.global.kubernetesVersion) }}
{{- fail "skipPhases is only supported for Kubernetes 1.22 and higher" }}
{{- end }}
{{- with $kubeadmConfigSpec }}
{{- toYaml . }}
{{- end }}
{{- with $initConfiguration }}
initConfiguration: {{ toYaml $initConfiguration | nindent 2 }}
{{- end }}
{{- if or $files $skipPhases $kubeProxyConfiguration }}
files:
{{- range $files }}
- {{ toYaml . | nindent 4 }}
{{- end }}
{{- if $skipPhases }}
- path: /run/kubeadm/skip-phases.yaml
content: |
skipPhases: {{ toYaml $skipPhases | nindent 8 }}
owner: root:root
permissions: "0644"
{{- end }}
{{- with $kubeProxyConfiguration }}
- path: /run/kubeadm/kube-proxy-configuration.yaml
content: |
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
{{- toYaml . | nindent 6 }}
owner: root:root
permissions: "0644"
{{- end }}
{{- end }}
{{- if or $preKubeadmCommands $skipPhases $kubeProxyConfiguration }}
preKubeadmCommands:
{{- range $preKubeadmCommands }}
- {{ . }}
{{- end }}
{{- if $skipPhases }}
- cat /run/kubeadm/skip-phases.yaml >> /run/kubeadm/kubeadm.yaml
{{- end }}
{{- if $kubeProxyConfiguration }}
- cat /run/kubeadm/kube-proxy-configuration.yaml >> /run/kubeadm/kubeadm.yaml
{{- end }}
{{- end }}
{{- end }}
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
name: {{ include "openstack-cluster.componentName" (list . "control-plane") }}
labels: {{ include "openstack-cluster.componentLabels" (list . "control-plane") | nindent 4 }}
annotations:
# We let Cluster API clean up the cluster resources
# Deleting them ourselves, which CAPI is not expecting, can cause some nasty race conditions
helm.sh/resource-policy: keep
spec:
version: {{ .Values.global.kubernetesVersion | required ".Values.global.kubernetesVersion is required" }}
replicas: {{ .Values.controlPlane.machineCount }}
rolloutStrategy: {{ toYaml .Values.controlPlane.rolloutStrategy | nindent 4 }}
machineTemplate:
metadata:
labels: {{ include "openstack-cluster.componentSelectorLabels" (list . "control-plane") | nindent 8 }}
infrastructureRef:
kind: OpenStackMachineTemplate
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha6
name: {{ include "openstack-cluster.controlplane.mt.name" . }}
{{- with .Values.controlPlane.nodeDrainTimeout }}
nodeDrainTimeout: {{ . }}
{{- end }}
kubeadmConfigSpec: {{
include
"openstack-cluster.controlplane.kubeadmConfigSpec"
(list . .Values.controlPlane.kubeadmConfigSpec) |
fromYaml |
list . |
include "openstack-cluster.kubeadmConfigSpec" |
nindent 4
}}