Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

[stable/grafana] Unable to set Grafana Env Var #22903

Closed
andrew-pickin-epi opened this issue Jun 22, 2020 · 12 comments
Closed

[stable/grafana] Unable to set Grafana Env Var #22903

andrew-pickin-epi opened this issue Jun 22, 2020 · 12 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@andrew-pickin-epi
Copy link

Attempting to create an entry fro a Grafana environment variable causes an error:

    grafana:
      enabled: true
      env:
        - name: GF_FOO
          value: bar

Results in:

ts=2020-06-22T17:28:02.984996473Z caller=release.go:292 component=release release=prometheus-operator targetNamespace=monitoring resource=monitoring:helmrelease/prometheus-operator helmVersion=v3 error="upgrade failed: template: prometheus-operator/charts/grafana/templates/secret.yaml:1:58: executing \"prometheus-operator/charts/grafana/templates/secret.yaml\" at <.Values.env.GF_SECURITY_ADMIN_PASSWORD__FILE>: can't evaluate field GF_SECURITY_ADMIN_PASSWORD__FILE in type interface {}" action=upgrade

The same is true fro setting by SecretKeyRef, including setting the GF_SECURITY_ADMIN_PASSWORD__FILE variable itself.

@tahsinrahman
Copy link

tahsinrahman commented Jul 2, 2020

i'm also facing the same issue

$ helm upgrade --install -n monitoring prometheus-operator stable/prometheus-operator --version 8.15.6 --set grafana.env[0].name=KEY --set grafana.env[0].value=VALUE 
coalesce.go:196: warning: cannot overwrite table with non table for env (map[])
Error: UPGRADE FAILED: template: prometheus-operator/charts/grafana/templates/secret.yaml:1:58: executing "prometheus-operator/charts/grafana/templates/secret.yaml" at <.Values.env.GF_SECURITY_ADMIN_PASSWORD__FILE>: can't evaluate field GF_SECURITY_ADMIN_PASSWORD__FILE in type interface {}

@aramhakobyan
Copy link

+1

@tahsinrahman
Copy link

i found the solution, actually env expects an object, not an array, so you need to do --set grafana.env.key1=value1 --set grafana.env.key2=value2 or,

grafana:
  enabled: true
  env:
    key1: value1
    key2: value2

@gldraphael
Copy link

FWIW this also happens in the stable/grafana chart. Here's my values:

grafana.ini:
  database:
    type: mysql
    name: grafana
    ssl_mode: skip-verify
    host: mysql-host-goes-here
    user: mysql-user-goes-here
    password: ${GF_DATABASE_PASSWORD} # This *shouldn't* be required, but adding it doesn't help either
    # password: the-secret-password   # This works, but we don't want to hard code secrets!
    ca_cert_path: "/etc/ssl/certs/ca-certificates.crt"
env:
  - name: GF_DATABASE_PASSWORD
    valueFrom:
      secretKeyRef:
        name: grafana-db
        key: secret

Grafana should ideally read the GF_DATABASE_PASSWORD environment variable if it exists. The OP is trying to do the same by setting GF_FOO. In my case, we have a setup that automatically pulls secret-env variables from a vault and that setup doesn't work with grafana since the chart expects me to hardcode the secret.

@stale
Copy link

stale bot commented Aug 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.

@stale stale bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 9, 2020
@gldraphael
Copy link

Hey @andrew-pickin-epi could you add [stable/grafana] to the title?

@stale stale bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 9, 2020
@NikolaeVarius
Copy link

experiencing the same issue

@scottrigby scottrigby changed the title Unable to set Grafana Env Var [stable/grafana] Unable to set Grafana Env Var Aug 13, 2020
@scottrigby
Copy link
Member

#22903 (comment) is correct. env is expected to be a map:

env:
{{- range $key, $value := .Values.downloadDashboards.env }}
- name: "{{ $key }}"
value: "{{ $value }}"
{{- end }}
The pod template creates the array from the values map. IMO this is actually a good pattern for charts, because it allows an environment variable to be deleted or overwritten by key as opposed to array index which is more error prone.

Can someone experiencing this issue please verify that this works?

@scottrigby
Copy link
Member

scottrigby commented Aug 13, 2020

This is correct. 30 second test steps:

$ kind create cluster
Creating cluster "kind" ...
$ helm install issue-22903 stable/grafana --set env.FOO=bar,env.BAZ=qux
$ kubectl describe deployments.apps issue-22903-grafana

Relevant output:

Pod Template:
  Containers:
   grafana:
    Environment:
      BAZ:                         qux
      FOO:                         bar

Cleanup:

$ kind delete cluster
Deleting cluster "kind" ...

@gldraphael
Copy link

@scottrigby I can confirm that setting env this way works. Thank you.
Was also able to read GF_DATABASE_PASSWORD from a kubernetes secret by setting:

envFromSecret: "secretName"

@stale
Copy link

stale bot commented Sep 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.

@stale stale bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 13, 2020
@scottrigby
Copy link
Member

This chart is deprecated: #23662
If still applicable, please re-open issues at: https://github.com/grafana/helm-charts

Though I think this one has been answered 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

6 participants