Skip to content

Commit 9858fb6

Browse files
author
Andrey Kolkov
committed
test(etcd): cover default and overridden affinity rendering
The affinity value added in this branch introduced a two-branch conditional in templates/etcd-cluster.yaml (default soft podAntiAffinity vs. a supplied value) with no coverage. Add a helm unittest suite pinning both branches: the default preferred per-host rule, and that a supplied affinity replaces the default outright (no preferred rule leaks through). Signed-off-by: Andrey Kolkov <[email protected]>
1 parent c83a22e commit 9858fb6

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
suite: etcd EtcdCluster affinity rendering
2+
3+
release:
4+
name: etcd
5+
namespace: tenant-root
6+
7+
templates:
8+
- templates/etcd-cluster.yaml
9+
10+
tests:
11+
- it: applies a soft per-host podAntiAffinity by default
12+
set:
13+
_cluster: {}
14+
documentSelector:
15+
path: kind
16+
value: EtcdCluster
17+
asserts:
18+
- equal:
19+
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].weight
20+
value: 100
21+
- equal:
22+
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey
23+
value: kubernetes.io/hostname
24+
- equal:
25+
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.labelSelector.matchLabels["app.kubernetes.io/instance"]
26+
value: etcd
27+
- lengthEqual:
28+
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution
29+
count: 1
30+
31+
# A supplied affinity must replace the default outright — a hard rule should
32+
# render verbatim and the soft preferred default must not leak through.
33+
- it: renders a supplied affinity verbatim and drops the default
34+
set:
35+
_cluster: {}
36+
affinity:
37+
podAntiAffinity:
38+
requiredDuringSchedulingIgnoredDuringExecution:
39+
- labelSelector:
40+
matchLabels:
41+
app.kubernetes.io/instance: etcd
42+
topologyKey: kubernetes.io/hostname
43+
documentSelector:
44+
path: kind
45+
value: EtcdCluster
46+
asserts:
47+
- equal:
48+
path: spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].topologyKey
49+
value: kubernetes.io/hostname
50+
- equal:
51+
path: spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].labelSelector.matchLabels["app.kubernetes.io/instance"]
52+
value: etcd
53+
- lengthEqual:
54+
path: spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution
55+
count: 1
56+
- notExists:
57+
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution

0 commit comments

Comments
 (0)