Repository navigation
feat(k8s): owner-referenced children are runtime, not orphans (#1077) - #1180
Merged
Merged
Conversation
A Pod a declared Deployment's controller creates is live and undeclared, the same shape the diff engine has always classified `orphan`. That makes `lifecycle plan` propose deletes for things the controller simply recreates. `ownerReferences` distinguishes an expected runtime child from a genuine orphan; no other chant substrate maintains that chain. Core owns the new classification (`OwnerChainVerdict` in packages/core/src/owner-chain.ts, a pure bounded/cycle-safe chain walker) and threads it through `diffLive` (new `runtimeChildren` bucket), `buildChangeSet` (new `runtime` action, never delete/adopt), and the graph overlays (`_status: "runtime"` instead of `warn`/foreign). An unresolved chain (unreadable hop, cycle, depth bound) stays conservative and routes as `orphan`, composing with #1168's tri-state. The k8s lexicon supplies the chain: describeResources() now scans Pods in the namespaces of entities it just resolved and walks each one's ownerReferences (reading past undeclared intermediates like a ReplicaSet) against the declared/observed set from the same call. Every consumer change is additive; a lexicon that never sets `ownerChain` is unaffected.
This was referenced Jul 28, 2026
This was referenced Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1077. Part of epic #1073.
What was asked, restated
The diff engine has exactly one bucket for "live but chant never declared it":
orphan, which routes to adopt-or-delete. That's correct for the AWS case #1014/#1015 model (an out-of-band console-added SNS subscription). It's wrong on Kubernetes: a Pod a declared Deployment's controller created is live and undeclared, but it isn't drift and it isn't abandoned — it's the runtime doing its job, and deleting it just gets it recreated.ownerReferencesis the mechanism that tells the two cases apart, and no other chant substrate maintains that chain.The ask: walk a live, undeclared object's
ownerReferenceschain, transitively, cycle-safe, bounded. If it reaches a declared entity, classify the object as a new category —runtime— distinct from orphan and from drift, carrying which declared entity owns it. A chain that's genuinely unowned, resolves to something foreign, or can't be fully verified staysorphan, exactly as today. Thread this through whatever already renders orphans (diff --live,plan, the graph overlay), additively, the way #1168 threaded its tri-state through the same set of consumers.Classification rules
ownerChain.rootdeclaredruntimeChildrenruntimeunownedorphanadopt/delete(ownership-marker driven, unchanged)foreignorphanadopt/deleteunknownorphanadopt/deleteruntimeverdictownerChainorphanadopt/deleteruntimeis never escalated todelete, even if a runtime child happens to carry chant's own ownership marker (e.g. via label propagation) — that check runs before the ownership-marker branch inbuildChangeSet.Where it lives
packages/core/src/owner-chain.ts(new) —OwnerChainVerdict(declared | unowned | foreign | unknown) andclassifyOwnerChain(), a pure, depth-bounded (default 12), cycle-safe walker over a lexicon-supplied node map. Core owns this per the issue's own division of labor ("core owns the category and the diff-engine wiring; the k8s lexicon supplies the chain").packages/core/src/lexicon.ts—ResourceMetadata.ownerChain?: OwnerChainVerdict, optional, additive.lexicons/k8s/src/api/owner-chain.ts(new) —resolveK8sOwnerChain(), the chain-supplying half: reads each intermediate owner through the typed client (@intentius/chant-k8s-client, feat(k8s): typed API client — kubectl shell-outs retired (#1074) #1177) — there's no server-side "who ultimately owns this" query, Kubernetes' own GC doesn't have one either — then hands the assembled chain to core'sclassifyOwnerChainfor the verdict.lexicons/k8s/src/describe-resources.ts— after declared entities resolve, scans Pods in the namespaces those entities live in and classifies each one. Scoped deliberately narrow: Pods only (the concrete case the issue and its acceptance criteria name), and only the namespaces this observation already touched — not a cluster-wide sweep. Widening to other controller-spawned kinds (ReplicaSet, Job, …) is the same walk repeated; noted as a follow-up rather than done here, matching feat(aws): deep observation surface — Cloud Control reader for undeclared-property & out-of-band-child drift #1015's own "prove it narrow, then widen" precedent.Consumer/wire changes (additive)
diffLive(live-diff.ts) — newruntimeChildren: RuntimeChildResource[]bucket;orphanexcludes anything withownerChain.root === "declared". A runtime child rolling to a new name between snapshots is notdisappeared, and its own transient status change is notdriftedSinceSnapshot— both would just reintroduce the noise this issue removes.buildChangeSet(change-set.ts) — newChangeActionvalue"runtime", entry fieldruntimeOwner?: string.gitlabMrReportexcludes it automatically (it only ever readscreate/update/deleteoffsummarize()).chant lifecycle diff --live/plan(lifecycle.ts) — new RUNTIME section in both human renders; JSON output carries the new fields for free (no shape change needed, same as fix(core): observation distinguishes not-observed from absent — reads stop synthesizing confident actions (#1089) #1168's additive fields).graph-ir.ts) —IRNode.runtimeOwner?: string;overlayGraphs/sourceOverlayGraphstag_status: "runtime"instead of"warn"for a live, undeclared node whose chain resolves to a declared entity.lifecycle plan --json'ssummarizePlancounts every non-noopaction as a pending change today, same situation fix(core): observation distinguishes not-observed from absent — reads stop synthesizing confident actions (#1089) #1168's"unobserved"value left it in; a"runtime"entry will be counted there until behold'sLifecyclePlanEntryunion widens. Flagging it here rather than fixing it in this repo, matching fix(core): observation distinguishes not-observed from absent — reads stop synthesizing confident actions (#1089) #1168's own precedent. The graph overlay's_statushandling already degrades gracefully for an unrecognized value (overlayStatus()returnsundefined→ "no verdict"), so"runtime"there is a soft landing even before behold's viewer recognizes it explicitly. This is the precondition epic: Kubernetes runtime surface behold#84/feat: chant migrate CLI (--emit yaml) #86 (runtime tier below the declaration boundary) are waiting on.GCP: does it inherit this mechanically?
No, and it shouldn't be forced. GCP's Config Connector observation (
lexicons/gcp/src/describe-resources.ts) shellskubectlper declared entity — it was deliberately kept off the typed client in #1177 ("a separate lexicon and a separate decision"). Two things don't transfer:resolveK8sOwnerChainis built on@intentius/chant-k8s-client'slist/readIfPresent; GCP has neither. A GCP equivalent would need its own kubectl-based reader, mechanical repetition of the same walk, not reuse.What does compose for free: the core classification contract (
OwnerChainVerdict,ResourceMetadata.ownerChain, the diff/change-set wiring) is fully generic. If GCP ever gains a reason to populateownerChain, every downstream consumer already understands it — no core change needed.Tests
packages/core/src/owner-chain.test.ts(new, 13 tests) — the pure walker: declared chain, immediate-declared, unowned, foreign, unreadable start/intermediate hop, dangling reference, missing start id, 2-cycle, self-cycle, depth-bound-exceeded (conservativeunknown), exact-at-bound (still resolves), custommaxDepth.packages/core/src/lifecycle/live-diff.test.ts— newdescribe("runtime children vs orphans")block: declared-chain →runtimeChildrennotorphan; unowned/foreign/unknown →orphan; no-ownerChain-at-all lexicon unaffected; rolling name isn'tdisappeared; own status churn isn'tdriftedSinceSnapshot.packages/core/src/lifecycle/change-set.test.ts—runtimeaction for a declared chain (never delete/adopt), ordering guard (marker-carrying runtime child still classifiesruntime), unowned/foreign/unknown stayadopt, unaffected-lexicon regression, summarize/render surface it,gitlabMrReportexcludes it.packages/core/src/graph-ir-live.test.ts—buildLiveGraphIrcarriesruntimeOwneronly for a resolveddeclaredchain; both overlay functions tag_status: "runtime"distinct from"warn".lexicons/k8s/src/api/owner-chain.test.ts(new, 10 tests) —resolveK8sOwnerChain: direct declared match (no extra reads), Pod→ReplicaSet→Deployment (one extra read, past the undeclared intermediate), fully-foreign chain, 404 owner → conservativeunknown, throwing owner read (RBAC) → conservativeunknown, a real cycle terminates rather than hanging, custommaxDepthbounds the fetch count, missing-uid start, multiple owner refs picks thecontroller: trueone.lexicons/k8s/src/describe-resources.test.ts— newdescribe("runtime children (#1077)")block against the real typed client with a faked transport (fakeCluster): Pod-owned-via-ReplicaSet-by-declared-Deployment →runtime; genuinely unowned Pod →orphan; Pod owned by something never declared →orphan;--ownedwithholds an unrelated Pod but keeps a runtime child; a Pod that's itself declared is never duplicated; a Pod-list failure for one namespace is best-effort (declared entities still resolve); no namespaced entities → no Pod scan at all.No cluster or kubeconfig access anywhere — every k8s test drives the real typed client against a literal kubeconfig with the transport faked (
fakeCluster/fakeRequestLayer), same as every other test in this file.Gate evidence
Test plan
just buildjust lintjust test(9726 passed | 5 skipped)npm run prepack -w @intentius/chant-lexicon-k8sjust check-lexicons(11/11, no regression)just fold-differential(zero drift vs origin/main)just sandbox-differential(zero drift vs origin/main)examples/k8s-client-boundary.test.ts+examples/sandbox-execution-boundary.test.ts(both unchanged)