--- source_keys: - adr-0032-action-tiers - delivery-guard-flux-allowlist --- # Applied check flow Answer one question: has this Kustomization applied this commit? Read tier only; every command here is in the `SKILL.md` tier table. ## Inputs - Kustomization name and namespace. No namespace given → `flux-system`, and say so in the output. - Target commit: a full 40-character SHA. Given a short SHA or a branch name, return `unverifiable: need a full commit SHA` and stop; do not resolve it yourself. - Wait cap: the caller passes a cap in minutes. It counts 60-second pauses, not wall-clock time, so a cap of N allows at most N pauses. No cap given → read once and return; never invent a wait. - HelmReleases, optional: a list of `/`. Given → check only those. Not given → check only the HelmReleases this Kustomization applies itself (step 3). - Kubeconfig path, optional: given → prefix every command below with `KUBECONFIG=`. ## 1 — Read the Kustomization Run exactly, substituting name and namespace, behind the `KUBECONFIG=` prefix when given: ```bash kubectl get kustomization -n -o jsonpath='{.spec.suspend}{"|"}{.spec.sourceRef.kind}{"|"}{.spec.sourceRef.namespace}{"|"}{.spec.sourceRef.name}{"|"}{.status.lastAppliedRevision}{"|"}{.status.lastAttemptedRevision}{"|"}{.status.conditions[?(@.type=="Ready")].status}{"|"}{.status.conditions[?(@.type=="Ready")].reason}{"\n"}' ``` An empty source namespace means the Kustomization's own namespace. Gates, in order: - `suspend` is `true` → verdict `suspended`. Stop; never resume it. - Source kind is not `GitRepository` → verdict `unverifiable: source is ; its revision carries no commit SHA`. Stop. ## 2 — Extract SHAs A Git revision reads `@sha1:`, or `sha1:` when the source pins a commit. Flux before 2.0 wrote `/`. Take the 40-hex SHA after `sha1:`, or after the last `/` for the legacy form. Compare full SHAs only. ## 3 — Classify "At or past the target" means the SHA equals the target, or the target is its ancestor. Test ancestry in the repo checkout with `rtk git merge-base --is-ancestor `; the exit code is the answer. Exit 0 → at or past; exit 1 → not. Exit 128 (unknown commit) → `rtk git fetch` once and retry; still 128 → `unknown: not in local history`. First match wins: 1. Applied SHA at or past the target → `applied`, whatever Ready says now. Applied SHA past the target → note `superseded by `. Attempted SHA differs from the applied one and Ready is `False` → note `later revision failing`; that failure belongs to the later revision, never to this target. 2. Attempted SHA at or past the target, Ready `False` → `failed`: the target is not applied and the attempt carrying it fails. Record the Ready reason and the failing HelmReleases (below), then read `references/diagnose.md` and follow it from its step 3 for this Kustomization. 3. Attempted SHA at or past the target, Ready `Unknown` → `pending: reconciling`. 4. Ready reason `DependencyNotReady` → `pending: waiting on dependency`; name the `dependsOn` objects from `flux get ks -n `'s message. 5. Read the source with `flux get sources git -n `. Source revision not at or past the target and READY `False` → `failed` at the source, since the target cannot arrive; diagnose as in rule 2. Source revision not at or past the target → `pending: source has not fetched the commit`. Otherwise → `pending: queued for the next reconcile`. On `applied`, check the HelmReleases: the caller's list, or else the HelmRelease entries of this Kustomization's own inventory, read with `kubectl get kustomization -n -o jsonpath='{.status.inventory.entries[*].id}'` (an id reads `_
_helm.toolkit.fluxcd.io_HelmRelease`). Never widen to `flux tree` of a root Kustomization: it spans the whole cluster, and an unrelated failing release would block a commit that never touched it. For each release read `kubectl get helmrelease
-n -o jsonpath='{.metadata.generation}{"|"}{.status.observedGeneration}{"|"}{.status.conditions[?(@.type=="Ready")].status}{"|"}{.status.conditions[?(@.type=="Ready")].reason}{"\n"}'`. Observed generation behind generation, or Ready `Unknown` → verdict becomes `pending: helm upgrade in progress`. Ready `False` at the current generation → verdict becomes `failed`, naming the release. A release failing since before this commit is still reported; attributing it is the caller's job. On `failed` by rule 2, read the same releases and name each Ready `False` on the HelmReleases line. A Kustomization with `wait: true` or `healthChecks` whose health check on a release fails is believed, not confirmed, to keep the applied revision at the previous commit, so that release is the failure's likely cause. ## 4 — Poll, only with a cap and a `pending` verdict Each round makes exactly one pause, and every pause counts toward the cap, even one that returns early. Pause on the object the verdict waits for. Kustomization pending: ```bash kubectl wait kustomization/ -n --for=jsonpath='{.status.lastAppliedRevision}'= --timeout=60s ``` `` is the target in the form of the current revision: `@sha1:`, where `` is the text before `@` in the attempted revision, or `sha1:` for a source pinned to a commit. HelmRelease pending, observed generation behind the `metadata.generation` read this round: ```bash kubectl wait helmrelease/
-n --for=jsonpath='{.status.observedGeneration}'= --timeout=60s ``` HelmRelease pending, observed generation already equal and Ready `Unknown`: ```bash kubectl wait helmrelease/
-n --for=jsonpath='{.status.conditions[?(@.type=="Ready")].status}'=True --timeout=60s ``` Waiting on the generation there would return at once and spend a pause without waiting. Never pause with `--for=condition=Ready` while the generation is behind: a release still Ready at its old generation satisfies it before helm-controller has seen the new spec. A non-zero exit on timeout is the normal end of a pause, not an error. After every pause, repeat steps 1–3. Stop polling on any verdict other than `pending`, or once the pause count reaches the cap. At the cap, return the last `pending` verdict as it stands. Never extend the cap, and never `flux reconcile` to hurry it; that is an odd job for a human. ## Output ```text Kustomization: / Target: Verdict: Applied: Attempted: Ready: Source: / at , Ready HelmReleases: , … | none Pauses: of | not polled Note: failing, defaulted namespace, or empty> ``` On `failed`, append the diagnosis output from `references/diagnose.md` below these lines.