fluxcd / helm-operator

Successor: https://github.com/fluxcd/helm-controller — The Flux Helm Operator, once upon a time a solution for declarative Helming.

Home Page:https://docs.fluxcd.io/projects/helm-operator/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regression: disable line wrapping for helm templating

knack-roque opened this issue · comments

Describe the bug

In helm-operator 1.4.2 we are encountering a problem with templating wrapping a line in the a variable reference causing an "unclosed action" as the }} to close the reference are now on a different line. Deploying the same chart with the same values using helm-operator 1.3.0 does not encounter this issue.

I understand helm-operator is no longer supported but I'm putting this here in case anyone else runs into the issue since it was irritating me for a while.

To Reproduce

This should fail for more than just our case but how we're getting into it is that we're deploy the kube-prometheus-stack chart as part of an umbrella chart and inside the values of the umbrella chart we're passing something that will need to be further templated.

values.yaml:

kube-prometheus-stack:
  grafana:
    extraInitContainers:
      - name: wait-for-db
        image: "{{ .Values.global.imageRegistry }}/{{ .Values.global.postgresql.repository }}:{{ .Values.global.postgresql.tag }}"
        imagePullPolicy: "{{ .Values.global.postgresql.pullPolicy }}"
        command:
        - bash
        - ...

grafana's _pod.yaml bundled with prometheus:

...
{{- if .Values.extraInitContainers }}
{{ tpl (toYaml .Values.extraInitContainers | indent 2) $ }}
{{- end }}
...

See the logs section below for the full error message but the important bit is image: '{{ .Values.global.imageRegistry }}/{{ .Values.global.postgresql.repository\n }}:{{ .Values.global.postgresql.tag }}'\n where there is an incorrect \n being added into the middle variable reference.

Expected behavior

No error to occur and the chart to be installed successfully.

Logs

[root@int-k8s01 ~]$ k -n stack-control describe hr monitoring

Events:
  Type     Reason             Age                 From           Message
  ----     ------             ----                ----           -------
  Warning  FailedReleaseSync  71s (x11 over 30m)  helm-operator  synchronization of release 'monitoring' in namespace 'monitoring' failed: installation failed: template: monitoring/charts/kube-prometheus-stack/charts/grafana/templates/deployment.yaml:49:10: executing "monitoring/charts/kube-prometheus-stack/charts/grafana/templates/deployment.yaml" at <include "grafana.pod" .>: error calling include: template: monitoring/charts/kube-prometheus-stack/charts/grafana/templates/_pod.tpl:155:3: executing "grafana.pod" at <tpl (toYaml .Values.extraInitContainers | indent 2) $>: error calling tpl: error during tpl function execution for "  - command:\n    - bash\n    - -c\n    - |\n      echo \"Waiting for database connection ...\"\n      until pg_isready \\\n        --host {{ include \"grafana.postgresql.fullname\" . }} \\\n        --port {{ include \"grafana.postgresql.port\" . }} \\\n        --username {{ include \"grafana.postgresql.username\" . }} \\\n        --dbname {{ include \"grafana.postgresql.database\" . }} \\\n        --timeout 5; do\n          echo \"Connection failed, trying again in 2 seconds\";\n          sleep 2;\n      done;\n      echo \"Connection succeeded\"\n  \n      echo \"Waiting for user connection to database ...\"\n      until psql \\\n        --host {{ include \"grafana.postgresql.fullname\" . }} \\\n        --port {{ include \"grafana.postgresql.port\" . }} \\\n        --username {{ include \"grafana.postgresql.username\" . }} \\\n        --dbname {{ include \"grafana.postgresql.database\" . }} \\\n        --command='SELECT 1;'; do\n        echo \"User connection failed, trying again in 2 seconds\";\n        sleep 2;\n      done;\n      echo \"User connected\"\n    env:\n    - name: PGSSLMODE\n      value: require\n    - name: PGPASSWORD\n      valueFrom:\n        secretKeyRef:\n          key: password\n          name: grafana.acid-grafana.credentials\n    image: '{{ .Values.global.imageRegistry }}/{{ .Values.global.postgresql.repository\n      }}:{{ .Values.global.postgresql.tag }}'\n    imagePullPolicy: '{{ .Values.global.postgresql.pullPolicy }}'\n    name: wait-for-db\n    resources:\n      limits:\n        cpu: 250m\n        memory: 256Mi\n      requests:\n        cpu: 100m\n        memory: 128Mi\n    securityContext:\n      allowPrivilegeEscalation: false\n      privileged: false": parse error at (monitoring/charts/kube-prometheus-stack/charts/grafana/templates/deployment.yaml:36): unclosed action

Additional context

  • Helm Operator version: 1.4.2
  • Kubernetes version: 1.20.10
  • Git provider: N/A
  • Helm repository provider: N/A

Workaround
I changed go.mod by adding the following to force to the version of go-yaml used in helm-operator v1.3.0 and then rebuilt helm-operator v1.4.2

// Pin go-yaml to 2.3.0 to support infinite line size
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.3.0

There should be some way to set disableLineWrapping = true but I'm not strong enough on go to know where to put that.

Upstream link to why this worked previously and no longer is go-yaml/yaml#670 where they swapped the default back to no longer handle line wrapping.

Thank you for the detailed report!

I did not see whether it was resolved by subsequent updates, I never ran into this in my own testing unfortunately. We've just put out one more release of Helm Operator with go-yaml at the latest v2, hopefully that fixed it.

Please let us know if there's anything we can do to help you migrate past Helm Operator, the Flux v2 is in active development and continues to pass new feature milestones on the way to GA. I'm going to go ahead and close this, as the specific version pins we have chosen are now carefully tuned for compatibility balanced with security and to mitigate CVEs, if you have any further suggestion welcome to reopen or open again – please accept our thanks for participating in Flux 🎉