Skip to content

ci(k8s-e2e): shard execution qualification and cut provisioning time - #2432

Merged
rdimitrov merged 7 commits into
mainfrom
ci/shard-k8s-execution-e2e
Oct 20, 2026
Merged

rdimitrov merged 7 commits into
mainfrom
ci/shard-k8s-execution-e2e

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

k8s-e2e.yml is the long pole for PR wall-clock. The execution provider production profile (kind) job took ~38 min: ~10–12 min of provisioning plus ~25.5 min of tests run serially against one Kind cluster. This PR cuts the workflow from 37.9 min to 17.9 min on a cold Go cache, and to about 13 min on a warm one, with the same tests. It folds in the provisioning work from #2434.

Sharding

  • Three-way matrix. Each shard provisions its own Kind cluster. shards.txt assigns every TestKindExecution* test to a shard, balanced by measured durations (~500s each).
  • Selection. run.sh reads MECATL_EXECUTION_QUAL_SHARD and skips only the listed tests the shard doesn't own. An unlisted test runs on every shard, and a test listed under two shards runs on both, so nothing silently drops out.
  • Guard. shards_test.go runs in task test. It fails if a cluster test is in no shard or in more than one, if a row names a missing test, or if the shard ids and the workflow matrix differ.
  • Ordering constraints, documented in shards.txt:
    • ProductionHelmLifetime uninstalls the release, so it must be the last cluster test in its shard. Its zz_ file name guarantees that.
    • SecurityRotation shares that release, so the two stay together.
    • The renewal phases (in-flight, plus natural expiry on dispatch) run only on the shard that owns them.
  • Handoff. run.sh refuses sharding in handoff mode, because e2e-live.yml needs the whole suite on one retained cluster.

