From bc0a90682c16f005a173427df80ddc8021bd8f5f Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Tue, 10 Jan 2023 14:09:25 +0100 Subject: [PATCH] add lua support --- grafana/helm/grafana/Chart.yaml | 2 +- grafana/helm/grafana/values.yaml.lua | 119 +++++++++++++++++++++++++++ grafana/helm/grafana/values.yaml.tpl | 81 ------------------ 3 files changed, 120 insertions(+), 82 deletions(-) create mode 100644 grafana/helm/grafana/values.yaml.lua delete mode 100644 grafana/helm/grafana/values.yaml.tpl diff --git a/grafana/helm/grafana/Chart.yaml b/grafana/helm/grafana/Chart.yaml index e5c6372f9..e5796f7a2 100644 --- a/grafana/helm/grafana/Chart.yaml +++ b/grafana/helm/grafana/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: grafana description: A Helm chart for grafana on plural type: application -version: 0.2.19 +version: 0.2.20 appVersion: "9.2.5" dependencies: - name: grafana diff --git a/grafana/helm/grafana/values.yaml.lua b/grafana/helm/grafana/values.yaml.lua new file mode 100644 index 000000000..fd57b7923 --- /dev/null +++ b/grafana/helm/grafana/values.yaml.lua @@ -0,0 +1,119 @@ +output = { + global={ + application={ + links={ + { description= "grafana web ui", + url=Var.Values.hostname + } + } + } + }, + grafana={ + admin={ + password=dedupe(Var, "grafana.grafana.admin.password", randAlphaNum(14)), + user='admin' + }, + ingress={ + annotations={}, + tls={ + { + hosts={ + Var.Values.hostname, + }, + secretName='grafana-tls' + } + }, + hosts={ + Var.Values.hostname + } + }, + ["grafana.ini"]={ + server={ + root_url="https://" .. default("grafana.onplural.sh", Var.Values.hostname), + }, + }, + }, +} + +if Var.Provider == "kind" then + output.grafana.ingress.annotations = { + ['external-dns.alpha.kubernetes.io/target']='127.0.0.1' + } +end + +if Var.SMTP ~= nil then + output.secret={ + smtp={ + enabled=true, + user=Var.SMTP.User, + password=Var.SMTP.Password + } + } + output.grafana.smtp={ + existingSecret='grafana-smtp-credentials', + userKey= "user", + passwordKey= "password", + } + grafana_ini = output.grafana["grafana.ini"] + grafana_ini.smtp={ + enabled=true, + host= Var.SMTP.Server .. ":" .. Var.SMTP.Port, + from_address=Var.SMTP.Sender + } +end + +if Var.OIDC ~= nil then + grafana_ini = output.grafana["grafana.ini"] + grafana_ini["auth.generic_oauth"]={ + name='Plural', + enabled=true, + allow_sign_up=true, + client_id=Var.OIDC.ClientId, + client_secret=Var.OIDC.ClientSecret, + scopes='openid profile', + auth_url=Var.OIDC.Configuration.AuthorizationEndpoint, + token_url=Var.OIDC.Configuration.TokenEndpoint, + api_url=Var.OIDC.Configuration.UserinfoEndpoint, + role_attribute_path="null", + groups_attribute_path='groups' + } +end + +if Var.Configuration then + if Var.Configuration.loki then + output.grafana.datasources={ + ["datasources.yaml"]={ + apiVersion=1, + deleteDatasources={ + { + name='Loki', + orgId=1 + } + } + } + } + end +end + +if Var.Values.usePostgres then + output.grafana.env={ + ['GF_DATABASE_TYPE']='postgres', + ['GF_DATABASE_HOST']='plural-postgres-grafana', + ['GF_DATABASE_NAME']='grafana', + ['GF_DATABASE_USER']='grafana', + ['GF_DATABASE_SSL_MODE']='require' + } + + output.grafana.envValueFrom={ + GF_DATABASE_PASSWORD={ + secretKeyRef={ + name='grafana.plural-postgres-grafana.credentials.postgresql.acid.zalan.do', + key='password' + } + } + } + + output.postgres={ + enabled=true + } +end diff --git a/grafana/helm/grafana/values.yaml.tpl b/grafana/helm/grafana/values.yaml.tpl deleted file mode 100644 index 92d4ee934..000000000 --- a/grafana/helm/grafana/values.yaml.tpl +++ /dev/null @@ -1,81 +0,0 @@ -global: - application: - links: - - description: grafana web ui - url: {{ .Values.hostname }} - -{{- if .SMTP }} -secret: - smtp: - enabled: true - user: {{ .SMTP.User }} - password: {{ .SMTP.Password }} -{{- end }} - -grafana: - admin: - password: {{ dedupe . "grafana.grafana.admin.password" (randAlphaNum 14) }} - user: admin - ingress: - {{- if eq .Provider "kind" }} - annotations: - external-dns.alpha.kubernetes.io/target: "127.0.0.1" - {{- end }} - tls: - - hosts: - - {{ .Values.hostname }} - secretName: grafana-tls - hosts: - - {{ .Values.hostname }} - {{- if .SMTP }} - smtp: - existingSecret: grafana-smtp-credentials - userKey: "user" - passwordKey: "password" - {{- end }} - grafana.ini: - server: - root_url: https://{{ .Values.hostname }} - {{- if .SMTP }} - smtp: - enabled: true - host: "{{ .SMTP.Server }}:{{ .SMTP.Port }}" - from_address: {{ .SMTP.Sender }} - {{- end }} - {{- if .OIDC }} - auth.generic_oauth: - name: Plural - enabled: true - allow_sign_up: true - client_id: {{ .OIDC.ClientId }} - client_secret: {{ .OIDC.ClientSecret }} - scopes: openid profile - auth_url: {{ .OIDC.Configuration.AuthorizationEndpoint }} - token_url: {{ .OIDC.Configuration.TokenEndpoint }} - api_url: {{ .OIDC.Configuration.UserinfoEndpoint }} - role_attribute_path: "null" - groups_attribute_path: groups - {{- end }} - {{- if .Configuration.loki }} - datasources: - datasources.yaml: - apiVersion: 1 - deleteDatasources: - - name: Loki - orgId: 1 - {{- end }} - {{- if .Values.usePostgres }} - env: - GF_DATABASE_TYPE: postgres - GF_DATABASE_HOST: plural-postgres-grafana - GF_DATABASE_NAME: grafana - GF_DATABASE_USER: grafana - GF_DATABASE_SSL_MODE: require - envValueFrom: - GF_DATABASE_PASSWORD: - secretKeyRef: - name: grafana.plural-postgres-grafana.credentials.postgresql.acid.zalan.do - key: password -postgres: - enabled: true - {{- end }}