Repository navigation
fix(cozy-lib): make the cozyconfig helpers survive uninjected values - #3647
Merged
Merged
Conversation
`_cluster` and `_namespace` reach a chart through valuesFrom on the
cozystack-values Secret, so they are absent whenever a chart is rendered
on its own: `helm lint`, a plain `helm template`, and any helm-unittest
suite that does not set them. Twelve of the helpers in _cozyconfig.tpl
read straight through the missing map and abort the render rather than
returning their documented empty default.
Two spellings, one cause. `index .Values._cluster "root-host"` raises
`index of untyped nil`, and `.Values._namespace.host` raises
`nil pointer evaluating interface {}.host`. In both cases the trailing
`| default ""` never runs: it applies to the result, and there is no
result, only an error. That default covered a key missing from a map
that exists, never a missing map.
Guard the map instead, which is what `cozy-lib.images-registry` in this
same file already did:
(index (.Values._cluster | default dict) "root-host") | default ""
`index` on an empty map returns nil harmlessly, so the trailing default
applies as it always read. With the map present, `| default dict`
returns it untouched.
This changes no rendered output. Every one of the 34 charts that symlink
cozy-lib was rendered before and after, both with the injected values
populated and with them set to empty maps, and every result is
byte-identical. Eight charts differ between any two runs because they
generate passwords; rendering the unchanged tree twice reproduces
exactly those eight, which is how they are excluded.
What this does not do is fix a chart that fails today. The charts that
cannot render standalone read the injected values directly in their own
templates rather than through these helpers, so they are unaffected by a
change to the library and are being addressed where they live.
Twelve of the thirteen helpers here have no callers anywhere in
packages/ at present; only `cozy-lib.images-registry` is reached, from
`cozy-lib.image`, and it was already guarded. The guard is still worth
having on the rest: they are the library's public surface, they are what
a chart author copies when reaching for cluster configuration, and the
broken spelling propagates by being read. `cozy-lib.image` is called
from four templates, so these helpers do get adopted once they exist.
Add a suite in cozy-lib-tests, which is where library behaviour is
pinned because a library chart renders nothing of its own. One case
covers the uninjected state, which needs no mocking since neither key is
in values.yaml, and one covers the injected state so the guard cannot
quietly change what a populated map returns. The injected case includes
`scheduling` and `branding` specifically: those two are the helpers
whose body was restructured rather than wrapped, so they are the ones
whose present-map behaviour most needs pinning. Against the unguarded
helpers the first case fails with `index of untyped nil`.
Assisted-By: Claude <[email protected]>
Signed-off-by: Aleksei Sviridkin <[email protected]>
Aleksei Sviridkin (lexfrei)
requested review from
IvanHunters,
myasnikovdaniil and
Kirill Ilin (sircthulhu)
as code owners
August 8, 2026 01:06
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughCozy configuration helpers now handle missing ChangesCozy configuration hardening
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
What this PR does
_clusterand_namespacereach a chart through valuesFrom on the cozystack-values Secret, so they are absent whenever a chart is rendered on its own:helm lint, a plainhelm template, and any helm-unittest suite that does not set them. Twelve of the helpers in_cozyconfig.tplread straight through the missing map and abort the render instead of returning the empty default they document.Two spellings, one cause.
index .Values._cluster "root-host"raisesindex of untyped nil;.Values._namespace.hostraisesnil pointer evaluating interface {}.host. In both, the trailing| default ""never runs, because it applies to the result and there is no result, only an error. That default covered a key missing from a map that exists, never a missing map.The guard goes on the map, which is what
cozy-lib.images-registryin this same file already did:indexon an empty map returns nil harmlessly, so the trailing default applies as it always read, and with the map present| default dictreturns it untouched.This fixes no chart that is failing today. The charts that cannot render standalone read the injected values directly in their own templates rather than through these helpers, so a change to the library does not reach them; they are handled where they live. Worth being blunt about the same point from the other side: twelve of the thirteen helpers here currently have no callers anywhere in
packages/. Onlycozy-lib.images-registryis reached, fromcozy-lib.image, and it was already guarded. The guard is still worth having on the rest, because they are the library's public surface, they are what a chart author copies when reaching for cluster configuration, and a broken spelling propagates by being read.cozy-lib.imageis called from four templates, so these helpers do get adopted once they exist.Rendered output does not change, and that is measured rather than argued. All 34 charts that symlink cozy-lib were rendered before and after, both with the injected values populated and with them set to empty maps, and every result is byte-identical. That check needs a control: the first comparison showed eight charts differing, which looks like a regression in a library change. Rendering the unchanged tree twice reproduces exactly those eight, because they generate passwords. Subtracting the control leaves zero real differences.
The suite lives in
cozy-lib-tests, which is where library behaviour is pinned, since a library chart renders nothing of its own. One case covers the uninjected state, which needs no mocking because neither key appears in any values file, and one covers the injected state so the guard cannot quietly change what a populated map returns. The injected case pinsschedulingandbrandingas whole YAML documents rather than by substring: those two had their bodies restructured rather than wrapped, and a substring assertion survives the loss of thetoYamlthat produces the document, because the key name also appears in Go's default map formatting. Against the unguarded helpers the first case fails withindex of untyped nil.Three things left deliberately undone, so they are not mistaken for oversights. The header comments in
_cozyconfig.tplsay where these values come from but not what the helpers now do when they are absent, which is the contract this change creates and would be better stated next to the helpers than only in the suite.Chart.yamlin cozy-lib-tests still carriesname: quotafrom when that chart covered one helper family, so the runner prints### Chart [ quota ]for a suite that now covers three. And the mixed state, one map injected and the other not, has no case of its own; the two guards are independent so composition covers it, and a third case would pin nothing new.Relates to #3646.
Screenshots
Downstream repositories
Release note
Summary by CodeRabbit
Bug Fixes
Tests