Faster provisioning (from #2434)

  • Job-owned Go cache. The shared setup-go key is also used by ci.yml and never matched ko's -trimpath compiles. The execution job now restores its own ~/go/pkg/mod + ~/.cache/go-build entry, keyed on Go version + go.sum. Only shard 1 saves it, only outside pull requests, and only once per go.sum. PR runs read main's entry and add nothing to the cache budget.
  • Host compiles reuse ko's packages. The templates tool and go test -c build with ko's CGO_ENABLED=0 -trimpath settings. The test binary starts compiling right after the ko builds, so it overlaps image work.
  • One archive for the workload family. The workload image and its two derivatives share base layers, so they're saved and loaded together.

Race fixes exposed by faster setup

Both bugs predate this PR. Faster setup and the shard order made them hit more often.

  • ResourceQuota admission. With fast setup, the first test's EnsureTemplate could arrive before the quota controller had computed the chart's ResourceQuota. Kubernetes then refuses the create as Forbidden, and the client surfaces it as "internal: execution provider request failed". This was seen on unsharded run 38883705359 and reproduced on a debug branch. For the ExecutionEnvironment count, usage only appears after the quota controller discovers the new resource type. run.sh now waits, for at most 180s, until every key in the quota has both its limit and its usage computed. It logs how long that took (17–31s observed).
  • Agent run release. TestKindExecutionQualification read mecak8s's prompt stream to the end and then immediately called AcquireRun. mecak8s releases its own run claim only after that stream ends, so the test could win the race and get Conflict ("environment has an active run"). This was seen on unsharded main run 38732150492 (15 Oct) and twice on shard 2. The test now waits, for at most 45s, until the environment shows no unexpired active run claim before acquiring. That's the provider's own admission rule, not a retry on Conflict.

Triggers and budget

  • Both jobs skip release/* PRs, which only bump version strings on a commit main has already qualified.
  • The PR paths filter drops Taskfile.yml (7 of 45 triggering PRs touched only that file) and go.work.sum, which git doesn't track. go.mod/go.sum stay, because dependency bumps can change in-cluster behaviour. Push-to-main triggers are unchanged.
  • The timeout comment claimed a 30m in-flight renewal; that phase has a 10m ceiling. The per-shard budget is 75 min (210 for natural-expiry dispatch). The architecture doc is updated to match.

Measurements

Before (39380803820, main) Sharded only (39389618485) Combined, cold cache (39405535923) Combined, warm cache (39396317476)
Workflow wall-clock 37m54s 23m20s 17m57s 13m01s
Execution tests per shard 1534s (one job) 512–559s ~500s 468–512s
Images phase per shard 366s 399–446s 324–346s 109–110s

PRs see the warm numbers once a push to main has saved the job's cache entry.

Cache pressure: the repo's Actions cache is at about 10.4 GB against a 10 GB limit. Every entry belongs to an open PR, and main currently has no entries. Least-recently-used eviction means the warm entry may not survive long until that eases. Saving Go caches only on pushes to main (restore-only on PRs) everywhere would fix that, as a separate PR.

I also tried building the ko images in parallel. With a cold cache, the concurrent builds compile the shared packages twice and were slower, so they stay serial.

Test plan

  • go test ./deploy/mecatl-execution-kind/... ./deploy/execution-templates/... on Linux (golang:1.27.2 with jq). On macOS, a few existing run.sh tests fail identically on unmodified main (no GNU timeout, /private/var paths).
  • Offline unit tests in e2e/k8s_execution (-tags kind_execution_e2e).
  • actionlint .github/workflows/k8s-e2e.yml, task docs.
  • task lint: clean apart from a pre-existing darwin-only gosec finding in environment/microvm, which this PR doesn't touch.
  • Mutation check of the shard guard: dropping one row and duplicating another fails with both messages.
  • Real runs: sharded, combined cold, and combined warm (links above), all green.
  • PR run on the combined head 160f18463.

🤖 Generated with Claude Code

rdimitrov and others added 2 commits October 20, 2026 10:54
The production execution job ran ~25 minutes of tests serially on one
cluster after ~10 minutes of provisioning, making it the PR long pole.

- Split the job into a 3-way matrix, each shard on its own Kind cluster.
  deploy/mecatl-execution-kind/shards.txt assigns every TestKindExecution*
  test (and the renewal phases) to one shard, balanced by measured main
  durations. run.sh selects a shard via MECATL_EXECUTION_QUAL_SHARD by
  skipping tests owned by other shards, so an unlisted test still runs.
- shards_test.go fails when a cluster test matches no shard or more than
  one, or when shard ids drift from the workflow matrix.
- Build the four ko images concurrently, overlapped with the container
  builds.
- Skip both jobs on release/* PRs; drop Taskfile.yml and the untracked
  go.work.sum from the PR paths filter (push to main unchanged).
- Correct the job timeout comment (in-flight renewal has a 10m ceiling,
  not 30m) and size the per-shard budget at 75 minutes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measured on run 39389618485: with the cold Go build cache this job always
starts from, concurrent ko builds compile shared packages twice and the
images phase took 399-446s against 366s serial on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rdimitrov and others added 5 commits October 20, 2026 12:21
When setup is fast (warm Go cache), the first cluster test's EnsureTemplate
can run before the quota controller has computed the chart's ResourceQuota
status. The API server then rejects the ExecutionEnvironment create as
Forbidden, which the client surfaces as "internal: execution provider
request failed". Reproduced on a debug run (backend_failure reason=forbidden
with count/executionenvironments missing from quota status); it cleared within
seconds. The same failure hit unsharded run 38883705359.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous wait matched status.hard to spec.hard, but #2434's warm-cache
run still hit Forbidden on the first create: the API server also requires
status.used for every listed resource, and the ExecutionEnvironment count is
only computed once the quota controller discovers the newly installed CRD.
Wait until every spec.hard key has a matching status.hard value and a
status.used entry (the same condition failure-evidence.jq reports), and log
how long the wait took.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A shard previously skipped every test listed under another shard, so a test
listed under two shards ran on neither. Skip only listed tests the shard does
not own, so duplicates run twice instead. The partition test still rejects
duplicates, missing tests, and matrix drift; the selection and preflight
tests it made redundant are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TestKindExecutionQualification reads the agent's prompt stream to the end
and immediately calls AcquireRun on the same environment. The agent
(mecak8s) releases its own run claim only in teardownExecution after that
stream ends, so the test can win the race and get Conflict ("environment
has an active run"). Seen on unsharded run 38732150492 and twice on shard 2,
where the test now runs earlier on a fresh cluster.

Wait until the environment's status.activeRun is gone or expired (the
provider's own admission rule) before acquiring, bounded at 45s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Give the execution shards a job-owned Go module and build cache, saved once
per go.sum by shard 1 outside pull requests. The shared setup-go entry never
warmed ko's -trimpath compiles and lost its save race to the sibling job.

Compile the host-side templates tool and qualification test binary with
ko's CGO_ENABLED=0 -trimpath configuration so they reuse ko's packages, and
start the test compile right after the ko builds. Load the workload and its
two derivatives, which share the Go base layers, from one archive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdimitrov rdimitrov changed the title ci(k8s-e2e): shard execution qualification across three Kind clusters ci(k8s-e2e): shard execution qualification and cut provisioning time Oct 20, 2026
@rdimitrov
rdimitrov merged commit 7ac90c4 into main Oct 20, 2026
77 checks passed
@rdimitrov
rdimitrov deleted the ci/shard-k8s-execution-e2e branch October 20, 2026 12:19
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 23, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant