Repository navigation
feat(gcp): deep observation — Config Connector managed-fields reuse (#1087) - #1182
Merged
Merged
Conversation
…1087) Implements #1014's deep-observe contract for the gcp lexicon by reusing the k8s row (#1076) rather than writing a second implementation: a Config Connector custom resource is a Kubernetes object too, so it carries the same envelope (status, metadata.uid/resourceVersion/generation/creationTimestamp/ managedFields/selfLink) and the same SSA fieldsV1 encoding for metadata.managedFields. The genuinely shared piece (the managed-fields ownership walk and the generic Kubernetes object envelope/list-map-key conventions) moves out of the k8s lexicon into packages/core/src/managed-fields.ts, the same reason kubectl-context.ts's resolveClusterTarget lives in core — so gcp can reuse it without depending on the k8s lexicon package or on @intentius/chant-k8s-client. lexicons/k8s/src/deep-observe.ts and deep-observe-hooks.ts now delegate to core for that shared half and keep only what's genuinely k8s-lexicon-specific (K8S_SERVICE_DEFAULTS). gcp's own row (lexicons/gcp/src/deep-observe.ts, deep-observe-hooks.ts) reads through the same kubectl-shelled transport describe-resources.ts already uses (factored into resolveGcpKubectlContext/execConfigConnectorGet so neither reader restates it), adds Config Connector's own observed-state annotation noise, and works out the GCP-specific twist on the contested/owned rule: chant's own kubectl-apply path has no distinct "chant" field manager the way the k8s lexicon's typed-client SSA path does (GCP's deploy scripts run plain `kubectl apply -f`, attributing chant's own writes to kubectl's own default manager), so the contested-field rule (a declared field is always diffable regardless of who owns it live) does the work isChantFieldManager does on the k8s side. Gate evidence: - npx tsc --noEmit -p packages/core/tsconfig.json — clean - npm run build -w @intentius/chant-lexicon-gcp — clean - npm run build -w @intentius/chant-lexicon-k8s — clean - npx eslint packages/ — clean - just test — 800 passed | 1 skipped (801 files); 9776 passed | 5 skipped - just check-lexicons — 11/11 lexicons, 17/17 tier-1 checks each - just fold-differential — 104/104, drift: 0 - just sandbox-differential — 103/103, drift: 0 - examples/k8s-client-boundary.test.ts — 38/38, 0 modules importing the client package - node scripts/depcheck.mjs — no undeclared runtime dependencies
This was referenced Jul 28, 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 #1087. The GCP row of #1014, per #1173's per-row checklist and #1181's k8s row (#1076), which this reuses.
What I was asked to do, restated
Implement
observeResourcesDeep()for GCP by reusing the k8s row rather than writing a second implementation. A Config Connector custom resource is a Kubernetes object:kubectl get <kind>.<group> -o jsonagainst a Config Connector-enabled cluster returnsmetadata.managedFields,status, and the rest of the standard object envelope for the same reason a Deployment carries them — the API server on the other end is the same kind of API server. The epic's own table listsmetadata.managedFieldsunder GCP's "field noise" to prune; it's the opposite of noise, and it's available here for exactly the reason #1076 reads it.Three things had to come out of this:
status, generation churn.@intentius/chant-k8s-client(gcp shells kubectl; chant feat(k8s): typed API client — kubectl shell-outs retired (#1074) #1177/feat(k8s): owner-referenced children are runtime, not orphans (#1077) #1180 kept it that way on purpose).What's genuinely shared, and where it lives now
The managed-fields ownership walk (
buildOwnershipSets/walkOwnership, resolving one object'sfieldsV1against its live and declared trees) and the generic Kubernetes object envelope/list-map-key conventions have nothing k8s-lexicon-specific about them — they're Kubernetes API machinery, true of any Kubernetes-shaped object regardless of which lexicon reads it. Rather than have gcp depend on the k8s lexicon package to reach them, I moved them topackages/core/src/managed-fields.ts— the same reasonkubectl-context.ts'sresolveClusterTargetalready lives in core rather than in the k8s lexicon ("GCP's Config Connector observation needs it too, without taking a dependency on the k8s lexicon").K8S_OBJECT_ENVELOPE_PRUNE_PATTERNS—status,metadata.{uid,resourceVersion,generation,creationTimestamp,managedFields,selfLink}. Was k8s-lexicon-private (K8S_UNCONDITIONAL_PRUNE_PATTERNS); now core, exported.k8sListMapOrderKey— Kubernetes' own list-map-key conventions (containers/env/volumes byname, ports bycontainerPort/port+protocol). Needed on the gcp side too: some CNRM kinds embed genuinely k8s-shaped substructures (Cloud Run'sRunServicewraps a Knative pod spec).buildOwnershipSets,OwnershipSets,pruneByOwnership— the three-question rule itself (chant-owned → always diffable; foreign+undeclared → pruned; foreign+declared → contested, kept). Moved out oflexicons/k8s/src/deep-observe.tsverbatim.lexicons/k8s/src/deep-observe.tsanddeep-observe-hooks.tsnow delegate to core for that shared half and re-exportbuildOwnershipSets/OwnershipSetsso nothing changes for an existing importer of that file (its own test suite from #1181 runs unmodified — same 21 tests, same assertions). What stays k8s-lexicon-specific is onlyK8S_SERVICE_DEFAULTS, keyed by chant's own k8s entityType catalog.What's genuinely gcp-specific:
operationForis a k8s-lexicon/typed-client concept generated from cluster discovery this reader never touches.deriveGVK(already indescribe-resources.ts) stands in.cnrm.cloud.google.com/observed-secret-versions, confirmed from Config Connector's own docs) — narrow and evidence-based, since severalcnrm.cloud.google.com/*annotations (state-into-spec,deletion-policy,management-conflict-prevention-policy) are themselves user-authored configuration, not observed state, and blindly pruning that whole family would hide genuine drift on them.describe-resources.tsgained two exported helpers (resolveGcpKubectlContext,execConfigConnectorGet) so the thin and deep readers share the exact cluster-binding resolution andkubectl get -o jsonmechanics rather than each restating them.Same split k8s uses for the same reason:
lexicons/gcp/src/deep-observe-hooks.ts(no transport dependency, imported statically fromplugin.tsbecause core normalizes the declared tree with it whether or not a cluster read ever happens) vs.lexicons/gcp/src/deep-observe.ts(imports./describe-resources.ts, which pulls innode:child_process; reached only viaplugin.ts's dynamicimport(), matching howdescribeResources/exportResourcesare already wired).The manager-identity finding
Chant #1076's rule treats a field as always-diffable when any chant field manager (
chant,chant:<stack>— chant #1075's SSA identity) owns it. That identity is only ever set by the k8s lexicon's typed client applying with an explicit--field-manager. GCP has no equivalent apply activity — every gcp example's own deploy script (e.g.examples/cockroachdb-multi-region-gke/scripts/deploy.sh) runs plainkubectl apply -f dist/*.yaml: classic client-side apply, no--server-side, no--field-manager. kubectl's own hardcoded default field manager for that command iskubectl-client-side-apply— identical to what a human'skubectl apply -f their-own-file.yamlwould record.There is no field-manager name on GCP's real deploy path that distinguishes "chant applied this" from "a person applied this." (Config Connector's own controller is distinguishable — it records itself as
cnrm-controller-manager, per the k8s-config-connector source's ownControllerManagedFieldManagerconstant, confirmed via its docs/source rather than assumed.)Working out whether that breaks the contract: it doesn't, because question 3 of the three-question rule (is the path declared?) already covers it. Chant's own kubectl apply always applies the exact built manifest, so any field chant's own most recent apply set is, by construction, also in
declaredRooton the very next read.chantOwned(manager iskubectl-client-side-apply, notchant), but foreign-owned and declared → contested → kept diffable anyway. Same outcome as chant-owned would have been.kubectl edit, or their ownkubectl apply -f) that chant does declare: foreign-owned and declared → contested → surfaces as drift. This is the issue's acceptance criterion 1.isGcpChantFieldManagerstill checks thechant/chant:<stack>family (restated locally rather than imported from@intentius/chant-k8s-client— a two-branch string comparison, not the kind of logic the "never duplicate" instruction is protecting), so a future gcp apply path that does route through server-side apply with an explicit chant manager is recognized with no change needed here. On today's plain-apply path it's provably inert (a dedicated test drives the same mutation throughkubectl-client-side-apply,cnrm-controller-manager, and an arbitrary third-party operator, and gets identical results) — the contested-field rule is what actually keeps GCP's drift semantics correct without it.Tests
lexicons/gcp/src/deep-observe.test.ts, same harnessdescribe-resources.test.tsuses (node:child_process'sexecmocked, no ambient kubectl config, no cluster contacted):gcpPlugin.observeResourcesDeepexists;deepNormalizationHooksis the shared static instance.gcpDeepNormalizationHooksunit tests: envelope pruning, the CNRM observed-state-vs-user-config annotation distinction, list-map ordering reused for an embedded k8s pod spec.observeResourcesDeepGcpunit tests: unsupported-kind, read-failure-as-hole,--ownedfiltering.kubectl edit-ed label → drift; CNRM-owned undeclared field and its observed-state annotation → pruned; classickubectl apply's ownlast-applied-configurationannotation → pruned by the reused ownership rule with no special case, proving that claim rather than asserting it) and a SQL instance (Config Connector's own controller currently holds a field chant declares differently → contested → still drift, sharpening "CNRM-owned doesn't surface as drift" to undeclared CNRM-owned specifically), plusunsupported-kindandread-failedentities, a baseline acceptance case, and a whole-lexicon-failure case routed through core's realobserveDeep.kubectl-client-side-apply,cnrm-controller-manager, an arbitrary third-party operator) and silence under the same three when undeclared, plus a check that an explicitchant:<stack>manager (were it ever used on this path) is still recognized as chant-owned rather than merely contested.packages/core/src/managed-fields.test.ts(new): direct unit tests for the relocatedK8S_OBJECT_ENVELOPE_PRUNE_PATTERNS,k8sListMapOrderKey,buildOwnershipSets(ported from the k8s lexicon's own suite, now exercised at its new home), andpruneByOwnership.Test plan
just build— core tsc cleannpm run build -w @intentius/chant-lexicon-gcp— cleannpm run build -w @intentius/chant-lexicon-k8s— clean (touched its hooks module)just lint— 0 errors (also rannpx eslintdirectly over every touched file in both lexicons and core — clean)just test— 800 passed | 1 skipped (801 files); 9776 passed | 5 skipped (9781 tests)just check-lexicons— 11/11 lexicons, 17/17 tier-1 checks each, no untracked failuresjust fold-differential— 104/104,drift: 0just sandbox-differential— 103/103,drift: 0examples/k8s-client-boundary.test.ts— 38/38; 117 modules reachable from the k8s lexicon's entry points, 0 importing the client package; 32 corpus builds, 0 loading it (unaffected by this PR, re-verified)node scripts/depcheck.mjs— no undeclared runtime dependenciesnode:child_process'sexec; nothing reads~/.kube/config/$KUBECONFIG, no socket opens.Deliberately not in scope
status.conditionsstaleness as its own signal, which the issue's own "Proposed" section floats as worth deciding rather than doing.statusis pruned outright here (matching k8s, and the acceptance criteria), and a CNRM projection lagging real GCP state is a genuine gap — but detecting it means reading the actual GCP API, not the CR, a different read than this contract's "normalize what Kubernetes reports" scope. Flagged in the module doc, not papered over.Part of #1014.