Repository navigation
fix: make adopt a plain overlay so every layer survives - #13
Merged
Merged
Conversation
adopt used to build a finished copy of `type + upstream` and stack it on the object. A copy holds plain values, not merges, so it overwrote type-level overlays (env_ entries, per-item settings), froze fields that read `self`, and checked type asserts against the upstream item. adopt(o) is now `typeFor(o) + adoptOverlay(o)`. The overlay merges the upstream values in and reads the type only through `super` at render time. typedNamedArrays records item types in a hidden `_namedArrays+::`, so extending a type adds named arrays instead of replacing them. Also: - upstream items keep their upstream order; overlay-added items follow - nested objects in items merge with type defaults - unnamed, null-named and repeated-name items stay in place and no longer block overlays on the rest of the array - null arrays (Helm's empty `env:`) are treated as [] - default-container annotation follows containers added after adopt The adopt example golden changes: the sidecar now gets COMMON_ENV and the pod has no default-container annotation (two main containers). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
k8s.adoptbuilt a finished copy oftype + upstream itemand stacked it on the object. A copy holds plain values, not merges, so:PodSpec+: { containers_+: { app+: { env_+: ... } } }lost its env entries, andContainer+:defaults beat per-item settings)self(e.g. a pull policy derived fromself.image) were computed from the upstream values and never updated#12 fixed overlays applied after adopt by making that copy earlier, which moved the loss to overlays applied before adopt. This PR removes the copy instead.
Change
adopt(o)is nowtypeFor(o) + adoptOverlay(o). The overlay merges upstream values in and reads the type only throughsuper, at render time.typedNamedArraysrecords item types in a hidden_namedArrays+::, so extending a type adds named arrays instead of replacing the built-in ones.deepMapObject,adoptObject,adopterFromPartialType,adoptNamedArray.Also fixed by the same code:
$(VAR)in env); overlay-added items followsecurityContext,resources) merge with type defaultsenv:) are treated as[]instead of crashingkubectl.kubernetes.io/default-containerfollows containers added after adoptexamples/adopt.goldenchanges: thesidecontainer now getsCOMMON_ENV, and the pod has no default-container annotation (it has two main containers).Not changed
An upstream item with the same name as a type-level default item is still merged onto it, not replaced. Replacing would break type-level overlays on adopted items.
Testing
just testpasses. New adopt cases intests/k8s_test.jsonnetfail on the old code.🤖 Generated with Claude Code