Skip to content

Commit c504d31

Browse files
authored
fix(capi-cluster): add labels and annotations to machinepool (#849)
Signed-off-by: David van der Spek <[email protected]>
1 parent 1696106 commit c504d31

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed

bootstrap/helm/cluster-api-cluster/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: cluster-api-cluster
33
description: A Helm chart for Kubernetes
44
type: application
5-
version: 0.1.43
5+
version: 0.1.44
66
appVersion: v1.24.16

bootstrap/helm/cluster-api-cluster/templates/_helpers.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ metadata:
208208
name: {{ .name }}
209209
annotations:
210210
helm.sh/resource-policy: keep
211+
{{- if (hasKey .values "annotations") -}}
212+
{{- toYaml (merge .values.annotations .defaultVals.annotations)| nindent 4 }}
213+
{{- else -}}
214+
{{- toYaml .defaultVals.annotations | nindent 4 }}
215+
{{- end }}
216+
labels:
217+
{{- if (hasKey .values "labels") -}}
218+
{{- toYaml (merge .values.labels .defaultVals.labels)| nindent 4 }}
219+
{{- else -}}
220+
{{- toYaml .defaultVals.labels | nindent 4 }}
221+
{{- end }}
211222
spec:
212223
clusterName: {{ .ctx.Values.cluster.name }}
213224
replicas: {{ $replicas }}

bootstrap/helm/cluster-api-cluster/tests/aws_machinepools_test.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ tests:
3030
type: managed
3131
cluster.aws.region: abc
3232
cluster.kubernetesVersion: v1.2.3
33+
workers.defaults.aws.labels:
34+
test: test
3335
workers.defaults.aws.spec.availabilityZones:
3436
- us-east-1a
3537
- us-east-1b
@@ -39,11 +41,78 @@ tests:
3941
path: spec.amiType
4042
value: AL2_x86_64
4143
documentIndex: 0
44+
- isSubset:
45+
path: metadata.labels
46+
content:
47+
test: test
48+
- isSubset:
49+
path: metadata.annotations
50+
content:
51+
cluster.x-k8s.io/replicas-managed-by: external-autoscaler
4252
- equal:
4353
path: spec.diskSize
4454
value: 50
4555
documentIndex: 2
4656
template: aws/machinepools.yaml
57+
- it: test override
58+
set:
59+
cluster.name: test
60+
provider: aws
61+
type: managed
62+
cluster.aws.region: abc
63+
cluster.kubernetesVersion: v1.2.3
64+
workers.defaults.aws.spec.availabilityZones:
65+
- us-east-1a
66+
- us-east-1b
67+
- us-east-1c
68+
workers.aws.small-burst-spot:
69+
labels:
70+
test: test
71+
annotations:
72+
test: test
73+
spec:
74+
amiType: AL2_x86_64_GPU
75+
diskSize: 100
76+
asserts:
77+
- equal:
78+
path: spec.eksNodegroupName
79+
value: small-burst-spot
80+
documentIndex: 22
81+
- equal:
82+
path: metadata.name
83+
value: small-burst-spot
84+
documentIndex: 23
85+
- isSubset:
86+
path: metadata.labels
87+
content:
88+
test: test
89+
documentIndex: 22
90+
- isSubset:
91+
path: metadata.annotations
92+
content:
93+
cluster.x-k8s.io/replicas-managed-by: external-autoscaler
94+
test: test
95+
documentIndex: 22
96+
- isSubset:
97+
path: metadata.labels
98+
content:
99+
test: test
100+
documentIndex: 23
101+
- isSubset:
102+
path: metadata.annotations
103+
content:
104+
cluster.x-k8s.io/replicas-managed-by: external-autoscaler
105+
test: test
106+
documentIndex: 23
107+
- equal:
108+
path: spec.diskSize
109+
value: 100
110+
documentIndex: 22
111+
- equal:
112+
path: spec.amiType
113+
value: AL2_x86_64_GPU
114+
documentIndex: 22
115+
template: aws/machinepools.yaml
47116
- it: test large-burst-spot
48117
set:
49118
cluster.name: test

bootstrap/helm/cluster-api-cluster/tests/gcp_machinepools_test.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ tests:
66
set:
77
provider: gcp
88
type: managed
9+
workers.defaults.gcp.labels:
10+
test: test
911
asserts:
1012
- hasDocuments:
1113
count: 6
@@ -51,6 +53,14 @@ tests:
5153
equal:
5254
path: spec.machineType
5355
value: e2-standard-2
56+
- isSubset:
57+
path: metadata.labels
58+
content:
59+
test: test
60+
- isSubset:
61+
path: metadata.annotations
62+
content:
63+
cluster.x-k8s.io/replicas-managed-by: external-autoscaler
5464
- it: should have custom kubernetes version set
5565
set:
5666
provider: gcp
@@ -67,4 +77,3 @@ tests:
6777
asserts:
6878
- hasDocuments:
6979
count: 0
70-

0 commit comments

Comments
 (0)