mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
The history guard covered only the parent Kubernetes HelmRelease. A failed action on one of the addon releases it installs left no mark the suite inspected, so a run surfaced only the downstream symptom, typically the node-join deadline, with nothing naming the release behind it. The tenant CNI and CSI are the sharp cases, since they carry a cluster-wide precondition. The guard now reads every addon release of the parent, selected from the cluster by name prefix so a release added later is covered too. A "failed" or "uninstalled" Snapshot fails the run on a release whose install strategy is RetryOnFailure: the parent, which the aggregated apiserver stamps that way, and cilium and csi. The same footprint on the other addons, which pair the default strategy with retries: -1, is printed as a note and leaves the run green. The footprint is not split into a teardown and a retried failure. In helm-controller v1.5.0, the version the platform installs, and unchanged in v1.5.1, a release with an active retry strategy never remediates: atomic_release.go returns an upgrade for a failed release before it reaches the remediation switch (lines 465-475), and the two other paths that uninstall, a changed release target and deletion, both call ClearHistory afterwards. On a RetryOnFailure release an "uninstalled" Snapshot is therefore unreachable, and the "failed" one is the only signal. A retry that later recovered still fails the run, by design, with one blind spot the statuses cannot close: a failed install that the very next attempt recovers is marked superseded by Helm, because there is no deployed release to supersede instead, and its history reads like an ordinary upgrade. The guard runs after the assertions, while every deadline a failed addon breaks ends the script earlier, so the same classification is also printed without a verdict from the node-join collector and from the exit handler. That handler is now armed at the tenant CR apply, so the management-cluster waits before the tenant answers are covered too. Every read is bounded and never folded into "no history", and the parent must read back RetryOnFailure: an empty value there means the jsonpath stopped resolving, and any other value means the apiserver stamp is gone, either of which would turn its footprint into a note. The history read takes its jsonpath from HELMRELEASE_HISTORY_JSONPATH, and the upstream-type pin accepts the bounded wrapper the read goes through. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
96 lines
3.7 KiB
Bash
96 lines
3.7 KiB
Bash
#!/usr/bin/env bats
|
|
# -----------------------------------------------------------------------------
|
|
# Unit tests for hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
#
|
|
# helmrelease_has_remediation_cycle takes a newline-delimited list of
|
|
# HelmRelease history snapshot status values (deployed/superseded/failed/
|
|
# uninstalled/...) and returns 0 when any entry is "failed" or "uninstalled"
|
|
# (meaning flux helm-controller performed install/upgrade remediation).
|
|
#
|
|
# This is used by the e2e script after the HelmRelease reaches Ready. The
|
|
# failure/upgrade counters (.status.installFailures / .status.upgradeFailures)
|
|
# are useless there because flux's ClearFailures zeroes them on successful
|
|
# reconciliation; .status.history retains the snapshot trail.
|
|
#
|
|
# cozytest.sh's awk parser recognizes only @test blocks and a bare `}` on
|
|
# its own line; there is no bats `run` or `$status`. Assertions are
|
|
# expressed as direct shell tests that exit non-zero on failure.
|
|
#
|
|
# Run with: hack/cozytest.sh hack/remediation-guard.bats
|
|
# -----------------------------------------------------------------------------
|
|
|
|
@test "empty history returns not-detected" {
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
if helmrelease_has_remediation_cycle ""; then
|
|
echo "expected not-detected for empty history" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "single deployed snapshot returns not-detected" {
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
if helmrelease_has_remediation_cycle "deployed"; then
|
|
echo "expected not-detected for deployed-only history" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "deployed then superseded returns not-detected" {
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
statuses=$(printf 'deployed\nsuperseded\n')
|
|
if helmrelease_has_remediation_cycle "${statuses}"; then
|
|
echo "expected not-detected for deployed+superseded history" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "single failed snapshot returns detected" {
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
if ! helmrelease_has_remediation_cycle "failed"; then
|
|
echo "expected detected when history contains failed snapshot" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "single uninstalled snapshot returns detected" {
|
|
# The exact signature of the install-remediation race: the first install
|
|
# exceeded flux's wait budget, remediation uninstalled, the next retry
|
|
# eventually succeeded. History still carries the uninstalled snapshot.
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
if ! helmrelease_has_remediation_cycle "uninstalled"; then
|
|
echo "expected detected when history contains uninstalled snapshot" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "uninstalled then deployed still returns detected" {
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
statuses=$(printf 'uninstalled\ndeployed\n')
|
|
if ! helmrelease_has_remediation_cycle "${statuses}"; then
|
|
echo "expected detected despite later successful deploy" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "deployed then failed still returns detected" {
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
statuses=$(printf 'deployed\nfailed\n')
|
|
if ! helmrelease_has_remediation_cycle "${statuses}"; then
|
|
echo "expected detected when any entry is failed" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "the predicate does not overwrite a caller variable named statuses" {
|
|
# This library is sourced rather than executed, and the helper assigns
|
|
# "statuses" internally, so without a local the argument lands in the
|
|
# caller's scope.
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
statuses=sentinel
|
|
helmrelease_has_remediation_cycle "failed"
|
|
if [ "${statuses}" != sentinel ]; then
|
|
echo "helmrelease_has_remediation_cycle replaced the caller's statuses with: ${statuses}" >&2
|
|
exit 1
|
|
fi
|
|
}
|