Files
cozystack/hack/testdata/install-wait/heredoc-terminators.sh
Aleksei Sviridkin 5fe595d4c0 test(e2e): hold the tenant-cluster install wait to an ordering rule
A test that creates a tenant Kubernetes cluster cannot END while that
release is still installing. A Helm release cannot be uninstalled
mid-install, and for this kind the install can outlive the fast
assertions: the kind carries helm-install-disable-wait, which drops
the wait on the main resources but not on the chart's blocking
post-install hook. A test that asserts and ends hands the remainder of
the install to teardown, where it is reported red on a step that tests
nothing.

The rule is about ending, not about touching the cluster at all. The
hook polls for the admin kubeconfig in the modes that have one, and
that Secret is what the test needs to reach the tenant API, so
bringing up a worker or waiting on a child release happens while the
parent is still installing. Reading mid-install is fine.

run-kubernetes.sh already does the right thing: it waits for the
parent release to reach Ready before the tenant-cluster assertions.
Nothing held it there. This adds the guard that does, and states the
rule where the e2e conventions live.

The guard reads the script rather than Chainsaw fixtures, because no
fixture applies this kind and a guard walking apply.file would pass by
having nothing to check. A case asserts that this stays the only
script creating it, and the sweep behind it keys on the apiVersion and
kind together so that an indented apply.resource block counts as a
creator too. It reads scripts and manifests only, and that rule is
pre-emptive rather than a response to what the root holds today: a
manifest quoted in prose or parked in a `.disabled` file creates no
cluster, and this repository writes the first shape in docs that lie
outside the root.

The rules it holds the script to -- what counts as a wait with teeth,
where in the body it has to stand, what may not switch errexit off
above it, and which call shapes count as an end-assertion -- are in
the file's header beside the code that enforces them, each with the
spellings it accepts and what it cannot see. How to size the budget is
derived once in the e2e conventions.

Nothing is added at the wait itself: hack/e2e-chainsaw/_lib is shared
by every Chainsaw suite, so a comment there escalates this change from
no e2e suites to the full suite, and the guard already reds on the
move it would have warned about.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-11 09:06:19 +03:00

44 lines
1.7 KiB
Bash

# Fixture for hack/run-kubernetes-install-wait_test.bats.
# Not executed: read as text by the guard's matchers.
#
# Every shape here is a heredoc whose body contains something that LOOKS like a
# terminator but is not one, followed by a fully qualifying wait. The shell
# keeps reading data past each of them, so none of these waits ever runs; a
# matcher that ends the heredoc early hands the wait back as a command and
# answers with a line from a YAML document.#
# `git diff --check` flags the trailing space on that line, deliberately:
# the space is the subject here, not an accident, and a case reds if it is
# stripped. Nothing suppresses the warning -- a suppression would cover the
# next file written here too, where a stray space would be an accident.
creating_body() {
kubectl apply -f - <<EOF
apiVersion: apps.cozystack.io/v1alpha1
kind: KubernetesNodes
spec:
script: |
EOF
kubectl wait hr -n tenant-test "kubernetes-${test_name}" --timeout=5m --for=condition=ready
EOF
kubectl apply -f - <<EOF
data:
note: |
EOF
kubectl wait hr -n tenant-test "kubernetes-${test_name}" --timeout=6m --for=condition=ready
EOF
kubectl apply -f - <<-TABBED
data: |
TABBED
kubectl wait hr -n tenant-test "kubernetes-${test_name}" --timeout=7m --for=condition=ready
TABBED
# Two openers on one command. Their bodies arrive in the order opened, so
# FIRST's terminator ends the first body and the wait below it is still data,
# inside SECOND. Tracking one delimiter per command ends the tracking here and
# hands that wait back as a command.
kubectl apply -f - <<FIRST <<SECOND
data: one
FIRST
kubectl wait hr -n tenant-test "kubernetes-${test_name}" --timeout=8m --for=condition=ready
SECOND
cozy_assert_after "${test_name}"
}