Repository navigation
fix(k8s): a cross-resource reference resolves to metadata.name, not the declarable id - #1494
Merged
Merged
Conversation
…he declarable id
`claimName: pgClaim.name` emitted `claimName: pgClaim`. The manifest named a
resource that does not exist, applied cleanly, and failed on the cluster --
which is the failure this system exists to remove.
The visitor returned the logical name for every attribute, and both of its
branches were identical:
attrRef: (name, attr) => {
// For K8s, attribute references typically resolve to metadata.name
if (attr === "name") return name;
return name;
},
The lexicon's own plugin comment already said what this should do -- "Cross-
resource references are handled by the AttrRef system in the serializer
(resolves to metadata.name)" -- so this brings the code to the documentation
rather than the other way round.
Kubernetes YAML has no deploy-time reference mechanism. There is no !Ref and no
Fn::GetAtt, so whatever a reference means has to be resolved before
serialization or it means nothing at all.
.name the target's metadata.name, falling back to the SAME kebab-case
derivation the manifest builder uses when the target declares
none. Extracted to derivedName() so a reference and the thing it
references cannot drift apart.
.namespace the declared namespace, or a refusal naming what to set. Which
namespace a manifest lands in is otherwise decided at apply time.
.uid refused. A UID is assigned by the API server at admission, so no
build-time value exists and any string emitted here would be a
fabrication.
anything refused, saying k8s can express neither.
Every refusal is an error with the fix in it, rather than a plausible string.
Verified end to end against INTENTIUS/fountain-ops, which had every
cross-resource reference written as a repeated literal precisely because this
did not work. Swapping one literal for a reference:
YAML byte-identical to the literal version
graph {"from":"pgDeployment","to":"pgClaim","kind":"ref","viaAttr":"spec"}
That pairing is the whole point: the manifest is unchanged and the graph gains
the relationship, so a project can express what references what without
touching what it deploys. A k8s estate currently renders as one flat row of
unrelated nodes for this reason (fountain-ops#84, behold#131).
10668 tests pass; 6 new cover both resolutions and all three refusals.
Closes #1493
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012n8PKN49z8c6jZVA9QYwvk
78 of 84 tasks
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 #1493.
claimName: pgClaim.nameemittedclaimName: pgClaim. The manifest named a resource that does not exist, applied cleanly, and failed on the cluster.The bug
Both branches identical, and
nameis the logical name. The lexicon's own plugin comment already said what it should do — "Cross-resource references are handled by the AttrRef system in the serializer (resolves to metadata.name)" — so this brings the code to the documentation rather than the other way round.What resolves, and what is refused
Kubernetes YAML has no deploy-time reference mechanism — no
!Ref, noFn::GetAtt— so whatever a reference means has to be resolved before serialization or it means nothing..namemetadata.name, falling back to the same kebab-case derivation the manifest builder uses when the target declares none.namespace.uidThe
.namefallback matters: a resource that declares no name already gets one derived from its logical name, and a reference to it has to derive the same one. That derivation is nowderivedName(), shared by both call sites, so they cannot drift.Every refusal is an error carrying the fix, rather than a plausible-looking string:
Verified end to end
Against fountain-ops, which writes every cross-resource reference as a repeated literal precisely because this did not work. Swapping one literal for a reference:
That pairing is the point: the manifest is unchanged and the graph gains the relationship. A project can express what references what without altering what it deploys. Today a k8s estate renders as one flat row of unrelated nodes for exactly this reason (fountain-ops#84, behold#131).
Tests
just checkgreen: build, lint,check-lexicons(21/21 tier-1 on every lexicon), and 10668 tests passing. 6 new cover both resolutions and all three refusals.Note for reviewers:
lexicons/k8s/src/serializer.test.tshas two Argo/Flux GVK tests that fail under a barenpx vitestwithout codegen — they pass underjust test, and they fail identically on cleanmain. Not touched by this change.🤖 Generated with Claude Code
https://claude.ai/code/session_012n8PKN49z8c6jZVA9QYwvk