Skip to content

[Backport release-1.6] fix(cozy-lib): make the cozyconfig helpers survive uninjected values - #5141

Merged
myasnikovdaniil merged 1 commit into
release-1.6from
backport/3647-release-1.6
Oct 30, 2026
Merged

myasnikovdaniil merged 1 commit into
release-1.6from
backport/3647-release-1.6

Conversation

@myasnikovdaniil

Copy link
Copy Markdown
Contributor

What this PR does

Backport of #3647 to release-1.6.

Since #5080 (backport of #4710) tenant.ciliumPolicies calls cozy-lib.bundle-name, and on release-1.6 that helper still does index .Values._cluster "bundle-name", which fails with index of untyped nil when _cluster is not set. Tenant export-proxy suite (tests/networkpolicy_vm_exportproxy_test.yaml) sets no _cluster, so all four cases fail and unit tests are red on every PR against release-1.6, including batch #5089. #5080 set _cluster: {} only in its own suite, that's why it passed there.

#3647 guards the map in every cozyconfig helper and adds cozy-lib-tests suite for injected and uninjected state. It applies cleanly, diff is identical to main.

Checked locally (helm-unittest is not installed here, CI runs it):

  • export-proxy suite renders fail on current branch and pass with this change;
  • new cozyconfig suite passes, its uninjected case fails against old helpers;
  • all 34 charts using cozy-lib render the same before and after with realistic _cluster / _namespace (apart from generated passwords), only tenant chart with nothing injected changes, it doesn't fail in networkpolicy.yaml anymore.

Plain helm template of tenant chart without _cluster still fails in keycloakgroups.yaml, main fixed it separately in #3636. Unit tests are not affected, suite renders only templates it names.

Screenshots

Not a UI change.

Downstream repositories

Release note

fix(cozy-lib): the cozyconfig helpers now return their documented empty defaults when the platform has not injected `_cluster` / `_namespace`, instead of aborting the render, so a chart using them can be rendered and unit-tested on its own

`_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`.

(cherry picked from commit 93ffb38)

On release-1.6 one of these helpers does have a caller that fails
today, so the two paragraphs above about callers do not hold here:
tenant.ciliumPolicies calls cozy-lib.bundle-name since the isp-hosted
Cilium guard was backported in 2f820f7. Every tenant suite that
renders templates/networkpolicy.yaml without setting _cluster aborts
with `index of untyped nil` in the helper, which is how the
vm-exportproxy suite has failed on this branch since then. With the map
guarded, bundle-name returns "" there and the policies render as on
every non-isp-hosted bundle. The patch applies unchanged.

Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size/L This PR changes 100-499 lines, ignoring generated files area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) kind/bug Categorizes issue or PR as related to a bug labels Oct 27, 2026
@myasnikovdaniil
myasnikovdaniil merged commit d7c280c into release-1.6 Oct 30, 2026
43 checks passed
@myasnikovdaniil
myasnikovdaniil deleted the backport/3647-release-1.6 branch October 30, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) kind/bug Categorizes issue or PR as related to a bug size/L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant