Files
cozystack/packages/extra/etcd/tests/affinity_test.yaml
T
Andrey Kolkov 9858fb63ac 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 <andrey.kolkov@aenix.io>
2026-08-26 13:26:26 +04:00

58 lines
2.1 KiB
YAML

suite: etcd EtcdCluster affinity rendering
release:
name: etcd
namespace: tenant-root
templates:
- templates/etcd-cluster.yaml
tests:
- it: applies a soft per-host podAntiAffinity by default
set:
_cluster: {}
documentSelector:
path: kind
value: EtcdCluster
asserts:
- equal:
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].weight
value: 100
- equal:
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey
value: kubernetes.io/hostname
- equal:
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.labelSelector.matchLabels["app.kubernetes.io/instance"]
value: etcd
- lengthEqual:
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution
count: 1
# A supplied affinity must replace the default outright — a hard rule should
# render verbatim and the soft preferred default must not leak through.
- it: renders a supplied affinity verbatim and drops the default
set:
_cluster: {}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app.kubernetes.io/instance: etcd
topologyKey: kubernetes.io/hostname
documentSelector:
path: kind
value: EtcdCluster
asserts:
- equal:
path: spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].topologyKey
value: kubernetes.io/hostname
- equal:
path: spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].labelSelector.matchLabels["app.kubernetes.io/instance"]
value: etcd
- lengthEqual:
path: spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution
count: 1
- notExists:
path: spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution