test(kubernetes-nodes): cover the Talos support-matrix guard by render

The pool chart checks every worker's Talos release against the
Kubernetes version it joins, once for talos.version and once for the
release osImage resolves to, and that is now the only such check. Its
coverage was two grep tests that the call sites exist; nothing rendered
a refusal, and the pairings it has to let through were pinned only in
the parent chart, against a copy of the table.

The pool's own suite pins the in-window pairings, through talos.version
at both ends of the schema's version range and through
osImage.factory.version. The refusals need a version the schema does
not offer and the versions map does not hold, so they render a copy of
the chart with --skip-schema-validation and one extra versions.yaml row,
the way the postgres preload allowlist test reaches its backstop. They
fail if the second call is fed talos.version instead of the resolved
release, if the table is keyed on the full release instead of the
minor, or if either call is dropped.

Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Myasnikov Daniil committed 2026-11-12 16:57:46 +05:00
1 parent 90f0b043a6
commit 6b0a564bc4
3 files changed
+152 -12

No files matched your search

+9 -12
View File
@@ -78,19 +78,16 @@ CATALOG_VALUES="$REPO_ROOT/packages/system/kubernetes-worker-image/values.yaml"
# -----------------------------------------------------------------------------
# Second family of default-drift guards on the same chart: the Talos <-> Kubernetes
# support matrix. The render guard keyed only on `talos.version`, so a pool could
# reach a different Talos release through `osImage.builtin.version` /
# `osImage.factory.version` and boot a kubelet outside its support window with no
# render failure. The table now lives once in templates/_helpers.tpl and both
# paths consult it.
# support matrix. A pool reaches a Talos release through `talos.version` or through
# `osImage.builtin.version` / `osImage.factory.version`, and the table in
# templates/_helpers.tpl has to be consulted for whichever one the pool boots.
#
# The symmetry is structural, not observable from a render: the matrix ships one
# row (`v1.13`) whose Kubernetes list is a superset of `values.schema.json`'s
# `version` enum, so no schema-valid pairing can make either call site fail today.
# A helm-unittest case would have to put an out-of-enum `version` in, and
# helm-unittest validates the schema, so it cannot. These two guards cover what a
# render cannot: that both call sites exist, and that the table still means
# something for the defaults the chart ships.
# The matrix ships one row (`v1.13`) whose Kubernetes list is a superset of
# `values.schema.json`'s `version` enum, so no schema-valid pairing makes either
# call site fail today. hack/kubernetes-nodes-talos-matrix.bats renders the
# refusals with the schema skipped; these two guards cover what it does not: that
# both call sites stay wired, and that the table still means something for the
# defaults the chart ships.
NODES_TEMPLATE="$REPO_ROOT/packages/apps/kubernetes-nodes/templates/nodegroup.yaml"
NODES_SCHEMA="$REPO_ROOT/packages/apps/kubernetes-nodes/values.schema.json"
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env bats
# Unit test: the refusals of the Talos to Kubernetes support-matrix guard in
# packages/apps/kubernetes-nodes (kubernetes-nodes.assertTalosSupportsKubernetes,
# called from templates/nodegroup.yaml for talos.version and again for the
# release osImage resolves to).
#
# On the shipped chart a refusal is unreachable: the values schema offers only
# Kubernetes versions the v1.13 row lists, and files/versions.yaml, which another
# template fails on first, holds the same set. The guard is there for the day a
# Talos row stops listing a version the chart still offers. So this renders a
# copy of the chart with --skip-schema-validation and one extra versions.yaml row
# for a version the matrix does not list. The pairings the guard lets through
# are in the chart's own tests/talos_k8s_support_matrix_test.yaml.
load test_helper
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
CHART="$REPO_ROOT/packages/apps/kubernetes-nodes"
# render_pool <args...> renders the pool chart copy with the given --set flags and
# prints helm's output, errors included. The copy lives in the test's own tmpdir.
render_pool() {
copy="$BATS_TEST_TMPDIR/chart"
if [ ! -d "$copy" ]; then
cp -RL "$CHART" "$copy"
printf '"v1.30": "v1.30.14"\n' >> "$copy/files/versions.yaml"
fi
helm template kubernetes-nodes-myk8s-md0 "$copy" --namespace tenant-test \
--skip-schema-validation \
--set cluster=myk8s \
--set _cluster.cluster-domain=cozy.local \
--set minReplicas=1 --set maxReplicas=3 \
--set instanceType= --set resources.cpu=2 --set resources.memory=4Gi \
--set diskSize=20Gi --set storageClass=replicated \
"$@" 2>&1
}
@test "an in-window pairing renders on the same copy, so the refusals below are the guard's" {
out=$(render_pool --set version=v1.31) || { echo "$out" >&2; return 1; }
printf '%s\n' "$out" | grep -q '^kind: KubevirtMachineTemplate$'
}
@test "a Kubernetes version outside the row of talos.version is refused" {
if out=$(render_pool --set version=v1.30); then
echo "render succeeded with Kubernetes v1.30 on the default Talos" >&2
return 1
fi
printf '%s\n' "$out" | grep -qF "Kubernetes v1.30 is not supported by Talos v1.13.6. Supported versions: [v1.31 v1.32 v1.33 v1.34 v1.35 v1.36]. Bump 'version' or set talos.version explicitly." \
|| { echo "$out" >&2; return 1; }
}
@test "an older patch release of a listed Talos minor is checked against the same row" {
if out=$(render_pool --set version=v1.30 --set talos.version=v1.13.0); then
echo "render succeeded with Kubernetes v1.30 on Talos v1.13.0: the guard is not keyed on the minor" >&2
return 1
fi
printf '%s\n' "$out" | grep -qF 'Kubernetes v1.30 is not supported by Talos v1.13.0.' \
|| { echo "$out" >&2; return 1; }
}
# talos.version names a minor the matrix does not list, so the first call lets the
# pool through and only the call fed the osImage release can refuse it.
@test "a Kubernetes version outside the row of osImage.factory.version is refused" {
if out=$(render_pool --set version=v1.30 --set talos.version=v1.12.0 --set osImage.factory.version=v1.13.0); then
echo "render succeeded with Kubernetes v1.30 on Talos v1.13.0 reached through osImage.factory" >&2
return 1
fi
printf '%s\n' "$out" | grep -qF 'Kubernetes v1.30 is not supported by Talos v1.13.0.' \
&& printf '%s\n' "$out" | grep -qF 'nodeGroup md0 reaches this Talos release through its osImage override' \
|| { echo "$out" >&2; return 1; }
}
@test "a Kubernetes version outside the row of osImage.builtin.version is refused" {
if out=$(render_pool --set version=v1.30 --set talos.version=v1.12.0 --set osImage.builtin.version=v1.13.0); then
echo "render succeeded with Kubernetes v1.30 on Talos v1.13.0 reached through osImage.builtin" >&2
return 1
fi
printf '%s\n' "$out" | grep -qF 'Kubernetes v1.30 is not supported by Talos v1.13.0.' \
&& printf '%s\n' "$out" | grep -qF 'nodeGroup md0 reaches this Talos release through its osImage override' \
|| { echo "$out" >&2; return 1; }
}
@@ -0,0 +1,62 @@
suite: Talos to Kubernetes support-matrix guard (assertTalosSupportsKubernetes)
# The guard is keyed by Talos minor and consulted twice in nodegroup.yaml: once
# for talos.version and once for the release osImage resolves to. These cases
# pin the pairings it has to let through: each one fails if the matrix row loses
# the Kubernetes version under test.
#
# The refusals are in hack/kubernetes-nodes-talos-matrix.bats. The values schema
# offers only Kubernetes versions the v1.13 row lists, so no schema-valid input
# reaches a refusal, and helm-unittest always validates the schema; the bats file
# renders with --skip-schema-validation instead.
templates:
- templates/nodegroup.yaml
release:
name: kubernetes-nodes-myk8s-md0
namespace: tenant-test
set:
cluster: myk8s
_cluster:
cluster-domain: cozy.local
minReplicas: 1
maxReplicas: 3
instanceType: ""
diskSize: 20Gi
storageClass: replicated
roles: [ingress-nginx]
resources:
cpu: "2"
memory: 4Gi
tests:
- it: renders the oldest Kubernetes version the schema offers against the default Talos
set:
version: "v1.31"
asserts:
- notFailedTemplate: {}
- hasDocuments:
count: 4
- it: renders the newest Kubernetes version the schema offers against the default Talos
set:
version: "v1.35"
asserts:
- notFailedTemplate: {}
- it: renders an in-window pairing reached through osImage.factory.version
set:
version: "v1.31"
talos:
version: "v1.12.0"
osImage:
factory:
version: "v1.13.0"
asserts:
- notFailedTemplate: {}
- equal:
path: spec.template.spec.virtualMachineTemplate.spec.dataVolumeTemplates[0].spec.source.http.url
value: https://factory.talos.dev/image/ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515/v1.13.0/openstack-amd64.raw.xz
documentSelector: {path: kind, value: KubevirtMachineTemplate}