Skip to content

test: cover every template and helper; fix nested overlays after adopt - #12

Merged
mkmik merged 1 commit into
mainfrom
test-coverage
Oct 20, 2026
Merged

mkmik merged 1 commit into
mainfrom
test-coverage

Conversation

@mkmik

@mkmik mkmik commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Adds tests for everything k8s.libsonnet does, and fixes a bug in adopt that the new tests found.

Tests (tests/k8s_test.jsonnet)

  • Every template (31): right apiVersion and kind, typeFor finds it, and only namespaced kinds get the shared namespace.
  • typeFor falls back to the plain Object for unknown kinds and groups.
  • Deployment, StatefulSet, DaemonSet and Job get the PodTemplateSpec overlays. ObjectTemplateMeta labels land on both the object and its pods.
  • Named arrays: containers_, initContainers_, volumes_, env_, ports_, volumeMounts_, Service ports_.
  • default-container: set for one main container plus sidecars; not set for two main containers or none.
  • Arrays keyed by something other than name: volumeClaimTemplates_, endpoints_, podMetricsEndpoints_, selector_.matchExpressions_, VaultSecret secrets_.
  • RBAC refs and defaults; the generic helpers (applyOverlayEach, deriveEach, asKeyedArray, asNamedArray, orray); mounted components getting the parent's k8s, envConf and conf; RootComponent.
  • adopt: nested overlays, new containers after adopt, unknown kinds unchanged.

Bug fix (adoptNamedArray)

After adopt, an overlay on an array inside an array item was ignored:

k8s.adopt(objs)[0] { spec+: { containers_+: { c+: { env_+: { A+: { value: 'b' } } } } } }
// env A still had its upstream value

Each item was adopted again when the output was built, and its upstream env array won over the overlay. Items are now adopted once, when adopt runs, so later overlays apply on top. New containers added after adopt still get the Container template. examples/adopt.golden is unchanged.

just test passes.

🤖 Generated with Claude Code

Add regression asserts for every template (apiVersion, kind, typeFor,
namespace scope), the pod template overlays on all workloads, named and
keyed arrays, default-container, RBAC refs, generic helpers, components
and adopt.

The new adopt test found a bug: after adopt, overlays on an array inside
an array item (e.g. containers_.c.env_) were ignored, because each item
was adopted again when rendering and its upstream array won. Items are
now adopted once, up front, so later overlays apply on top.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mkmik
mkmik merged commit 276d866 into main Oct 20, 2026
1 check passed
@mkmik
mkmik deleted the test-coverage branch October 20, 2026 10:53
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.

1 participant