Skip to content

ADR-0022: Switching a scenario on with a per-cluster branch, on Kind and the lab

  • Status: Accepted
  • Date: 2026-11-03

Context

Stage 0 is done when every scenario can be reproduced with one command (design 13). There are six scenarios (#34 to #39), and their harness (#33) needs make scenario-<name> and make scenario-reset against the current kube context. This ADR decides how that command breaks the cluster and on which clusters it runs. Four facts limit the choice:

  • The broken object must come from Git. A remediation pull request can be made only for an object that a Flux Kustomization applies from one plain manifest (ADR-0012, design 8.2). The value in that file must equal the live value, and the path's kustomization file may hold only apiVersion, kind, metadata and resources: components, patches and generators stop the mapping with NeedsIntervention. Spec fields of the Flux Kustomization such as components, patches and postBuild stop it too. kubectl apply or kubectl patch of a broken manifest therefore cannot produce the positive case (OOM, #36, the v0.1.0 acceptance in #58).
  • The pull request targets the branch Flux tracks. The GitRepository must track a branch (spec.ref.branch), and that branch must equal the repository's targetBranch in RemediationSettings. GitBranch accepts names such as cluster/lab and refuses the shadewright/ prefix, which the GitHub adapter keeps for its own head branches.
  • main of shadewright-fleet is protected. Changes reach it only through pull requests with the required checks Conventional PR title, Render manifests, Harness tests, Kind baseline, Workflow lint, Dependency review and Path guard, and the operator's GitHub App never bypasses the ruleset (fleet AGENTS.md). Render manifests (scripts/render.sh) renders every kustomization under clusters/, infrastructure/ and apps/ with kubeconform -strict. It leaves scenarios/ out on purpose: those files are broken, and the script says the scenario harness renders them.
  • Where things run. End-to-end tests run on Kind in GitHub Actions, and the AKS lab is applied for a session and destroyed after (ADR-0008). On the lab, Flux is installed by scripts/lab.sh in shadewright-azure after the Terraform apply (see the amendment of 2026-11-04; it was the AKS Flux extension before): a GitRepository named fleet that tracks var.fleet_branch (default main) and polls every 60 seconds, plus a Kustomization lab that applies ./clusters/lab with the Azure values as postBuild substitutions, which the lab root hands over as its flux output. clusters/lab applies infrastructure and then apps, both with prune: true. The demo workloads go into apps/demo/, which has no substitutions, so ADR-0012 can map them.

The criteria, from #32: one command switches a scenario on and one command resets to healthy; it works on Kind without Azure; branch protection on main stays intact; the agent's pull request still targets the branch Flux tracks. Two more come from the invariants: changes go through Git only (invariant 3), and the lab is paid only while it runs.

Options for switching a scenario on

Switch Reset Kind without Azure main protection Agent's PR targets the tracked branch ADR-0012 can map the object Render check
1. kubectl apply or patch of the broken object One command One command, or wait for Flux to correct the drift Yes Intact Not applicable: no mapping No: the file and the live value differ Not involved
2. A pull request to main that swaps a plain file in apps/demo/ A PR, then a review and a merge Another PR Only for one cluster at a time, since every cluster tracking main breaks together Intact, but every scenario uses the admin bypass to merge the maintainer's own PR Yes (main) Yes Runs on the scenario; the invalid-manifest scenario (#39) cannot pass it
3. Kustomize components in apps/demo/, switched on by a commit One commit (on main, a PR as in option 2) One commit As option 2 As option 2 Yes No: components in the kustomization file stops the mapping As option 2
4. One Flux Kustomization per scenario (path ./scenarios/<name>), created or resumed with kubectl or flux One command Delete or suspend it Yes Intact Yes Only if the file in scenarios/<name>/ is in the policy's allowedPaths, and the same Deployment from apps and from the scenario makes two Kustomizations fight over it The file the agent patches is in scenarios/, which the render check skips
5. Each cluster's Flux tracks its own branch, which the harness moves forward one commit at a time: a scenario on top of main's tree, or main's tree again (recommended) One command: commit and push to that branch One command: commit main's tree to that branch Yes: Kind reads the same public repository Intact: the harness never writes to main Yes: the cluster's branch Yes: the broken file is a plain manifest in apps/demo/ Stays a gate on main and on the agent's PRs; scenario commits are rendered by the harness

Option 1 is what the design already rules out: a patched object no longer equals its file, and Flux reapplies the file on its next reconcile. Option 4 creates Flux objects outside Git and keeps the broken file outside apps/demo/, where #34 to #39 say only the demo workloads change and #58 limits the policy to apps/demo. Options 2 and 3 keep the most realistic setup (the agent's PR goes to protected main), but each switch and reset is a reviewed pull request, a scenario on one cluster breaks every cluster that tracks main, CI cannot switch scenarios at all, and #39 (a manifest that does not render) can never merge without bypassing a required check.

Options for where scenarios run

  • Kind only: free and needs no Azure, but has no workload identity, Key Vault signer or managed model (ADR-0008), so it cannot run the diagnosis and pull request loop of #58.
  • The lab only: the real loop, but every iteration on a scenario costs node hours, and CI cannot run it.
  • Both: Kind reproduces symptoms and checks the healthy baseline, locally and in CI; the lab runs the full loop when a session is up.

For Kind, Flux can read the public shadewright-fleet repository over HTTPS, as on the lab, or a Git server inside the Kind cluster. A local server works offline and in CI without any write token, but it is one more component to pin, its URL differs from the lab's, and no pull request can be opened against it (the only GitProvider is GitHub).

Decision

  1. Each cluster tracks its own branch. Flux on a cluster tracks cluster/<cluster> (cluster/lab for the AKS lab, cluster/kind for a local Kind cluster), never main. Between scenarios that branch holds the same tree as main (ADR-0012 compares files at the branch head, not commits). RemediationSettings on that cluster set targetBranch to the same branch, so the agent's pull requests go there, as ADR-0012 requires. One value sets both. The GitRepository side exists: on the lab it is the variable fleet_branch of the lab root, which reaches the GitRepository through the flux output of lab/flux.tf (default main, set to cluster/lab in the lab's git-ignored terraform.tfvars, as the README of shadewright-azure describes), and on Kind scripts/kind.sh uses FLEET_BRANCH (default cluster/kind). The RemediationSettings side is still manual: the fleet installs the agent through clusters/lab/shadewright.yaml (path ./infrastructure/shadewright-lab, with its own postBuild), but the RemediationSettings object and its targetBranch are set by hand from config/samples. If the branch is later forwarded from the same variable, it has to go through the postBuild of clusters/lab/shadewright.yaml, not infrastructure.yaml, because substitutions apply only to the Kustomization that declares them. The CI baseline cluster is the one exception: its GitRepository tracks the pull request's ref (refs/pull/<n>/head), read-only, and the wait step checks that Flux fetched the commit under test, and the harness refuses to run there because Flux then tracks no cluster/ branch.
  2. A scenario is one commit on that branch. scenarios/<name>/ holds README.md, expected.yaml and the broken versions of files under apps/demo/, at the same relative paths. make scenario-<name>:
    • takes the cluster as an explicit argument (make scenario-oom CLUSTER=kind), reads the branch from the GitRepository flux-system/fleet in the current kube context, and refuses unless CLUSTER is kind or lab, that branch is exactly cluster/<CLUSTER>, nothing else (tag, semver, ref name, commit) is pinned, the GitRepository URL is the repository of the Git remote, and the branch exists on the remote (the maintainer creates cluster branches, the harness never does); so it can never push main or another cluster's branch, even when a copied entry point names the wrong one;
    • builds a tree from the current origin/main (never from the working tree) with the scenario's files copied over apps/demo/ (only paths inside apps/demo/, validated against scenarios/schema), renders apps/ with the same tools and versions as scripts/render.sh (a render failure is accepted only for scenarios that declare render: fails in expected.yaml, such as #39), and commits that tree on top of the head of the cluster's branch;
    • pushes that commit as a fast-forward, never a force push, then may ask Flux to fetch now (flux reconcile source git fleet, which only sets an annotation);
    • honours SCENARIO_REF (a ref other than origin/main to take the scenario's files from, for trying a scenario that is not merged) only together with DRY_RUN=1, which builds and renders the commit but pushes nothing. A push always builds the scenario from origin/main, so unreviewed local files never reach a cluster under the bypass of decision 5. This rule is decided here; the guard is implemented in the fleet pull request pkalin/shadewright-fleet#22.
  3. Reset is a commit of main's tree. make scenario-reset CLUSTER=<cluster> commits the tree of the current origin/main on top of the cluster's branch and pushes it as a fast-forward. It is a no-op when the trees are already equal, and prune: true on apps removes anything a scenario added. One scenario is on at a time per cluster. The branch only moves forward, so its history records every scenario and reset.
  4. Scenarios run on both Kind and the lab. Kind (pinned Kind and Flux versions, #33) reproduces every symptom and runs the baseline check in CI, without Azure. The lab runs the diagnosis and the agent's pull request (#58). Kind reads the public repository from GitHub like the lab, so the two clusters differ only in their branch and entry point; a Git server inside Kind is not used for now. The CI baseline job points Flux at the pull request's ref, read-only, waits until Flux has fetched the commit under test, and does not push.
  5. The cluster branches get their own rulesets, which mirror main's protections for the agent's pull requests. Two rulesets on cluster/*:

    • "cluster branches: reviews and checks", with the pull request rules of main except the checks that guard the fleet's own tooling: required checks Conventional PR title, Render manifests and Path guard, code owner review, one approval of the latest push, stale approvals dismissed, review threads resolved, squash only. The repository admin role may bypass it (always, since the harness pushes without a pull request), so the harness can push its commits directly;
    • "cluster branches: forward only", with non_fast_forward and deletion and no bypass actor at all, so nobody, the harness included, can force-push or delete a cluster branch.

    Which checks run on a pull request to a cluster branch follows from the workflow triggers at origin/main of the fleet. Render manifests and Path guard have no branch filter on the pull request trigger, so they run there (Path guard runs on pull_request_target). Harness tests, Kind baseline and Workflow lint filter only their push trigger to main, and Dependency review has a pull_request trigger only, so all four run on such pull requests too, but they test the fleet's tooling and are not required on cluster/*.

    Path guard runs the workflow, allow list and script from the base branch's files, not the pull request's. A cluster branch therefore has to hold main's tree before an agent pull request can pass the guard. Today cluster/lab and cluster/kind still sit at a commit that predates Path guard, its allow list and CODEOWNERS, so each must be reset with make scenario-reset CLUSTER=<cluster> first. That reset is the first step of every run, and the first commit of a new cluster branch must be one. A scenario commit keeps main's tree outside apps/demo/, so the guard keeps working after it. With code owner review, a change to .github/, Flux config or RBAC in an agent pull request needs a person, as on main.

    The operator's GitHub App is never a bypass actor on either, so its pull requests to cluster/lab wait for a person, as they would on main. The rulesets are repository settings made separately from this ADR. Both are live: "cluster branches: reviews and checks" requires code owner review and the checks Conventional PR title, Render manifests and Path guard, and "cluster branches: forward only" has no bypass actor. Design 8.4 says that the protected branch Flux tracks is cluster/<cluster> on the clusters that run scenarios.

Consequences

  • One command switches a scenario on and one resets it, on any cluster whose Flux tracks a cluster/ branch, and nothing about a scenario reaches main. main keeps its ruleset, and every change to it is still a reviewed pull request that renders.
  • The broken object is a plain manifest in apps/demo/ delivered by the apps Kustomization, so ADR-0012 maps it and the OOM pull request (#36, #58) changes one line in apps/demo/, inside the policy's allowedPaths.
  • Invariant 3 holds: the scenario, the agent's change and the reset are all Git commits that Flux applies; no object is changed with kubectl except the reconcile annotation. The agent still writes only shadewright/ branches and opens pull requests against the branch Flux tracks.
  • The agent's pull requests target cluster/lab, not main. The demo of branch rules and, at stage 4, of CODEOWNERS and auto-merge is only as strong as the cluster/* ruleset, which therefore has to mirror the rules on main for the App. A fix merged into cluster/lab is discarded at the next reset, on purpose: the scenario stays reproducible.
  • Scenario commits are pushed directly under the bypass of the repository admin role, so no required check gates them; the harness renders them instead, and builds them only from origin/main on a real push (decision 2). That bypass covers every token of that role, as the pull_request bypass on main already does; a dedicated harness identity (a second App or machine user whose credentials live only where the harness runs) would narrow it, at the cost of one more identity to manage. No identity can rewrite or delete a cluster branch. Render manifests and Path guard run on the agent's pull requests to cluster/lab (neither has a branch filter on its pull request trigger), and the cluster/* ruleset makes them required there.
  • Known limit for v0.1.0: the admin bypass is always on for cluster/*. Flux on a cluster applies the whole tree from its cluster branch, including clusters/ and infrastructure/, where the agent install and its RBAC live. A direct push under the bypass therefore changes cluster infrastructure with no review and no required check. It can also edit the files that later check the agent's pull requests (.github/workflows/path-guard.yml, .github/shadewright-paths.txt, scripts/path_guard.py and CODEOWNERS, all read from the base branch), and that change would last until the next reset. This is accepted for a one-maintainer lab that is applied for a session and destroyed after; the follow-up below removes it.
  • A reset while an agent pull request is open changes the target file at the head of its base branch. The freshness check catches that, because it compares the file at the head of the target branch with the previous value and reruns the mapping (design 5.1 and 6): the request becomes Superseded and its pull request is closed. That is a stage 3 test case. It works only if the reset changes the previous value, so every scenario that expects a pull request breaks the very field the action patches.
  • Kind has an entry point of its own (clusters/kind/) that applies apps/ and the infrastructure the scenarios need (the demo namespace, KEDA, and Prometheus for the OOM evidence, ADR-0017) without the Azure substitutions. The Shadewright install with workload identity is done and lives in a path that only clusters/lab applies: clusters/lab/shadewright.yaml applies ./infrastructure/shadewright-lab.
  • The lab switches from main to cluster/lab by setting fleet_branch in the lab's git-ignored terraform.tfvars, or by changing its default; either is a Terraform change that goes through plan and an explicit approval. The lab still costs node hours only while a session is up, and scenario work starts on Kind.
  • Running scenarios (not only the baseline) in CI would need a token that can push cluster/ branches from a workflow; this ADR does not grant one.

Alternatives considered

  • kubectl apply or patch of a broken manifest (option 1): rejected by design 13 and 8.2; the object no longer matches its file, and Flux reverts it.
  • A pull request to main per scenario (option 2): the most realistic target branch, but switching is not one command, it breaks every cluster at once, it cannot run in CI, and #39 cannot pass the required render check.
  • Kustomize components (option 3): components in the kustomization file is outside what ADR-0012 maps, so the positive case would end in NeedsIntervention.
  • One Flux Kustomization per scenario, switched with kubectl (option 4): Flux objects created outside Git, the broken file outside apps/demo/ and outside the render check, and two Kustomizations owning one Deployment.
  • A second GitRepository, planned as the follow-up: only the apps Kustomization reads cluster/<cluster>, while clusters/ and infrastructure/ stay on protected main. A direct push to a cluster branch could then change only apps/, never the agent install or its RBAC. Not done now because it changes the Flux layout on both clusters and the lab's Flux install (lab/flux.tf and scripts/lab.sh), and ADR-0012 and targetBranch must keep seeing the one branch that holds the demo workloads.
  • A ruleset bypass actor of type DeployKey (a write deploy key used only by the harness) in place of the repository admin role: the bypass would then cover one credential instead of every token of the role. A possible follow-up, together with the second GitRepository.
  • A Git server inside Kind: offline and token-free, but no pull requests and one more component; worth revisiting if CI must run scenarios without a write token.
  • Force-pushing the cluster branch to main or to main plus one commit: simpler history, but it needs a bypass of non_fast_forward, so a leaked token or a harness bug could rewrite what the cluster runs without a trace.
  • One branch per scenario, with Flux pointed at it: switching a scenario would change the GitRepository (on the lab, a Terraform change followed by the Flux step of scripts/lab.sh), which is slow and puts Flux configuration on the scenario path.

Amendments

  • 2026-11-04: the lab's Flux is no longer the AKS Flux extension. lab/flux.tf in shadewright-azure keeps only an output (repository, branch, postBuild substitutions) and scripts/lab.sh up installs Flux after the Terraform apply, because the extension was slow: on 2026-11-04 it took 17 minutes 15 seconds to create in Terraform, while its own controller pods were Running about 2 minutes after the node was Ready; AKS itself took about 4 minutes. The install is the pinned release manifest (checksum verified, controller images pinned by digest, the same release as Kind), the GitRepository fleet and the root Kustomization lab (it was fleet-lab under the extension, as observed on the lab on 2026-11-04); no flux bootstrap, no Terraform kubernetes provider. The multi-tenancy the extension enables by default is replicated (Microsoft Learn, multi-tenancy): the kustomize, helm and notification controllers run with --no-cross-namespace-refs, and the kustomize and helm controllers with --default-service-account=flux-applier, a ServiceAccount in flux-system bound to cluster-admin, which is what the extension's cluster-scope configuration granted. The decisions of this ADR (a branch per cluster, the same GitRepository and Kustomization on Kind and the lab, no write access to main) are unchanged, and nothing is widened: no new credential, permission or write path (the cluster-admin binding replaces the one the extension created), and the install runs from the administrator's own session after a typed yes (shadewright-azure#16, shadewright-fleet#25).