Skip to content

fix(k8s): a read failure names the cluster context it read; the binding block typechecks (#1488, #1455) - #1610

Merged
lex00 merged 2 commits into
mainfrom
fix/1488-1455-cluster-binding
Aug 9, 2026
Merged

lex00 merged 2 commits into
mainfrom
fix/1488-1455-cluster-binding

Conversation

@lex00

@lex00 lex00 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Closes #1488. Closes #1455.

Both issues were mostly resolved on main already — #1507 made a declared
binding a selection rather than an ambient-policed check, and #1405/#1344
gave the k8s lexicon its configSchema and the ChantConfig augmentation.
This PR lands what each issue still asked for.

#1488 — read failures name the cluster they read

What #1507 left open is the issue's second ask: a read-failed with no
mention of which cluster was read. That is the exact scenario the report
opens with when no binding is declared — another project's k3d cluster takes
the ambient context and the estate goes grey with nothing to go on.

The fix sits at the client-construction seam. createK8sClient stamps a
context note onto every API and transport failure it throws — the resolved
context name plus how it was selected — and classifyApiFailure appends it
to the unobserved detail after the one-line cap, so it survives truncation.
The connector (defaultK8sConnector) supplies the selection story:

  • context "prod-eks" (bound by k8s.profiles.prod.context)
  • context "k3d-kubemicrovm-local" (ambient; no k8s.profiles.local binding)
  • context "prod-eks" (explicit --context)

Every read path — describeResources, deep observe, the discovery-driven
runtime sweep, the chant kube verbs, the Op activities — already builds
its client through defaultK8sConnector and classifies through
classifyApiFailure, so no caller needed touching. GCP observation moved to
REST in #1209 and no longer shares the kubectl path.

The issue's exact message shape included what the profile declares when it
disagrees with ambient; since #1507 that disagreement cannot occur — a
declared context is used, so a failure against it names the bound context,
and the ambient phrasing appears only when nothing is declared. A bound
context absent from the kubeconfig still refuses with the context name and
the k8s.profiles.<env>.context binding (KubeConfigError, from #1507),
never by falling back to ambient — covered by existing tests.

Also retires the doc comments in config.ts, kube/connect.ts and
kube/get.ts that still described the pre-#1507 mismatch refusal.

#1455 — the binding block typechecks, proven

The augmentation, schema and configSchema wiring the issue asks for landed
with #1405/#1344, but the k8s lexicon lacked the guard the forgejo lexicon
carries. config-augmentation.test.ts now holds the issue's reproduction
verbatim under satisfies ChantConfig (root import, as reported), plus
schema cases for the namespace's most expensive typos: profile and
contxt are rejected rather than silently leaving the environment unbound —
which is precisely the setup that produced #1488.

Sweep: other lexicons

Per the issue's closing question, checked every lexicon for a *ChantConfig
exported for a key core does not carry. Three lexicons own config
namespaces — k8s, temporal, forgejo — and all three declare configSchema
plus the module augmentation. The aws lexicon reads ChantConfig.stacks,
which core itself declares (#1161). The helm lexicon reads the k8s
namespace through resolveClusterTarget but owns no namespace and exports
no config type. Nothing else needed the pattern, so there is no third
commit.

Verification

  • npx vitest run lexicons/k8s/src packages/k8s-client/src packages/core/src/kubectl-context.test.ts packages/core/src/lexicon-config.test.ts — 1330 passed, 1 skipped
  • npm run build -w @intentius/chant-k8s-client — clean
  • npm run build -w @intentius/chant-lexicon-k8s — clean
  • just build (core tsc) — clean

lex00 added 2 commits August 8, 2026 23:16
resolveClusterTarget stopped policing ambient in #1507 — a declared
binding is used, not checked — but a read that still fails said nothing
about which cluster it talked to. The reporting scenario: no binding
declared, another project's k3d cluster steals the ambient context, and
every declared resource goes grey with a bare read-failed.

The typed client now stamps a context note onto every API and transport
failure at construction — context name plus how it was selected — and
classifyApiFailure appends it to the unobserved detail after the one-line
cap, so it never truncates away. The connector supplies the selection
story: 'bound by k8s.profiles.<env>.context', 'ambient; no
k8s.profiles.<env> binding', or 'explicit --context'. Every read path
(describeResources, deep observe, the runtime sweep, kube verbs, Op
activities) classifies through the same seam, so none of them needed
touching.

Also retires the stale pre-#1507 doc comments that still described the
ambient-mismatch refusal.
…ected (#1455)

The augmentation and schema #1455 asks for landed with #1405/#1344 —
config.ts declares 'k8s' on ChantConfig, config-schema.ts is the runtime
half, plugin.ts wires it as configSchema — but nothing proved the issue's
reproduction compiles, and the k8s lexicon lacked the config-augmentation
guard the forgejo lexicon carries. Port it: the reproduction verbatim
under satisfies ChantConfig, plus schema cases for the failure the
namespace most cares about — an unknown key ('profile', 'contxt') is
rejected rather than silently leaving the environment unbound, which is
exactly the wrong-cluster setup #1488 hit.
@lex00
lex00 merged commit 5591eb2 into main Aug 9, 2026
5 checks passed
lex00 added a commit that referenced this pull request Aug 9, 2026
… publish gate (#1616)

The release recipe rewrites @intentius/* peerDependencies to the new
version but left optionalDependencies alone, so lexicons/k8s kept
@intentius/chant-k8s-client at ^0.42.1 across the 0.44.0 bump. Under 0.x
semver that range excludes the workspace's 0.44.0, npm nests the published
0.42.1, and publish.yml's test job typechecks the lexicon against a client
missing contextLabel (#1610) and preferredGroupVersions (#1609) — which is
exactly how the chant-v0.44.0 publish run died before publishing anything.

Pins the dep to ^0.44.0 now and teaches the recipe to rewrite
@intentius/* optionalDependencies (a literal "*" stays untouched) so the
next lockstep bump carries it.
lex00 added a commit that referenced this pull request Aug 10, 2026
…e live wire (#1625)

From behold#192: a Flux-deployed k8s project declares no metadata.namespace
(the controller stamps targetNamespace at apply), so the live read scopes to
the context's default namespace, finds nothing, and correctly reports absence
— painting weeks-old running infrastructure pending. Every layer is
spec-correct; the report cannot explain itself.

The observation envelope now carries an optional queried map — the resolved
address each read was issued against, keyed by entity name. Purely additive:
classification still reads only resources/unobserved and the #1089 tri-state
does not shift. The map is the only record an OBSERVED-ABSENT entity gets
(absence is spelled 'in neither map'), and unobserved entries carry the
address inline as UnobservedEntity.queried.

- k8s-client grows pathFor(ref): the exact request path read() would GET,
  namespace defaulting made visible; undefined when discovery does not serve
  the kind.
- The k8s reader resolves the address before each read and stamps it on every
  verdict; the observeEntities harness accepts queried on all three
  EntityObservation variants for the other native observers.
- lifecycle diff --live --json emits resources.queried per lexicon and
  queried per unobserved row; the human report shows
  'web [queried /apis/apps/v1/namespaces/default/deployments/web]' on missing
  and unobserved lines. lifecycle plan carries the same address per change-set
  entry (a create's address is the one the provider confirmed absent).
- The #1610 context note now LEADS the unobserved detail instead of trailing
  it: consumers truncate a reason to its first line / ~160 chars, and a note
  appended after a long error vanished exactly when it mattered.

Closes #1620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant