Skip to content

Commit a8b20a5

Browse files
test(tests): exercise OIDC and certificate fixture branches
OIDC values do not reach tenant realm-group templates unless Helm also knows the Keycloak API. Harbor's Gateway setting bypasses its Ingress certificate branches, so certificate fixtures need the ingress path. Assisted-By: LLM Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 95c0184 commit a8b20a5

5 files changed

Lines changed: 67 additions & 10 deletions

File tree

‎hack/check-render-matrix.bats‎

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,74 @@ expect_render_failure() {
132132
rm -rf "$tmp"
133133
}
134134

135+
@test "render matrix reaches capability-gated OIDC templates" {
136+
tmp=$(mktemp -d)
137+
make_render_chart "$tmp/tenant"
138+
cat > "$tmp/tenant/templates/object.yaml" <<'EOF'
139+
{{- if and (eq (index .Values._cluster "oidc-enabled") "true") (.Capabilities.APIVersions.Has "v1.edp.epam.com/v1") }}
140+
{{- fail "OIDC branch rendered" }}
141+
{{- end }}
142+
EOF
143+
output=$(expect_render_failure "$tmp/tenant")
144+
printf '%s\n' "$output" | grep -Fx 'FAIL tenant (configured)'
145+
printf '%s\n' "$output" | grep -Fx 'FAIL tenant (wildcard)'
146+
printf '%s\n' "$output" | grep -F 'OIDC branch rendered'
147+
if printf '%s\n' "$output" | grep -Fq 'FAIL tenant (fresh)'; then
148+
echo 'OIDC branch enabled for fresh fixture' >&2
149+
exit 1
150+
fi
151+
rm -rf "$tmp"
152+
}
153+
154+
@test "fixture states enable OIDC groups and shared-service resources" {
155+
tmp=$(mktemp -d)
156+
for state in fresh configured wildcard; do
157+
helm template tenant-check packages/apps/tenant -n tenant-test \
158+
--api-versions v1.edp.epam.com/v1 \
159+
-f "hack/testdata/render-fixtures/$state.yaml" > "$tmp/tenant.yaml"
160+
helm template kubernetes-check packages/apps/kubernetes -n tenant-test \
161+
-f "hack/testdata/render-fixtures/$state.yaml" > "$tmp/kubernetes.yaml"
162+
groups=$(awk '/^kind: KeycloakRealmGroup$/ {n++} END {print n+0}' "$tmp/tenant.yaml")
163+
metrics=$(awk '/^ name: kubernetes-check-metrics-server$/ {n++} END {print n+0}' "$tmp/kubernetes.yaml")
164+
case "$state" in
165+
fresh) [ "$groups" -eq 0 ]; [ "$metrics" -eq 0 ] ;;
166+
*) [ "$groups" -eq 4 ]; [ "$metrics" -eq 1 ] ;;
167+
esac
168+
done
169+
rm -rf "$tmp"
170+
}
171+
172+
@test "certificate fixtures exercise per-host ACME and wildcard ingress" {
173+
tmp=$(mktemp -d)
174+
for state in configured wildcard; do
175+
helm template harbor-check packages/apps/harbor -n tenant-test \
176+
-f "hack/testdata/render-fixtures/$state.yaml" \
177+
--show-only templates/ingress.yaml > "$tmp/$state.yaml"
178+
grep -Fx 'kind: Ingress' "$tmp/$state.yaml"
179+
grep -F 'harbor-check.example.org' "$tmp/$state.yaml"
180+
done
181+
grep -F 'acme.cert-manager.io/http01-ingress-ingressclassname: tenant-test' "$tmp/configured.yaml"
182+
grep -F 'cert-manager.io/cluster-issuer: letsencrypt-prod' "$tmp/configured.yaml"
183+
grep -F 'secretName: harbor-check-ingress-tls' "$tmp/configured.yaml"
184+
grep -Fx ' tls:' "$tmp/wildcard.yaml"
185+
if grep -Eq '^[[:space:]]+(acme.cert-manager.io/|cert-manager.io/cluster-issuer:|secretName:)' "$tmp/wildcard.yaml"; then
186+
echo 'wildcard ingress unexpectedly requests a per-host certificate' >&2
187+
exit 1
188+
fi
189+
rm -rf "$tmp"
190+
}
191+
135192
@test "every pair of fixture states produces different deterministic manifests" {
136193
tmp=$(mktemp -d)
137194
count=0
138195
for fixture in hack/testdata/render-fixtures/*.yaml; do
139196
state=$(basename "$fixture" .yaml)
140197
count=$((count + 1))
141-
# Tenant exercises OIDC and certificate modes without random Secrets.
198+
# This compares whole states; the tests above assert specific branches.
142199
# Render twice so randomness cannot masquerade as state coverage.
143200
for run in first second; do
144201
helm template tenant-check packages/apps/tenant -n tenant-test \
145-
-f "$fixture" > "$tmp/$state-$run.yaml"
202+
--api-versions v1.edp.epam.com/v1 -f "$fixture" > "$tmp/$state-$run.yaml"
146203
done
147204
cmp "$tmp/$state-first.yaml" "$tmp/$state-second.yaml"
148205
cp "$tmp/$state-first.yaml" "$tmp/$state.manifests"

‎hack/check-render-matrix.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ render_chart() {
2222
chart=$1 fixture=$2
2323
name=$(basename "$chart")
2424
case "$name" in
25-
tenant) set -- tenant-sub ;;
25+
tenant) set -- tenant-sub --api-versions v1.edp.epam.com/v1 ;;
2626
# Satisfy the parent-cluster and release-name contract before the lookup.
2727
kubernetes-nodes) set -- kubernetes-nodes-render-check --set-string cluster=render ;;
2828
*) set -- "$name-render-check" ;;

‎hack/testdata/render-fixtures/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ The source of `_cluster` is `packages/core/platform/templates/apps.yaml`; `_name
66

77
`scheduling` and `branding` are maps copied with `toYaml`, which preserves their nested types. The scheduling keys read by app charts have a more specific contract: `globalAppTopologySpreadConstraints` is a string containing YAML (or an empty string), and `dedicatedNodesForWindowsVMs` is compared with the string `"true"`. The configured and wildcard fixtures supply a topology constraint; fresh leaves it empty. The embedded YAML retains numeric fields such as `maxSkew`.
88

9-
`_namespace.<service>` contains the namespace providing the shared service, or an empty string when unavailable. A non-empty value enables the service-dependent templates in the Kubernetes chart.
9+
`_namespace.<service>` contains the namespace providing the shared service, or an empty string when unavailable. A non-empty value enables the service-dependent templates in the Kubernetes chart. These states use ingress rather than Gateway API, so `gateway` stays empty: a non-empty gateway would disable Harbor Ingress and leave the certificate modes untested.
1010

1111
| File | State |
1212
|---|---|
1313
| `fresh.yaml` | OIDC off, no certificates or shared services, no topology constraint |
1414
| `configured.yaml` | OIDC on, per-host ACME via http01, shared services and topology constraint |
1515
| `wildcard.yaml` | OIDC on, dns01 with a platform-issued wildcard certificate, shared services and topology constraint |
1616

17-
Each chart is attempted under every fixture. `vm-instance` and `kubernetes-nodes` require a `VirtualMachineClusterInstancetype` lookup on their defaults. The sweep accepts their skip only while every fixture fails with the recorded lookup diagnostic; a successful render or a different error fails the sweep. For kubernetes-nodes it supplies a parent cluster and matching release name first.
17+
Each chart is attempted under every fixture. `vm-instance` and `kubernetes-nodes` require a `VirtualMachineClusterInstancetype` lookup on their defaults. The sweep accepts their skip only while every fixture fails with the recorded lookup diagnostic; a successful render or a different error fails the sweep. For kubernetes-nodes it supplies a parent cluster and matching release name first. For tenant it declares the Keycloak API with `--api-versions v1.edp.epam.com/v1`, allowing OIDC-enabled fixtures to render the realm groups.
1818

1919
`lookup` returns an empty result during this check. Tests for existing objects belong in chart-specific helm-unittest suites using `kubernetesProvider`; `packages/apps/clickhouse/tests/backup_api_password_persistence_test.yaml` covers both password generation and preservation that way. Presets, replica counts and other app feature toggles are outside this sweep.
2020

21-
The BATS suite checks fixture types with the small Helm chart in `validator/`, using `--set-file` so explicit nulls are not removed by Helm's values merge. It also verifies scheduling reaches the PostgreSQL manifest and compares complete tenant renders for every pair of fixture states. Tenant exercises OIDC and certificate modes without generating random Secrets; rendering each state twice verifies that the comparison is deterministic. Identical output from other charts is expected.
21+
The BATS suite checks fixture types with the small Helm chart in `validator/`, using `--set-file` so explicit nulls are not removed by Helm's values merge. Separate assertions check PostgreSQL topology constraints, tenant OIDC groups, the Kubernetes metrics-server HelmRelease and Harbor per-host ACME versus wildcard TLS. Pairwise comparison of complete tenant renders detects duplicate fixture states, and a second render of each state checks that randomness cannot satisfy that comparison. The branch assertions are needed because tenant also copies injected values into a Secret, so different output alone does not prove a conditional resource was rendered.
2222

2323
When adding an injected value read by an app, update the relevant states and add an assertion for the branch it exercises. Review all read forms, including `index`, `get` and `dig`, before deciding a value is unused:
2424

2525
```sh
26-
grep -rn '_cluster\|_namespace' packages/apps/*/templates/
26+
grep -rn -e '_cluster' -e '_namespace' packages/apps/*/templates/
2727
```

‎hack/testdata/render-fixtures/configured.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _cluster:
2424
_namespace:
2525
etcd: "tenant-test"
2626
ingress: "tenant-test"
27-
gateway: "tenant-test"
27+
gateway: ""
2828
monitoring: "tenant-test"
2929
seaweedfs: "tenant-test"
3030
host: "example.org"

‎hack/testdata/render-fixtures/wildcard.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# dns01 with a platform-issued wildcard certificate: the path where charts stop
2-
# doing per-host ACME and point at a shared Secret instead.
2+
# doing per-host ACME and use the ingress controller default certificate.
33
_cluster:
44
root-host: "example.org"
55
bundle-name: "paas-full"
@@ -24,7 +24,7 @@ _cluster:
2424
_namespace:
2525
etcd: "tenant-test"
2626
ingress: "tenant-test"
27-
gateway: "tenant-test"
27+
gateway: ""
2828
monitoring: "tenant-test"
2929
seaweedfs: "tenant-test"
3030
host: "example.org"

0 commit comments

Comments
 (0)