100 lines
3.4 KiB
YAML
Raw Normal View History

{{/*
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 }}
2021-08-26 10:40:10 +01:00
---
2021-11-17 10:02:06 +00:00
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
2021-08-26 10:40:10 +01:00
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
2021-08-26 10:40:10 +01:00
spec:
version: {{ .Values.global.kubernetesVersion | required ".Values.global.kubernetesVersion is required" }}
2021-08-26 10:40:10 +01:00
replicas: {{ .Values.controlPlane.machineCount }}
rolloutStrategy: {{ toYaml .Values.controlPlane.rolloutStrategy | nindent 4 }}
2021-08-26 10:40:10 +01:00
machineTemplate:
2021-09-06 10:23:43 +01:00
metadata:
labels: {{ include "openstack-cluster.componentSelectorLabels" (list . "control-plane") | nindent 8 }}
2021-08-26 10:40:10 +01:00
infrastructureRef:
kind: OpenStackMachineTemplate
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha6
2021-09-01 11:20:23 +01:00
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
}}