|
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "cluster-api-cluster.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 6 | +{{- end }} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Create a default fully qualified app name. |
| 10 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 11 | +If release name contains chart name it will be used as a full name. |
| 12 | +*/}} |
| 13 | +{{- define "cluster-api-cluster.fullname" -}} |
| 14 | +{{- if .Values.fullnameOverride }} |
| 15 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} |
| 16 | +{{- else }} |
| 17 | +{{- $name := default .Chart.Name .Values.nameOverride }} |
| 18 | +{{- if contains $name .Release.Name }} |
| 19 | +{{- .Release.Name | trunc 63 | trimSuffix "-" }} |
| 20 | +{{- else }} |
| 21 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} |
| 22 | +{{- end }} |
| 23 | +{{- end }} |
| 24 | +{{- end }} |
| 25 | + |
| 26 | +{{/* |
| 27 | +Create chart name and version as used by the chart label. |
| 28 | +*/}} |
| 29 | +{{- define "cluster-api-cluster.chart" -}} |
| 30 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
| 31 | +{{- end }} |
| 32 | + |
| 33 | +{{/* |
| 34 | +Common labels |
| 35 | +*/}} |
| 36 | +{{- define "cluster-api-cluster.labels" -}} |
| 37 | +helm.sh/chart: {{ include "cluster-api-cluster.chart" . }} |
| 38 | +{{ include "cluster-api-cluster.selectorLabels" . }} |
| 39 | +{{- if .Chart.AppVersion }} |
| 40 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 41 | +{{- end }} |
| 42 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 43 | +{{- end }} |
| 44 | + |
| 45 | +{{/* |
| 46 | +Selector labels |
| 47 | +*/}} |
| 48 | +{{- define "cluster-api-cluster.selectorLabels" -}} |
| 49 | +app.kubernetes.io/name: {{ include "cluster-api-cluster.name" . }} |
| 50 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 51 | +{{- end }} |
| 52 | + |
| 53 | +{{/* |
| 54 | +Create the name of the service account to use |
| 55 | +*/}} |
| 56 | +{{- define "cluster-api-cluster.serviceAccountName" -}} |
| 57 | +{{- if .Values.serviceAccount.create }} |
| 58 | +{{- default (include "cluster-api-cluster.fullname" .) .Values.serviceAccount.name }} |
| 59 | +{{- else }} |
| 60 | +{{- default "default" .Values.serviceAccount.name }} |
| 61 | +{{- end }} |
| 62 | +{{- end }} |
| 63 | + |
| 64 | +{{/* |
| 65 | +Creates the Kubernetes version for the cluster |
| 66 | +# TODO: this should actually be used to sanatize the `.Values.cluster.kubernetesVersion` value to what the providers support instead of defining these static versions |
| 67 | +*/}} |
| 68 | +{{- define "cluster.kubernetesVersion" -}} |
| 69 | +{{- if .Values.cluster.kubernetesVersion -}} |
| 70 | +{{ .Values.cluster.kubernetesVersion }} |
| 71 | +{{- else if eq .Values.provider "aws" -}} |
| 72 | +v1.24 |
| 73 | +{{- else if eq .Values.provider "azure" -}} |
| 74 | +v1.25.11 |
| 75 | +{{- else if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}} |
| 76 | +1.24.16 |
| 77 | +{{- else if eq .Values.provider "kind" -}} |
| 78 | +v1.25.11 |
| 79 | +{{- end }} |
| 80 | +{{- end }} |
| 81 | + |
| 82 | +{{/* |
| 83 | +Create the kind for the infrastructureRef for the cluster |
| 84 | +*/}} |
| 85 | +{{- define "cluster.infrastructure.kind" -}} |
| 86 | +{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}} |
| 87 | +AWSManagedCluster |
| 88 | +{{- end }} |
| 89 | +{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}} |
| 90 | +AzureManagedCluster |
| 91 | +{{- end }} |
| 92 | +{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}} |
| 93 | +GCPManagedCluster |
| 94 | +{{- end }} |
| 95 | +{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}} |
| 96 | +DockerCluster |
| 97 | +{{- end }} |
| 98 | +{{- end }} |
| 99 | + |
| 100 | +{{/* |
| 101 | +Create the apiVersion for the infrastructureRef for the cluster |
| 102 | +*/}} |
| 103 | +{{- define "cluster.infrastructure.apiVersion" -}} |
| 104 | +{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}} |
| 105 | +infrastructure.cluster.x-k8s.io/v1beta2 |
| 106 | +{{- end }} |
| 107 | +{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}} |
| 108 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 109 | +{{- end }} |
| 110 | +{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}} |
| 111 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 112 | +{{- end }} |
| 113 | +{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}} |
| 114 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 115 | +{{- end }} |
| 116 | +{{- end }} |
| 117 | + |
| 118 | +{{/* |
| 119 | +Create the kind for the controlPlaneRef for the cluster |
| 120 | +*/}} |
| 121 | +{{- define "cluster.controlPlane.kind" -}} |
| 122 | +{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}} |
| 123 | +AWSManagedControlPlane |
| 124 | +{{- end }} |
| 125 | +{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}} |
| 126 | +AzureManagedControlPlane |
| 127 | +{{- end }} |
| 128 | +{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}} |
| 129 | +GCPManagedControlPlane |
| 130 | +{{- end }} |
| 131 | +{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}} |
| 132 | +KubeadmControlPlane |
| 133 | +{{- end }} |
| 134 | +{{- end }} |
| 135 | + |
| 136 | +{{/* |
| 137 | +Create the apiVersion for the controlPlaneRef for the cluster |
| 138 | +*/}} |
| 139 | +{{- define "cluster.controlPlane.apiVersion" -}} |
| 140 | +{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}} |
| 141 | +controlplane.cluster.x-k8s.io/v1beta2 |
| 142 | +{{- end }} |
| 143 | +{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}} |
| 144 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 145 | +{{- end }} |
| 146 | +{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}} |
| 147 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 148 | +{{- end }} |
| 149 | +{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}} |
| 150 | +controlplane.cluster.x-k8s.io/v1beta1 |
| 151 | +{{- end }} |
| 152 | +{{- end }} |
| 153 | + |
| 154 | +{{/* |
| 155 | +Create the kind for the infrastructureRef for the worker MachinePools |
| 156 | +*/}} |
| 157 | +{{- define "workers.infrastructure.kind" -}} |
| 158 | +{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}} |
| 159 | +AWSManagedMachinePool |
| 160 | +{{- end }} |
| 161 | +{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}} |
| 162 | +AzureManagedMachinePool |
| 163 | +{{- end }} |
| 164 | +{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}} |
| 165 | +GCPManagedMachinePool |
| 166 | +{{- end }} |
| 167 | +{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}} |
| 168 | +DockerMachinePool |
| 169 | +{{- end }} |
| 170 | +{{- end }} |
| 171 | + |
| 172 | +{{/* |
| 173 | +Create the apiVersion for the infrastructureRef for the worker MachinePools |
| 174 | +*/}} |
| 175 | +{{- define "workers.infrastructure.apiVersion" -}} |
| 176 | +{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}} |
| 177 | +infrastructure.cluster.x-k8s.io/v1beta2 |
| 178 | +{{- end }} |
| 179 | +{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}} |
| 180 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 181 | +{{- end }} |
| 182 | +{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}} |
| 183 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 184 | +{{- end }} |
| 185 | +{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}} |
| 186 | +infrastructure.cluster.x-k8s.io/v1beta1 |
| 187 | +{{- end }} |
| 188 | +{{- end }} |
| 189 | + |
| 190 | +{{/* |
| 191 | +Create the configRef for the worker MachinePools |
| 192 | +*/}} |
| 193 | +{{- define "workers.configref" -}} |
| 194 | +{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}} |
| 195 | +configRef: |
| 196 | + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 |
| 197 | + kind: KubeadmConfig |
| 198 | + name: worker-mp-config |
| 199 | +{{- end }} |
| 200 | +{{- end }} |
| 201 | + |
| 202 | +{{/* |
| 203 | +Create a MachinePool for the given values |
| 204 | + ctx = . context |
| 205 | + name = the name of the MachinePool resource |
| 206 | + values = the values for this specific MachinePool resource |
| 207 | + defaultVals = the default values for the MachinePool resource |
| 208 | +*/}} |
| 209 | +{{- define "workers.machinePool" -}} |
| 210 | +{{- $replicas := (.values | default dict).replicas | default .defaultVals.replicas }} |
| 211 | +apiVersion: cluster.x-k8s.io/v1beta1 |
| 212 | +kind: MachinePool |
| 213 | +metadata: |
| 214 | + name: {{ .name }} |
| 215 | + annotations: |
| 216 | + helm.sh/resource-policy: keep |
| 217 | +spec: |
| 218 | + clusterName: {{ .ctx.Values.cluster.name }} |
| 219 | + replicas: {{ $replicas }} |
| 220 | + template: |
| 221 | + spec: |
| 222 | + {{- if or (eq .ctx.Values.provider "gcp") (eq .ctx.Values.provider "azure") (eq .ctx.Values.provider "kind") }} |
| 223 | + version: {{ .values.kubernetesVersion | default (include "cluster.kubernetesVersion" .ctx) | quote }} |
| 224 | + {{- end }} |
| 225 | + clusterName: {{ .ctx.Values.cluster.name }} |
| 226 | + bootstrap: |
| 227 | + {{- if or (eq .ctx.Values.provider "gcp") (eq .ctx.Values.provider "azure") (eq .ctx.Values.provider "aws") }} |
| 228 | + dataSecretName: "" |
| 229 | + {{- end }} |
| 230 | + {{- if eq .ctx.Values.provider "kind" }} |
| 231 | + {{- include "workers.configref" .ctx | nindent 8 }} |
| 232 | + {{- end }} |
| 233 | + infrastructureRef: |
| 234 | + name: {{ .name }} |
| 235 | + apiVersion: {{ include "workers.infrastructure.apiVersion" .ctx }} |
| 236 | + kind: {{ include "workers.infrastructure.kind" .ctx }} |
| 237 | +{{- end }} |
0 commit comments