Skip to content

fix(e2e): budget tenant scheduling separately from workload readiness - #3579

Merged
Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/e2e-backend-readiness-budget
Aug 6, 2026
Merged

fix(e2e): budget tenant scheduling separately from workload readiness#3579
Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/e2e-backend-readiness-budget

Conversation

@lexfrei

@lexfrei Aleksei Sviridkin (lexfrei) commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What this PR does

The tenant backend Deployment in the kubernetes suites had one 300s budget to reach condition=Available, and two unrelated variable costs shared it.

The first is scheduling. What the suite establishes before that point is two tenant nodes Ready, which is weaker than schedulable: a Ready node still carries node.cilium.io/agent-not-ready until the tenant cilium agent claims it, and a node the bringup has not finished with is SchedulingDisabled. In the run recorded in #3577 scheduling took 2m18s and 1m57s in the two suites, which left the image pull to finish inside what remained. It did not, and both suites reported the same timed out waiting for the condition for what were two different shortfalls.

So this waits for a node that actually accepts a Pod before creating the workload, on its own budget and its own failure message. The gate encodes the scheduler's rule for a Pod that tolerates nothing (Ready, not unschedulable, no NoSchedule or NoExecute taint) over a custom-columns probe, prints the node table on both outcomes so a timeout names the taint that held it, and treats a failed probe as not-schedulable so an API blip cannot release it. On the happy path it adds no wall time: it spends the seconds the Pod would otherwise spend Pending, plus at most one 5s poll interval. On a failing run the two budgets stack, so a run that exhausts both now gives up at ~600s where it used to give up at 300s, inside the 40m Chainsaw script op the suites document as a ~25m bringup. The readiness wait keeps its 300s, now starting from a schedulable node, and dumps deployment, pod and event state when it runs out.

The workload image is also pinned by digest. The tenant workers reach no Docker Hub mirror (hack/e2e-talos-image-cache.yaml serves the Talos worker OS disk image over HTTP and is not a registry mirror), so nginx is pulled from Docker Hub on every run either way. The digest does not take the pull off the critical path; it fixes what that pull returns instead of leaving a floating tag free to change size and content under a fixed deadline. Preloading the image would need infrastructure this tree does not have, and is not attempted here. Nothing will bump the pin: no renovate manager reads hack/, and the comment says so, because for a throwaway test workload the freeze is the point.

What this does not claim: it removes two measured consumers from a fixed budget, both taken from the events of a single run. Whether that budget was the only thing making those suites red is not established from one run, so this is not offered as the fix for a red pipeline.

hack/run-kubernetes-schedulable_test.bats covers the new logic: every branch of the predicate, the multi-node scan, the poll-again path, the deadline, and a probe that fails. Each test was verified by mutating the helper and checking that the intended test, and no other, went red.

Note for whoever reviews alongside #3575: that branch mirrors ghcr.io for tenant worker pulls, not docker.io, so it does not change the Docker Hub pull described here. git merge-tree reports no conflict between the two, nor with #3548.

Observed in #3577.

Screenshots

Not a UI change.

Downstream repositories

