Skip to content

fix(k8s): a cross-resource reference resolves to metadata.name, not the declarable id - #1494

Merged
lex00 merged 1 commit into
mainfrom
fix/1493-k8s-attrref-resolves-to-metadata-name
Aug 5, 2026
Merged

lex00 merged 1 commit into
mainfrom
fix/1493-k8s-attrref-resolves-to-metadata-name

Conversation

@lex00

@lex00 lex00 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Closes #1493.

claimName: pgClaim.name emitted claimName: pgClaim. The manifest named a resource that does not exist, applied cleanly, and failed on the cluster.

The bug

attrRef: (name, attr) => {
  // For K8s, attribute references typically resolve to metadata.name
  if (attr === "name") return name;
  return name;
},

Both branches identical, and name is 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, no Fn::GetAtt — so whatever a reference means has to be resolved before serialization or it means nothing.

.name the target's metadata.name, falling back to the same kebab-case derivation the manifest builder uses when the target declares none
.namespace the declared namespace, or a refusal naming what to set
.uid refused — assigned by the API server at admission, so no build-time value exists
anything else refused, saying k8s can express neither

The .name fallback 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 now derivedName(), shared by both call sites, so they cannot drift.

Every refusal is an error carrying the fix, rather than a plausible-looking string:

Cannot reference "service.uid": a Kubernetes UID is assigned by the API server at
admission, so it has no build-time value. Reference .name, or carry the UID at
runtime with fieldRef: { fieldPath: "metadata.uid" }.

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:

YAML    byte-identical to the literal version
graph   {"from":"pgDeployment","to":"pgClaim","kind":"ref","viaAttr":"spec"}

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 check green: 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.ts has two Argo/Flux GVK tests that fail under a bare npx vitest without codegen — they pass under just test, and they fail identically on clean main. Not touched by this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_012n8PKN49z8c6jZVA9QYwvk

…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
@lex00
lex00 merged commit a77d1c1 into main Aug 5, 2026
5 checks passed
@lex00
lex00 deleted the fix/1493-k8s-attrref-resolves-to-metadata-name branch August 5, 2026 06:27
@lex00 lex00 mentioned this pull request Nov 20, 2026
78 of 84 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

k8s: a cross-resource AttrRef serializes to the declarable id, so referencing another resource emits a manifest that names something that does not exist

1 participant