Skip to content

Commit 4331a1f

Browse files
authored
feat(bootstrap): add cluster api cluster chart (#834)
Signed-off-by: David van der Spek <[email protected]>
1 parent 8c5ab6e commit 4331a1f

31 files changed

+2174
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: cluster-chart-unit-test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'bootstrap/helm/cluster-api-cluster/**'
8+
pull_request:
9+
branches: [ main ]
10+
paths:
11+
- 'bootstrap/helm/cluster-api-cluster/**'
12+
jobs:
13+
helm-unit-test:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: 'read'
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: install helm
21+
uses: azure/setup-helm@v3
22+
with:
23+
version: v3.12.3
24+
- name: install helm unit test
25+
run: helm plugin install https://github.com/helm-unittest/helm-unittest.git
26+
- name: run helm unit test
27+
run: helm unittest ./bootstrap/helm/cluster-api-cluster
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
24+
tests/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: cluster-api-cluster
3+
description: A Helm chart for Kubernetes
4+
type: application
5+
version: 0.1.42
6+
appVersion: v1.24.16
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Cluster API Cluster
2+
3+
A helm chart that deploys a cluster using the Cluster-API project
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: plural.sh/v1alpha1
2+
kind: Dependencies
3+
metadata:
4+
application: true
5+
description: installs a cluster using cluster-api
6+
spec:
7+
dependencies: []
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
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

Comments
 (0)