The trigger map was walked against the diff. The change is confined to hack/e2e-chainsaw/_lib/run-kubernetes.sh and one new hack/*.bats unit test. It moves and renames nothing under hack/, changes no make target, and does not touch hack/e2e-prepare-cluster.bats, any package, any CRD or any namespace name, so none of the listed repositories are reached.

Release note

NONE

Summary by CodeRabbit

  • Bug Fixes

    • Improved Kubernetes deployment readiness by waiting for a suitable, schedulable node before timing backend startup.
    • Added clearer diagnostics when nodes are unavailable or backend readiness fails.
    • Replaced the floating backend container image tag with a fixed, verified version.
  • Tests

    • Added coverage for node readiness, cordoning, taints, polling, timeouts, probe failures, and deployment sequencing.

The tenant backend Deployment had a single 300s budget to reach
condition=Available, and two unrelated variable costs shared it. The
first is scheduling. What the suite establishes before that point is two
tenant nodes Ready, which is weaker than schedulable: a Ready node still
carries node.cilium.io/agent-not-ready until the tenant cilium agent
claims it, and a node the bringup has not finished with is
SchedulingDisabled. Scheduling took 2m18s and 1m57s in the two tenant
suites of one run, leaving the image pull to finish inside what was
left. It did not, and both suites failed with the same message for two
different shortfalls.

Wait for a node that actually accepts a toleration-free Pod before
creating the workload, on its own budget and its own failure message.
The gate encodes the scheduler's rule for such a Pod (Ready, not
unschedulable, no NoSchedule or NoExecute taint) over a custom-columns
probe, prints the node table on both outcomes so a timeout names the
taint that held it, and treats a failed probe as not-schedulable so an
API blip cannot release it. The readiness wait keeps its 300s, now
starting from a schedulable node, and dumps deployment, pod and event
state when it runs out.

Pin the workload image by digest. The tenant workers reach no registry
mirror, so nginx is pulled from Docker Hub on every run either way; the
digest fixes what that pull returns instead of leaving a floating tag
free to change size and content under a fixed deadline.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
@github-actions github-actions Bot added area/testing Issues or PRs related to testing (e2e, bats, unit tests) kind/bug Categorizes issue or PR as related to a bug size/L This PR changes 100-499 lines, ignoring generated files labels Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Kubernetes test flow now waits for a Ready, uncordoned, untainted tenant node before backend readiness timing. It adds bounded polling, failure diagnostics, schedulability tests, and a digest-pinned nginx image.

Changes

Tenant scheduling and backend readiness

Layer / File(s) Summary
Node admission predicates and probe handling
hack/e2e-chainsaw/_lib/run-kubernetes.sh, hack/run-kubernetes-schedulable_test.bats
The script evaluates node readiness, cordoning, and blocking taints. Tests cover individual rows and empty or mixed node results.
Scheduling gate and backend readiness integration
hack/e2e-chainsaw/_lib/run-kubernetes.sh, hack/run-kubernetes-schedulable_test.bats
Bounded polling waits for a schedulable tenant node before backend readiness timing. The nginx image uses a pinned OCI digest. Timeout and readiness failures emit diagnostics. Tests cover polling, command failures, query arguments, gate ordering, and caller control flow.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • cozystack/cozystack#3577 — The changes add the schedulability gate, pin the nginx image, and improve backend readiness diagnostics.

Suggested reviewers: myasnikovdaniil

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: separating tenant scheduling time from workload readiness time in Kubernetes end-to-end tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/e2e-backend-readiness-budget

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@hack/e2e-chainsaw/_lib/run-kubernetes.sh`:
- Line 180: The node probe in hack/e2e-chainsaw/_lib/run-kubernetes.sh:180 must
pass a finite --request-timeout value, such as 10s, to kubectl get nodes. Update
the stubbed probe assertion in hack/run-kubernetes-schedulable_test.bats:195-226
to require this flag while preserving the existing probe behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 26609d47-c3d9-4b4e-be8c-625d975f5f1c

📥 Commits

Reviewing files that changed from the base of the PR and between df157da and 5542ae5.

📒 Files selected for processing (2)
  • hack/e2e-chainsaw/_lib/run-kubernetes.sh
  • hack/run-kubernetes-schedulable_test.bats

_timeout="${2:-300}"
_deadline=$(( $(date +%s) + _timeout ))
while :; do
_nodes=$(kubectl --kubeconfig "$_kc" get nodes --no-headers -o custom-columns='NAME:.metadata.name,READY:.status.conditions[?(@.type=="Ready")].status,UNSCHEDULABLE:.spec.unschedulable,TAINTS:.spec.taints[*].effect' 2>/dev/null) || _nodes=""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

lib='hack/e2e-chainsaw/_lib/run-kubernetes.sh'
test='hack/run-kubernetes-schedulable_test.bats'

grep -n -- '--request-timeout=10s' "$lib"
sed -n '195,226p' "$test" | grep -n -- '--request-timeout=10s'

Repository: cozystack/cozystack

Length of output: 157


🏁 Script executed:

#!/bin/bash
set -euo pipefail

lib='hack/e2e-chainsaw/_lib/run-kubernetes.sh'
test='hack/run-kubernetes-schedulable_test.bats'

printf 'File exists: '
test -f "$lib" && echo "$lib" || echo "missing $lib"
test -f "$test" && echo "$test" || echo "missing $test"

printf '\nRelevant lib section:\n'
sed -n '150,195p' "$lib"

printf '\nRelevant test section:\n'
sed -n '195,230p' "$test"

printf '\nSearch for request-timeout or _deadline checks:\n'
rg -n -- '--request-timeout|_deadline|functimeout|timeout' "$lib" "$test"

Repository: cozystack/cozystack

Length of output: 12100


🌐 Web query:

kubectl documentation request-timeout default 0

💡 Result:

In kubectl, the default value for the --request-timeout flag is "0" [1][2][3]. A value of "0" indicates that there is no timeout, meaning the client will wait indefinitely for a server request to complete [1][4][5]. When providing a non-zero value, you must include a corresponding time unit, such as "1s", "2m", or "3h" [1][6][5]. This flag controls the length of time the kubectl client waits for a single request to the API server [1][2]. It is distinct from command-specific timeout flags (like those used for wait or delete operations), which typically define the duration of an operation rather than the individual HTTP request [7].

Citations:


Set a finite timeout for each node probe.

The loop limits total probe time, but kubectl get nodes does not cancel until it returns. The kubectl --request-timeout default is 0, so a stalled API request can exceed the 300-second gate and return no node table for diagnostics.

  • Add a finite --request-timeout, such as 10s, to the node probe: hack/e2e-chainsaw/_lib/run-kubernetes.sh#L180.
  • Assert that the stubbed probe includes this flag: hack/run-kubernetes-schedulable_test.bats#L195.
📍 Affects 2 files
  • hack/e2e-chainsaw/_lib/run-kubernetes.sh#L180-L180 (this comment)
  • hack/run-kubernetes-schedulable_test.bats#L195-L226
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@hack/e2e-chainsaw/_lib/run-kubernetes.sh` at line 180, The node probe in
hack/e2e-chainsaw/_lib/run-kubernetes.sh:180 must pass a finite
--request-timeout value, such as 10s, to kubectl get nodes. Update the stubbed
probe assertion in hack/run-kubernetes-schedulable_test.bats:195-226 to require
this flag while preserving the existing probe behavior.

@IvanHunters

Copy link
Copy Markdown
Collaborator

Verdict

LGTM with non-blocking notes

The scheduling gate is fail-closed, the parsing predicate matches the scheduler's admission rule, and the 21-case unit suite is non-vacuous and wired into make bats-unit-tests automatically. The notes below are craft-level only and do not block.

Findings

[MINOR] hack/e2e-chainsaw/_lib/run-kubernetes.sh:~695, poll probe hides the failure cause while it is polling

_nodes=$(kubectl --kubeconfig "$_kc" get nodes ... 2>/dev/null) || _nodes=""

The gate is correctly fail-closed: a failed probe yields an empty capture, cozy_has_schedulable_node "" reports not-schedulable, and the loop keeps waiting until the deadline (verified by the a failing probe holds the gate rather than releasing it test). The remaining gap is only observability: the 2>/dev/null discards the real cause (connection refused / Forbidden / etc.) on every poll, and the timeout branch prints <the node probe returned nothing> rather than the last error. In practice the caller's follow-up kubectl describe nodes / kubectl -n tenant-test get hr re-surface the state, so the operator is not fully blind. Consider capturing 2>&1 into a variable and echoing the last error on the timeout path so the failure reason is in the gate's own message. Not blocking.

[MINOR] hack/run-kubernetes-schedulable_test.bats:213 and :230, two assertions grep the library source text rather than exercise behaviour

The the scheduling gate runs before the backend Deployment is applied and the tenant backend workload image is pinned by digest cases assert on grep -n line numbers / image-line text in run-kubernetes.sh. These are source-text drift guards: they will break on unrelated reformatting and pass even if the runtime behaviour regresses in a way that keeps the text shape. They are defensible here because file ordering and the digest pin genuinely cannot be exercised without running the full e2e, and the comment in the test says as much. Flagging only so it is a conscious choice; the other 19 cases are genuine behavioural tests. Not blocking.

Caveats

  • Phase 5b (fresh install / upgrade): N/A for cluster state. The PR touches only the e2e harness (hack/e2e-chainsaw/_lib/run-kubernetes.sh, hack/run-kubernetes-schedulable_test.bats); it renders no chart, migration, RBAC, or CRD and cannot affect a customer install or upgrade.
  • Mechanical fail-open sweep: run on the new shell. The one decision-driving capture (_nodes=$(kubectl ... 2>/dev/null) || _nodes="") is fail-closed as noted above, not fail-open. No || true / || : on any gating command.
  • Verified locally (hermetic, no cluster): bash -n clean; shellcheck reports only pre-existing info/warnings outside the diff; hack/cozytest.sh hack/run-kubernetes-schedulable_test.bats → 21/21 OK; the library runs under the suite's set -eu and the new functions contain their exit inside the pipeline subshell (verified by the the scan reports a hit without exiting its caller test).
  • Budget stacking: a fully-failing run now spends up to 300s here plus up to 300s on the readiness wait (~600s where it was ~300s). The PR documents this sits inside the enclosing 40m Chainsaw op; confirmed the number is inside that envelope, not verified against real CI wall-clock.

@lexfrei
Aleksei Sviridkin (lexfrei) merged commit 0dae3ca into main Aug 6, 2026
15 of 16 checks passed
@lexfrei
Aleksei Sviridkin (lexfrei) deleted the fix/e2e-backend-readiness-budget branch August 6, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing Issues or PRs related to testing (e2e, bats, unit tests) kind/bug Categorizes issue or PR as related to a bug size/L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants