fix(e2e): read the KubernetesNodes pool release in the HelmRelease guard (#4970)

`cozy_guard_all_helmreleases` in
`hack/e2e-chainsaw/_lib/run-kubernetes.sh` reads the parent
`kubernetes-<test>` release and the addons selected by the
`kubernetes-<test>-` prefix. The worker pool is
`kubernetes-nodes-<test>-md0`, an Application HelmRelease the aggregated
apiserver stamps with `RetryOnFailure` like the parent, and it sits on
the node-join path through the talos-reconcile Job it renders. Its name
does not start with the addon prefix, so a failed action on it was never
read, on the passing path or in the failure-path report.

This reads it on both paths, with the `required` strategy check the
parent gets, since the apiserver stamps both. The pool name is derived
from the parent (`cozy_pool_helmrelease_name`), the way the addon prefix
is, so the two cannot drift. The failure-path report checks that the
release exists before reading it, with `get hr --ignore-not-found -o
name`: a run whose pool apply failed has no pool release (exit 0, empty
output), and the report says so instead of reporting a failed read. For
that run to reach the report at all, `run_kubernetes_test` now arms the
exit handler (`_tenant_failure_on_exit`, with
`CURRENT_TENANT_PARENT_HR`) right after the parent `Kubernetes` apply
instead of after the `KubernetesNodes` apply: before, a failing pool
apply exited under errexit with no handler installed, and the parent
went unclassified. The snapshot half still no-ops until the tenant
kubeconfig is set. A non-zero exit (a timeout, a kill, a Forbidden) is
reported as the failed read it is, through `_cozy_guard_read_failure`,
never as absence. The pool reads are gated on the report's own deadline
as well as the phase clock, like the addon listing.

Unit tests in `hack/run-kubernetes-remediation_test.bats` cover a
failing pool release on the passing path, a clean one (the composite
returns zero), an empty strategy on the pool, the report with and
without the pool release, a cut-off existence read, and a pool read past
the report budget; the ordering pin now also requires the handler to be
armed before the pool apply. The kubectl stub gained an existence read:
an `ABSENT` marker prints nothing and exits 0 under `--ignore-not-found`
(NotFound without it, as kubectl does), and the failure markers apply to
it as `<name>.exists`.

Verified with `hack/cozytest.sh` and Bats on
`hack/run-kubernetes-remediation_test.bats` (51 tests),
`hack/run-kubernetes-node-join_test.bats` and
`hack/remediation-guard.bats`.

Closes #4737


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Kubernetes release checks now include worker-pool releases alongside
the parent release and add-ons, and flag missing or invalid install
strategies and remediation failures.
* Failure reports distinguish worker-pool releases that are absent from
those whose status cannot be read. Existing releases are assessed
against the phase gate and report time budget; when the budget is
exhausted, skipped checks are identified.
* Failure handling now begins immediately after the parent resource is
applied, covering errors that occur while applying the worker pool.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Backported-from: 013b166967
This commit is contained in:
Myasnikov Daniil committed 2026-11-10 12:23:21 +00:00
commit 53a1d2da5a
2 files changed
+354 -36

No files matched your search

+71 -24
View File
@@ -5230,9 +5230,10 @@ _cozy_guard_kubectl() {
cozy_guard_helmrelease() {
local _ns="$1"
local _hr="$2"
# Non-empty on a release whose install strategy the cluster is known to set,
# which is the parent Application HelmRelease and nothing else here. See the
# branch that reads it for why the check cannot be applied to the addons.
# Non-empty on a release whose install strategy the cluster is known to set:
# the parent Application HelmRelease and the worker pool release, which is an
# Application HelmRelease too. See the branch that reads it for why the check
# cannot be applied to the addons.
local _strategy_required="${3:-}"
local _probe _strategy _history _ready _read_rc
_cozy_guard_read_bounds
@@ -5437,16 +5438,32 @@ cozy_guard_addon_helmreleases() {
# keeps the parent's own verdict, which an early return past the addons would
# drop.
#
# The worker pool release of parent kubernetes-<test>. The pool is a
# KubernetesNodes named <test>-md0 (see the apply in the run), and the
# aggregated apiserver names its HelmRelease kubernetes-nodes-<test>-md0. That
# name does not start with the addon prefix kubernetes-<test>-, so the addon
# listing never selects it, and it is read on its own. Derived from the parent
# rather than passed in, for the same reason as the addon prefix below.
cozy_pool_helmrelease_name() {
local _parent="$1"
printf 'kubernetes-nodes-%s-md0\n' "${_parent#kubernetes-}"
}
# The addon prefix is derived here rather than passed in, so the parent name and
# the prefix that selects its children cannot drift apart.
cozy_guard_all_helmreleases() {
local _ns="$1"
local _parent="$2"
local _failed=0
# The parent is asked to prove its install strategy read back non-empty; the
# addons are not, because most of them legitimately set none. See the branch
# in cozy_guard_helmrelease that reads this argument.
# The parent and the pool release are asked to prove their install strategy
# read back non-empty: both are Application HelmReleases, which the apiserver
# stamps. The addons are not, because most of them legitimately set none. See
# the branch in cozy_guard_helmrelease that reads this argument.
cozy_guard_helmrelease "$_ns" "${_parent}" required || _failed=1
# The pool release sits on the node-join path, through the talos-reconcile
# Job it renders, so a failed action on it is as much a finding as one on the
# parent. By the time this runs the pool has scaled, so the release exists.
cozy_guard_helmrelease "$_ns" "$(cozy_pool_helmrelease_name "${_parent}")" required || _failed=1
cozy_guard_addon_helmreleases "$_ns" "${_parent}-" || _failed=1
# These releases are now classified, and the same flag the failure-path report
# uses records it. The two are not alternatives: this call runs before the
@@ -5495,7 +5512,8 @@ _COZY_GUARD_REPORT_DONE=0
# failing path would replace the caller's own exit status, and the tenant
# crust-gather snapshot hangs off that exit.
#
# Bounded on its own clock, checked before the listing and before each release.
# Bounded on its own clock, checked before the pool release, before the listing
# and before each addon release.
# What comes after this on the exit path is the tenant snapshot, which needs the
# rest of the op, so a namespace whose apiserver answers slowly must cost a
# bounded number of seconds here rather than however many releases happen to be
@@ -5515,7 +5533,7 @@ cozy_report_helmrelease_remediation() {
local _ns="$1"
local _parent="$2"
local _label="${3:-}"
local _addon_hrs _hr _deadline _budget
local _addon_hrs _hr _pool _pool_found _read_rc _deadline _budget
[ "${_COZY_GUARD_REPORT_DONE}" -eq 0 ] || return 0
# An empty parent name means the run failed before the release was created, so
# there is no history anywhere to read yet.
@@ -5541,6 +5559,29 @@ cozy_report_helmrelease_remediation() {
cozy_diag_phase_has_time "HelmRelease remediation footprint of ${_parent}" || return 0
echo "=== ${_label}tenant HelmRelease remediation footprint (management cluster, ns ${_ns}) — classification only, this does not decide the run ==="
cozy_guard_helmrelease "$_ns" "${_parent}" required || true
# The pool release is created by a later apply than the parent, and
# run_kubernetes_test arms the exit handler between the two, so a run whose
# pool apply failed reaches this with none to read. Its absence is then a fact
# about where the run stopped, not a failed read, and is reported as such.
# Only an exit 0 with empty output means absent: --ignore-not-found makes
# NotFound that, so any non-zero exit is a read that failed and is named as
# one.
_pool=$(cozy_pool_helmrelease_name "${_parent}")
cozy_diag_phase_has_time "HelmRelease remediation footprint of ${_pool}" || return 0
if [ "$(date +%s)" -ge "${_deadline}" ]; then
echo "=== HelmRelease remediation footprint: stopped after ${_budget}s; ${_pool} and the addon releases of ${_parent} were not read, so nothing was observed about any of them ===" >&2
return 0
fi
_cozy_guard_read_bounds
_read_rc=0
_pool_found=$(_cozy_guard_kubectl get hr -n "$_ns" "${_pool}" --ignore-not-found -o name) || _read_rc=$?
if [ "${_read_rc}" -ne 0 ]; then
echo "Checking whether ${_pool} exists failed - $(_cozy_guard_read_failure "${_read_rc}"); nothing was observed about it either way." >&2
elif [ -z "${_pool_found}" ]; then
echo "» ${_pool} does not exist - the run ended before the worker pool was applied, or its HelmRelease was never created; nothing to read"
else
cozy_guard_helmrelease "$_ns" "${_pool}" required || true
fi
cozy_diag_phase_has_time "the addon HelmRelease listing of ${_parent}" || return 0
if [ "$(date +%s)" -ge "${_deadline}" ]; then
echo "=== HelmRelease remediation footprint: stopped after ${_budget}s; the addon releases of ${_parent} were not listed, so nothing was observed about any of them ===" >&2
@@ -5723,6 +5764,28 @@ ${ouroboros_addon}
version: "${k8s_version}"
EOF
# Armed here, at the parent apply, rather than once the tenant answers. The
# parent HelmRelease exists from this point on -- the aggregated apiserver
# creates it before it answers the apply above -- and everything between here
# and the tenant LB is a management-cluster wait on that release or on what it
# installs: the KamajiControlPlane, the control-plane Deployments, the
# MachineDeployment, the admin-kubeconfig Secret. That window is the one the
# guard was written for. An install action that times out while
# admin-kubeconfig is still being provisioned leaves the failed Snapshot this
# reads, and every one of those waits exits under errexit with no reading at
# all if the handler is armed after them.
#
# Ahead of the pool apply below as well, not after it: a pool apply that fails
# exits under errexit too, and armed after it that run would leave the parent
# unclassified. Armed here, it is the run the report's "pool release does not
# exist" line describes.
#
# Arming this early costs the snapshot nothing: _tenant_snapshot_on_fail
# returns on an unset CURRENT_TENANT_KC, which is assigned where the
# kubeconfig becomes usable, so it no-ops until then.
CURRENT_TENANT_PARENT_HR="kubernetes-${test_name}"
trap '_tenant_failure_on_exit' EXIT
# Worker node pool is a separate KubernetesNodes resource since the Phase 2
# split. Named "<cluster>-md0" so it produces MachineDeployment
# kubernetes-${test_name}-md0 — the same object the pre-split
@@ -5781,22 +5844,6 @@ ${talos_block}
storageClass: "${storage_class}"
version: "${k8s_version}"
EOF
# Armed here, at the apply, rather than once the tenant answers. The parent
# HelmRelease exists from this point on -- the aggregated apiserver renders it
# from the CR above -- and everything between here and the tenant LB is a
# management-cluster wait on that release or on what it installs: the
# KamajiControlPlane, the control-plane Deployments, the MachineDeployment,
# the admin-kubeconfig Secret. That window is the one the guard was written
# for. An install action that times out while admin-kubeconfig is still being
# provisioned leaves the failed Snapshot this reads, and every one of those
# waits exits under errexit with no reading at all if the handler is armed
# after them.
#
# Arming this early costs the snapshot nothing: _tenant_snapshot_on_fail
# returns on an unset CURRENT_TENANT_KC, which is assigned where the
# kubeconfig becomes usable, so it no-ops until then.
CURRENT_TENANT_PARENT_HR="kubernetes-${test_name}"
trap '_tenant_failure_on_exit' EXIT
# Wait for the tenant-test namespace to be active
kubectl wait namespace tenant-test --timeout=20s --for=jsonpath='{.status.phase}'=Active
+283 -12
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bats
# -----------------------------------------------------------------------------
# Unit tests for cozy_guard_addon_helmreleases in
# Unit tests for cozy_guard_all_helmreleases and cozy_guard_addon_helmreleases in
# hack/e2e-chainsaw/_lib/run-kubernetes.sh
#
# cozy_guard_helmrelease judges one release; cozy_guard_addon_helmreleases runs
@@ -32,9 +32,11 @@ load test_helper
# created. The stub answers the shapes the guard issues: the namespace listing
# (from ALL_HR), one release's install strategy and Ready condition together
# (<name>.strategy and <name>.ready, joined the way the guard's jsonpath joins
# them), and its history statuses (<name>.history). A missing fixture file
# stands for a field the object does not carry, which is what kubectl prints for
# an absent jsonpath - nothing.
# them), its history statuses (<name>.history), and whether it exists at all
# (`--ignore-not-found -o name`, which a <name>.ABSENT marker turns into empty
# output, and whose read the markers below take as <name>.exists). A missing
# fixture file stands for a field the object does not carry, which is what
# kubectl prints for an absent jsonpath - nothing.
#
# A FAILS marker file makes the matching read exit non-zero with a message on
# stderr, which is how the API answers a timeout or a denied request. That
@@ -96,6 +98,7 @@ for a in "$@"; do
describe) mode=describe ;;
*'status.history'*) mode=history ;;
*'install.strategy.name'*) mode=probe ;;
name) mode=exists ;;
kubernetes-*) name=$a ;;
esac
done
@@ -103,6 +106,7 @@ case "$mode" in
list) markers=LIST ;;
history) markers="$name.history" ;;
probe) markers="$name.strategy $name.ready" ;;
exists) markers="$name.exists" ;;
*) markers= ;;
esac
for m in $markers; do
@@ -145,6 +149,20 @@ case "$mode" in
"$(cat "$FIXTURES/$name.strategy" 2>/dev/null || true)" \
"$(cat "$FIXTURES/$name.ready" 2>/dev/null || true)"
;;
exists)
# `get hr <name> --ignore-not-found -o name`: an absent release prints
# nothing and exits 0, which an ABSENT marker reproduces; anything else
# exists. Without the flag kubectl answers NotFound with a non-zero exit,
# so a read that drops it is told apart here the way the cluster would.
if [ -f "$FIXTURES/$name.ABSENT" ]; then
case " $* " in
*' --ignore-not-found '*) exit 0 ;;
esac
echo "Error from server (NotFound): helmreleases.helm.toolkit.fluxcd.io \"$name\" not found" >&2
exit 1
fi
echo "helmrelease.helm.toolkit.fluxcd.io/$name"
;;
describe) echo "stub describe of $name" ;;
esac
exit 0
@@ -252,6 +270,245 @@ STUB
rm -rf "$tmp"
}
@test "the pool release is read by the full guard, and its footprint fails the run" {
# The worker pool is kubernetes-nodes-<test>-md0, an Application HelmRelease
# the apiserver stamps like the parent, on the node-join path through the
# talos-reconcile Job it renders. Its name does not start with the addon
# prefix kubernetes-<test>-, so the addon listing never selects it, and
# before this read a failed action on it was invisible to the guard on every
# path. Parent and addon are clean here; the pool alone carries the finding.
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
tmp=$(mktemp -d)
cozy_make_kubectl_stub "$tmp"
export FIXTURES="$tmp/fixtures"
printf 'kubernetes-test-latest-version-coredns\n' > "$FIXTURES/ALL_HR"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-coredns.history"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.strategy"
printf 'failed\ndeployed\n' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.history"
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_guard_all_helmreleases tenant-test kubernetes-test-latest-version 2>&1) || rc=$?
if [ "$rc" -eq 0 ]; then
echo "expected the pool release footprint to fail the run, got: $out" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q -F 'HelmRelease kubernetes-nodes-test-latest-version-md0 carries a failed or uninstalled Snapshot, and its install strategy is RetryOnFailure'; then
echo "expected the pool release to be named in the verdict, got: $out" >&2
exit 1
fi
if ! grep -q -F 'kubernetes-nodes-test-latest-version-md0' "$FIXTURES/CALLS"; then
echo "expected a read of the pool release, calls were: $(cat "$FIXTURES/CALLS")" >&2
exit 1
fi
rm -rf "$tmp"
}
@test "a clean pool release leaves the full guard green" {
# The pin for the passing path: with every release clean the composite
# returns zero, so the pool read above is a read and not an unconditional
# verdict. The pool name is derived from the parent, the way the addon
# prefix is, which this fixture spells out.
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
tmp=$(mktemp -d)
cozy_make_kubectl_stub "$tmp"
export FIXTURES="$tmp/fixtures"
printf 'kubernetes-test-latest-version-coredns\n' > "$FIXTURES/ALL_HR"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-coredns.history"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.history"
PATH="$tmp/bin:$PATH" cozy_guard_all_helmreleases tenant-test kubernetes-test-latest-version
[ "$(cozy_pool_helmrelease_name kubernetes-test-latest-version)" = kubernetes-nodes-test-latest-version-md0 ]
rm -rf "$tmp"
}
@test "the pool release is held to a stamped install strategy like the parent" {
# The pool is an Application HelmRelease, so an empty strategy there is the
# read and never the object, the same as on the parent. Without this the
# jsonpath rename the parent check exists for would leave the pool's
# footprint on the lenient branch while the parent's check still passed.
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
tmp=$(mktemp -d)
cozy_make_kubectl_stub "$tmp"
export FIXTURES="$tmp/fixtures"
printf 'kubernetes-test-latest-version-coredns\n' > "$FIXTURES/ALL_HR"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-coredns.history"
printf 'True' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.ready"
printf 'deployed\n' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.history"
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_guard_all_helmreleases tenant-test kubernetes-test-latest-version 2>&1) || rc=$?
if [ "$rc" -eq 0 ]; then
echo "expected an empty install strategy on the pool release to fail the run, got: $out" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q -F 'spec.install.strategy.name of kubernetes-nodes-test-latest-version-md0 came back empty'; then
echo "expected the failure to name the pool release, got: $out" >&2
exit 1
fi
rm -rf "$tmp"
}
@test "the failure-path report classifies the pool release too" {
# Same reading as the passing path, from the exit handler: a pool release
# that failed an action is named, and the report still returns zero.
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
tmp=$(mktemp -d)
cozy_make_kubectl_stub "$tmp"
export FIXTURES="$tmp/fixtures"
printf 'kubernetes-test-latest-version-coredns\n' > "$FIXTURES/ALL_HR"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-coredns.history"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.strategy"
printf 'failed\ndeployed\n' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.history"
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_report_helmrelease_remediation tenant-test kubernetes-test-latest-version 2>&1) || rc=$?
if [ "$rc" -ne 0 ]; then
echo "expected the report to return zero, got rc=$rc: $out" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q -F 'HelmRelease kubernetes-nodes-test-latest-version-md0 carries a failed or uninstalled Snapshot'; then
echo "expected the pool release footprint to be classified, got: $out" >&2
exit 1
fi
rm -rf "$tmp"
}
@test "the failure-path report says when the pool release was never created" {
# The pool is applied after the parent, and the exit handler is armed between
# the two, so a run whose pool apply failed reaches the report with no pool
# release. That is a fact about where the run stopped, and the report says so
# instead of reporting a failed read of a missing object.
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
tmp=$(mktemp -d)
cozy_make_kubectl_stub "$tmp"
export FIXTURES="$tmp/fixtures"
printf 'kubernetes-test-latest-version-coredns\n' > "$FIXTURES/ALL_HR"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-coredns.history"
: > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.ABSENT"
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_report_helmrelease_remediation tenant-test kubernetes-test-latest-version 2>&1) || rc=$?
if [ "$rc" -ne 0 ]; then
echo "expected the report to return zero, got rc=$rc: $out" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q -F 'kubernetes-nodes-test-latest-version-md0 does not exist'; then
echo "expected the report to say the pool release does not exist, got: $out" >&2
exit 1
fi
if printf '%s\n' "$out" | grep -q -F 'Reading .spec.install.strategy.name and the Ready condition of kubernetes-nodes-test-latest-version-md0 failed'; then
echo "expected no failed read of the absent pool release, got: $out" >&2
exit 1
fi
rm -rf "$tmp"
}
@test "a failed existence read of the pool release is not reported as absence" {
# The report runs on the failure path, where a slow apiserver is most
# likely. A cut-off existence read said "does not exist" there, which sends
# the reader to the wrong stage of the run; it has to be named as the failed
# read it is, the way the parent's and the listing's are, and the walk goes
# on to the addons.
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
tmp=$(mktemp -d)
cozy_make_kubectl_stub "$tmp"
export FIXTURES="$tmp/fixtures"
printf 'kubernetes-test-latest-version-coredns\n' > "$FIXTURES/ALL_HR"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-coredns.history"
: > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.exists.CUTOFF"
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_report_helmrelease_remediation tenant-test kubernetes-test-latest-version 2>&1) || rc=$?
if [ "$rc" -ne 0 ]; then
echo "expected the report to return zero, got rc=$rc: $out" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q -F 'Checking whether kubernetes-nodes-test-latest-version-md0 exists failed - the read did not finish'; then
echo "expected the cut-off existence read to be named as a failed read, got: $out" >&2
exit 1
fi
if printf '%s\n' "$out" | grep -q -F 'kubernetes-nodes-test-latest-version-md0 does not exist'; then
echo "expected a failed read not to be reported as absence, got: $out" >&2
exit 1
fi
if grep -F 'kubernetes-nodes-test-latest-version-md0' "$FIXTURES/CALLS" | grep -q -v -F -e '-o name'; then
echo "expected no classification read of a release whose existence is unknown, calls were: $(cat "$FIXTURES/CALLS")" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q 'HelmRelease kubernetes-test-latest-version-coredns '; then
echo "expected the addons to be read after the failed pool read, got: $out" >&2
exit 1
fi
rm -rf "$tmp"
}
@test "the failure-path report does not read the pool release past its budget" {
# The parent's reads are issued before the first clock check, so on a path
# that opens no phase they can spend the whole budget on their own. The pool
# release is three more bounded reads, and starting them past the deadline
# takes them out of the tenant snapshot's time.
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
tmp=$(mktemp -d)
cozy_make_kubectl_stub "$tmp"
export FIXTURES="$tmp/fixtures"
printf 'kubernetes-test-latest-version-coredns\n' > "$FIXTURES/ALL_HR"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.strategy"
printf 'failed\ndeployed\n' > "$FIXTURES/kubernetes-nodes-test-latest-version-md0.history"
# The deadline is stamped at 1000+90 and the pool release is checked one
# reading later, at 1100.
date_ticks="$tmp/ticks"
printf '0' > "$date_ticks"
date_now=1000
date_step=100
COZY_GUARD_REPORT_BUDGET=90
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_report_helmrelease_remediation tenant-test kubernetes-test-latest-version 2>&1) || rc=$?
date_now=
date_step=0
date_ticks=
unset COZY_GUARD_REPORT_BUDGET
if [ "$rc" -ne 0 ]; then
echo "expected the report to return zero, got rc=$rc: $out" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q 'HelmRelease kubernetes-test-latest-version (install strategy'; then
echo "expected the parent to have been classified before the budget ran out, got: $out" >&2
exit 1
fi
if grep -q -F 'kubernetes-nodes-test-latest-version-md0' "$FIXTURES/CALLS"; then
echo "expected no read of the pool release once the budget was spent, calls were: $(cat "$FIXTURES/CALLS")" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q -F 'stopped after 90s; kubernetes-nodes-test-latest-version-md0 and the addon releases of kubernetes-test-latest-version were not read'; then
echo "expected the skipped pool release to be named, got: $out" >&2
exit 1
fi
rm -rf "$tmp"
}
@test "single-release guard fails a RetryOnFailure release that failed and recovered" {
# The entry point the parent kubernetes-<test> release goes through, and the
# shape the rule exists for. The apiserver stamps RetryOnFailure on every
@@ -1110,14 +1367,15 @@ STUB
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-cilium.history"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version-coredns.history"
# 30s per reading against a 90s budget: the report stamps its deadline at
# 1000+90, the listing is checked at 1030, the first addon at 1060 and the
# second at 1090, which is the first reading the deadline refuses.
# 30s per reading against a 120s budget: the report stamps its deadline at
# 1000+120, the pool release is checked at 1030, the listing at 1060, the
# first addon at 1090 and the second at 1120, which is the first reading
# the deadline refuses.
date_ticks="$tmp/ticks"
printf '0' > "$date_ticks"
date_now=1000
date_step=30
COZY_GUARD_REPORT_BUDGET=90
COZY_GUARD_REPORT_BUDGET=120
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_report_helmrelease_remediation tenant-test kubernetes-test-latest-version 2>&1) || rc=$?
@@ -1137,7 +1395,7 @@ STUB
echo "expected the second addon to fall outside the budget, got: $out" >&2
exit 1
fi
if ! printf '%s\n' "$out" | grep -q -F 'stopped after 90s; kubernetes-test-latest-version-coredns and every release after it were not read'; then
if ! printf '%s\n' "$out" | grep -q -F 'stopped after 120s; kubernetes-test-latest-version-coredns and every release after it were not read'; then
echo "expected the cut-off release to be named, got: $out" >&2
exit 1
fi
@@ -1227,6 +1485,19 @@ $out" >&2
echo "expected the handler armed (line $arm) before the control-plane wait (line $cp_wait)" >&2
exit 1
fi
# And before the pool apply, which follows the parent's. A failing pool
# apply exits under errexit, so armed after it that run leaves the parent
# unclassified, and the report's absent-pool line describes a run that never
# reaches it.
pool_apply=$(grep -n '^kind: KubernetesNodes$' "$lib" | head -n 1 | cut -d: -f1)
if [ -z "$pool_apply" ]; then
echo "expected to find the KubernetesNodes apply in $lib" >&2
exit 1
fi
if [ "$arm" -ge "$pool_apply" ]; then
echo "expected the handler armed (line $arm) before the pool apply (line $pool_apply)" >&2
exit 1
fi
# The parent name is part of this one, because it is what tells the
# node-join call apart from the handler's. What follows it is not: a
# section label is presentation and may change without the wiring changing.
@@ -1320,13 +1591,13 @@ $out" >&2
printf 'RetryOnFailure' > "$FIXTURES/kubernetes-test-latest-version.strategy"
printf 'deployed\n' > "$FIXTURES/kubernetes-test-latest-version.history"
printf 'uninstalled\ndeployed\n' > "$FIXTURES/kubernetes-test-latest-version-cilium.history"
# The deadline is stamped at 1000+90 and the listing is checked one reading
# later, at 1100.
# The deadline is stamped at 1000+150, the pool release is admitted at 1100
# and the listing is checked one reading later, at 1200.
date_ticks="$tmp/ticks"
printf '0' > "$date_ticks"
date_now=1000
date_step=100
COZY_GUARD_REPORT_BUDGET=90
COZY_GUARD_REPORT_BUDGET=150
rc=0
out=$(PATH="$tmp/bin:$PATH" cozy_report_helmrelease_remediation tenant-test kubernetes-test-latest-version 2>&1) || rc=$?