Skip to content

helm/v2-alpha: Incorrect indentation of webhook-certs volumeMount in Helm chart template #5677

@felix-kaestner

Description

@felix-kaestner

What broke? What's expected?

The webhook-certs volume mount in dist/chart/templates/manager/manager.yaml is indented at the wrong level, causing a YAML parse error when rendering the chart with helm template.

Reproducing this issue

  1. Run helm template ./dist/chart/ on a project scaffolded with the helm/v2-alpha plugin
  2. Ensure certManager.enable: true and manager.extraVolumeMounts is non-empty in values.yaml

This can be reproduced on the tesdata in testdata/project-v4-with-plugins. Simply apply the following diff and then run the helm template command.

diff --git a/testdata/project-v4-with-plugins/dist/chart/values.yaml b/testdata/project-v4-with-plugins/dist/chart/values.yaml
index dfc37f14f..8ac60d328 100644
--- a/testdata/project-v4-with-plugins/dist/chart/values.yaml
+++ b/testdata/project-v4-with-plugins/dist/chart/values.yaml
@@ -33,6 +33,16 @@ manager:
         fieldRef:
           fieldPath: metadata.namespace
 
+  extraVolumes:
+    - name: foo
+      configMap:
+        name: bar
+  extraVolumeMounts:
+    - name: foo
+      mountPath: /var/run/foo
+      subPath: baz
+      readOnly: true
+
   ## Env overrides (--set manager.envOverrides.VAR=value)
   ## Same name in env above: this value takes precedence.
   ##

Expected Behavior

The chart renders without errors.

Actual Behavior

Error: YAML parse error on <project>/templates/manager/manager.yaml:
error converting YAML to JSON: yaml: line 82: did not find expected key

Root Cause

In templates/manager/manager.yaml, the conditional block that adds the webhook-certs volume mount is indented at the same level as the volumeMounts: key rather than nested under it as a list item:

        volumeMounts:
          {{- if .Values.manager.extraVolumeMounts }}
          {{- toYaml .Values.manager.extraVolumeMounts | nindent 10 }}
          {{- end }}
        {{- if .Values.certManager.enable }}       # <-- wrong: 8-space indent
        - mountPath: /tmp/k8s-webhook-server/serving-certs
          name: webhook-certs
          readOnly: true
        {{- end }}

The {{- if }} block and its content should be indented to 10 spaces so the - mountPath entry is a valid item under volumeMounts::

        volumeMounts:
          {{- if .Values.manager.extraVolumeMounts }}
          {{- toYaml .Values.manager.extraVolumeMounts | nindent 10 }}
          {{- end }}
          {{- if .Values.certManager.enable }}     # <-- correct: 10-space indent
          - mountPath: /tmp/k8s-webhook-server/serving-certs
            name: webhook-certs
            readOnly: true
          {{- end }}

Affected Version

Introduced in 62e49e5 (feat(helm/v2-alpha): add extra volumes support).

KubeBuilder (CLI) Version

v4.14.0

PROJECT version

No response

Plugin versions

Other versions

No response

Extra Labels

/kind regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.kind/regressionCategorizes issue or PR as related to a regression from a prior release.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions