helm-charts icon indicating copy to clipboard operation
helm-charts copied to clipboard

Grafana helm chart fails to install when defining env

Open daynebenn opened this issue 3 years ago • 4 comments

There appears to be some default environment variables configured that get destroyed when declaring an environment variable under env: {}.

As per the docs at https://grafana.com/docs/grafana/latest/alerting/high-availability/enable-alerting-ha/#update-kubernetes-container-definition it recommends to use the pod's IP address passed as an environment variable. When doing this I get the following error: Error: template: grafana/templates/secret.yaml:1:62: executing "grafana/templates/secret.yaml" at <.Values.env.GF_SECURITY_ADMIN_PASSWORD__FILE>: can't evaluate field GF_SECURITY_ADMIN_PASSWORD__FILE in type interface {}

If I do not change the values from env: {} it installs fine.

For now I am trying to see if the deployment will work properly for ha alerting without passing the pod IP (using the default value of 0.0.0.0)

daynebenn avatar Sep 29 '22 18:09 daynebenn

Same issue on any addition of env variables, chart is unusable in this state

jlcrow avatar Oct 26 '22 18:10 jlcrow

If you want env from fieldRef then you should use envValueFrom instead of env. Like values.yaml

envValueFrom:
  POD_IP:
    fieldRef:
      fieldPath: status.podIP

will be rendered as

- name: "POD_IP"
   valueFrom:
     fieldRef:
       fieldPath: status.podIP

tr3mor avatar Oct 28 '22 12:10 tr3mor

So after much pain I finally noticed that env: {} (Note the {}) is a MAPPING, not an array.

So if trying to do:

env:
- name: FOO
  value: bar

you will run into this error. The chart templates the mapping instead of just including it, violating convention of most other charts (not just including the array like most that use env: [].

But seems like have to do:

env:
  FOO: bar

The values.yaml really could use a shorter comment calling this out - I do not seem to be the only one who lost time to this.

MaxCWhitehead avatar Jan 16 '25 22:01 MaxCWhitehead

@MaxCWhitehead I was trying to do this

grafana:
  env:
    FOO: bar

but after doing helm template . got this

  - name: "FOO"
    value: "bar"

it looks like every env variable name will be a string

https://github.com/grafana/helm-charts/blob/72a7caf12f61cd5e7d82acbe586fb1e9c0bce2f6/charts/grafana/templates/_pod.tpl#L1200

any suggestions

AshishVerma7690 avatar May 30 '25 08:05 AshishVerma7690