fix: make RBAC and supporting templates nil-safe for optional provider and hub blocks - #1906
fix: make RBAC and supporting templates nil-safe for optional provider and hub blocks#1906victorlane wants to merge 10 commits into
Conversation
`concat` panics on nil arguments, so the previous `((.x).y)` form crashed when a user-supplied values file omitted or nulled a provider block. Defaulting to an empty list keeps the "empty = watch all" semantics intact and renders cleanly when providers.kubernetesIngress, providers.kubernetesCRD, providers.kubernetesGateway, providers.knative, or hub.namespaces are absent.
Wrap provider field reads in `(map).field` so the requirements preflight does not panic when a values file omits or nulls providers.kubernetesGateway, providers.kubernetesIngress, providers.kubernetesCRD, or providers.kubernetesIngressNGINX.
Wrap the kubernetesGateway lookup so NOTES.txt does not panic when the kubernetesGateway block is absent from values.
ClusterRole rules and the shared image/version helpers crashed when providers.kubernetesIngress, providers.kubernetesCRD, or the hub block were absent. Wrap parent maps in `(map).field` so reads short-circuit to nil instead of dereferencing nil.
…lates The hub block is optional but several templates (clusterrole.yaml, role.yaml, requirements.yaml, hub-license.yaml, hub-apiportal.yaml, hub-admission-controller.yaml) dereferenced .Values.hub.* directly, panicking when a user supplied values that omitted or nulled the whole hub block. Wrap the entry-point hub reads in `(.Values.hub).field` so they short-circuit to nil and the gated blocks render as no-ops.
…ates The shared pod template, deployment, daemonset, and file-provider ConfigMap each crashed when providers.file, providers.kubernetesIngress, providers.kubernetesCRD, or the hub block were nulled. Wrap each top-of-block guard so the gated regions render as no-ops instead of dereferencing nil.
…ranches NOTES.txt label-selector and hub warnings, plus the per-provider rule branches in Role, dereferenced provider/hub fields without guarding the parent map. Apply the same `(map).field` pattern so omitted blocks render cleanly.
Extend the existing nil-namespaces test with a case where the kubernetesGateway, knative, file, and kubernetesIngressNGINX provider blocks are absent entirely, locking in the nil-safe template behavior.
ff3cc28 to
4092a56
Compare
|
Hello @victorlane 👋, Thanks for this contribution 🏅 Thanks :-) |
Hi Remi, Below is a minimal values yaml that reproduces the issues. It only happens when an optional block is explicitly nulled rather than left out fully. rbac:
namespaced: true
providers:
kubernetesIngress:
enabled: true
kubernetesCRD:
enabled: true
kubernetesGateway:
enabled: false
knative: ~
kubernetesIngressNGINX: ~ |
|
@darkweaver87 had time to look after this yet? We are experiencing issues with this bug in (prod) installations. |
|
Hi @victorlane, and sorry for the late follow-up — I know you're hitting this in prod, thanks for your patience and for the minimal reproducer, it's very helpful. 🙏 Looking at it, everything in your values comes down to these two lines: knative: ~
kubernetesIngressNGINX: ~As you noted yourself, the panic only happens when an optional block is explicitly nulled rather than left out. Both of these providers are opt-in and already On the PR itself, my hesitation is that guarding parents path-by-path makes the chart only look nil-safe while leaving gaps:
So there's a design question underneath: do we want to officially support "nulling any optional block"? If yes, I'd rather we do it once and consistently (e.g. normalizing optional blocks in a helper, or leaning on schema defaults) than scatter parentheses that every future template author has to remember. If not, dropping the explicit The Let me know your thoughts, and thanks again for pushing on this! 🙌 |
What does this PR do?
Several templates dereference
.Values.providers.*and.Values.hub.*without guarding the parent map, so rendering panics withnil pointer evaluating interface {}.Xwhenever a user-supplied values file omits or nulls an optional block. The pre-existing((.x).y)"nil-safe" form inrolebinding.yamlwas also broken in a different way: it returnednil(notlist) andconcatpanicked on the nil argument.Motivation
Running into this issue while trying to deploy the helm chart
More
make testand all the tests passed