Skip to content

Commit 49218b8

Browse files
committed
test(helm): cover podLabels with helm unit tests
1 parent 1ec7ada commit 49218b8

3 files changed

Lines changed: 153 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
suite: Pod labels
16+
templates:
17+
- pod-certificate-controller.yaml
18+
tests:
19+
- it: keeps only the app label on the controller pod by default
20+
documentSelector:
21+
path: kind
22+
value: Deployment
23+
asserts:
24+
- equal:
25+
path: spec.template.metadata.labels
26+
value:
27+
app: podcertificate-controller
28+
29+
- it: adds podLabels to the controller pod next to the app label
30+
set:
31+
podLabels:
32+
giantswarm.io/tenant: team-a
33+
documentSelector:
34+
path: kind
35+
value: Deployment
36+
asserts:
37+
- equal:
38+
path: spec.template.metadata.labels
39+
value:
40+
app: podcertificate-controller
41+
giantswarm.io/tenant: team-a
42+
- equal:
43+
path: spec.selector.matchLabels
44+
value:
45+
app: podcertificate-controller
46+
47+
- it: refuses a podLabels entry that replaces the app selector label
48+
set:
49+
podLabels:
50+
app: other
51+
asserts:
52+
- failedTemplate:
53+
errorMessage: "podLabels must not set app: it is the selector label of the controller Deployment"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
suite: Pod labels selector guard
16+
templates:
17+
- ate-controller.yaml
18+
tests:
19+
- it: refuses a podLabels entry that replaces the app selector label
20+
set:
21+
podLabels:
22+
app: other
23+
asserts:
24+
- failedTemplate:
25+
errorMessage: "podLabels must not set app: it is the selector label of every workload in the chart"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
suite: Pod labels
16+
templates:
17+
- ate-api-server.yaml
18+
- ate-controller.yaml
19+
- atelet.yaml
20+
- atenet-egress.yaml
21+
- atenet-router.yaml
22+
- k8s-credential-provider.yaml
23+
- rustfs.yaml
24+
tests:
25+
- it: adds podLabels to every Deployment pod next to the app label
26+
set:
27+
podLabels:
28+
giantswarm.io/tenant: team-a
29+
example.com/tier: control
30+
documentSelector:
31+
path: kind
32+
value: Deployment
33+
skipEmptyTemplates: true
34+
matchMany: true
35+
asserts:
36+
- isSubset:
37+
path: spec.template.metadata.labels
38+
content:
39+
giantswarm.io/tenant: team-a
40+
example.com/tier: control
41+
- exists:
42+
path: spec.template.metadata.labels.app
43+
- notExists:
44+
path: spec.selector.matchLabels["giantswarm.io/tenant"]
45+
46+
- it: adds podLabels to the atelet DaemonSet pod
47+
template: atelet.yaml
48+
set:
49+
podLabels:
50+
giantswarm.io/tenant: team-a
51+
documentSelector:
52+
path: kind
53+
value: DaemonSet
54+
asserts:
55+
- equal:
56+
path: spec.template.metadata.labels
57+
value:
58+
app: atelet
59+
giantswarm.io/tenant: team-a
60+
- equal:
61+
path: spec.selector.matchLabels
62+
value:
63+
app: atelet
64+
65+
- it: leaves the rustfs-bucket-init Job pod without podLabels
66+
template: rustfs.yaml
67+
set:
68+
podLabels:
69+
giantswarm.io/tenant: team-a
70+
documentSelector:
71+
path: kind
72+
value: Job
73+
asserts:
74+
- notExists:
75+
path: spec.template.metadata.labels["giantswarm.io/tenant"]

0 commit comments

Comments
 (0)