bjw-s / helm-charts

A collection of Helm charts
https://bjw-s.github.io/helm-charts/
Apache License 2.0
535 stars 100 forks source link

Usage of persistence.advancedMounts when there are initContainers causes errors (common v2.0.0) #192

Closed jthvai closed 9 months ago

jthvai commented 9 months ago

Details

What steps did you take and what happened:

When both persistence.advancedMounts and controllers.*.initContainers are specified in values.yaml, installing or upgrading the chart (app-template) will fail with "error calling dig: interface conversion: interface {} is nil, not string".

Failed example `helm upgrade -i release-name bjw-s/app-template --version 2.0.0 -f values.yaml` ```yaml controllers: main: containers: main: image: repository: ghcr.io/mendhak/http-https-echo tag: 30 initContainers: a-container: image: repository: ghcr.io/mendhak/http-https-echo tag: 30 service: main: enabled: false persistence: config: enabled: true advancedMounts: main: main: - path: /data/config.yaml readOnly: false subPath: config.yaml ```
Successful example (same as above, with initContainers commented) `helm upgrade -i release-name bjw-s/app-template --version 2.0.0 -f values.yaml` ```yaml controllers: main: containers: main: image: repository: ghcr.io/mendhak/http-https-echo tag: 30 # initContainers: a-container: image: repository: ghcr.io/mendhak/http-https-echo tag: 30 service: main: enabled: false persistence: config: enabled: true advancedMounts: main: main: - path: /data/config.yaml readOnly: false subPath: config.yaml ```
Error output ``` Error: UPGRADE FAILED: template: app-template/templates/common.yaml:14:3: executing "app-template/templates/common.yaml" at : error calling include: template: app-template/charts/common/templates/loader/_generate.tpl:8:6: executing "bjw-s.common.loader.generate" at : error calling include: template: app-template/charts/common/templates/render/_controllers.tpl:25:12: executing "bjw-s.common.render.controllers" at : error calling include: template: app-template/charts/common/templates/classes/_deployment.tpl:59:13: executing "bjw-s.common.class.deployment" at : error calling include: template: app-template/charts/common/templates/lib/pod/_spec.tpl:58:12: executing "bjw-s.common.lib.pod.spec" at : error calling include: template: app-template/charts/common/templates/lib/pod/fields/_initContainers.tpl:28:32: executing "bjw-s.common.lib.pod.field.initContainers" at : error calling include: template: app-template/charts/common/templates/lib/container/_spec.tpl:48:12: executing "bjw-s.common.lib.container.spec" at : error calling include: template: app-template/charts/common/templates/lib/container/fields/_volumeMounts.tpl:38:33: executing "bjw-s.common.lib.container.field.volumeMounts" at : error calling dig: interface conversion: interface {} is nil, not string ```

(Examples are a reduced version of advanced-values.yaml)

What did you expect to happen:

The chart should install successfully, with the volumeMounts rendered as expected for both main and init containers (or ignored completely, if advancedMounts was not designed to include init containers).

Anything else you would like to add:

Additional Information:

I noticed that controllers.*.initContainers.*.volumeMounts is no longer applied (as in v1.5.1), and that persistence.globalMounts applies to init containers. Does this imply that persistence.advancedMounts was intended to also apply to init containers?

bjw-s commented 9 months ago

Thanks for reporting this issue! You are correct that persistence.advancedMounts was meant to apply to initContainers as well. Unfortunately I forgot to pass through an object to the function, which makes it fail with the error you are seeing.

I have the fix working locally, but also need to fix volumeClaimTemplates (which has a related bug) before I can release the fix