From dac97fd4d7ae12b725b20bf214df05650d697c78 Mon Sep 17 00:00:00 2001 From: miguelaeh Date: Thu, 5 Sep 2019 13:56:12 +0200 Subject: [PATCH] Perform some minor improvements on grafana --- bitnami/grafana/templates/NOTES.txt | 19 ++++++----- bitnami/grafana/templates/_helpers.tpl | 18 ++++++++++ bitnami/grafana/templates/configmap.yaml | 6 +--- .../grafana/templates/dashboard-provider.yaml | 6 +--- bitnami/grafana/templates/deployment.yaml | 34 ++++++++----------- bitnami/grafana/templates/ingress.yaml | 6 +--- bitnami/grafana/templates/pvc.yaml | 6 +--- bitnami/grafana/templates/secret.yaml | 12 +++---- bitnami/grafana/templates/service.yaml | 10 ++---- bitnami/grafana/values.yaml | 32 +++++++++++------ 10 files changed, 74 insertions(+), 75 deletions(-) diff --git a/bitnami/grafana/templates/NOTES.txt b/bitnami/grafana/templates/NOTES.txt index c9462658b..a0062cc7c 100644 --- a/bitnami/grafana/templates/NOTES.txt +++ b/bitnami/grafana/templates/NOTES.txt @@ -1,5 +1,7 @@ ** Please be patient while the chart is being deployed ** + 1. Get the application URL by running these commands: + {{- if .Values.ingress.enabled }} {{- range $host := .Values.ingress.hosts }} {{- range .paths }} @@ -7,21 +9,22 @@ {{- end }} {{- end }} {{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "grafana.fullname" . }}) - export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") - echo http://$NODE_IP:$NODE_PORT + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "grafana.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT {{- else if contains "LoadBalancer" .Values.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "grafana.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "grafana.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - echo http://$SERVICE_IP:{{ .Values.service.port }} + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "grafana.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} {{- else if contains "ClusterIP" .Values.service.type }} - echo "Browse to http://127.0.0.1:8080" - kubectl port-forward svc/{{ include "grafana.fullname" . }} 8080:{{ .Values.service.port }} + echo "Browse to http://127.0.0.1:8080" + kubectl port-forward svc/{{ include "grafana.fullname" . }} 8080:{{ .Values.service.port }} {{- end }} 2. Get the admin password: - echo Password: $(kubectl get secret {{ include "grafana.fullname" . }}-secret -o jsonpath="{.data.GF_SECURITY_ADMIN_PASSWORD}" | base64 --decode) + + echo "Password: $(kubectl get secret {{ include "grafana.fullname" . }}-secret -o jsonpath="{.data.GF_SECURITY_ADMIN_PASSWORD}" | base64 --decode)" {{- if and (contains "bitnami/" .Values.image.repository) (not (.Values.image.tag | toString | regexFind "-r\\d+$|sha256:")) }} diff --git a/bitnami/grafana/templates/_helpers.tpl b/bitnami/grafana/templates/_helpers.tpl index 9be02f83b..4cd6f1153 100644 --- a/bitnami/grafana/templates/_helpers.tpl +++ b/bitnami/grafana/templates/_helpers.tpl @@ -6,6 +6,24 @@ Expand the name of the chart. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{/* +Common labels +*/}} +{{- define "grafana.labels" -}} +app.kubernetes.io/name: {{ include "grafana.name" . }} +helm.sh/chart: {{ include "grafana.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector +*/}} +{{- define "grafana.matchLabels" -}} +app.kubernetes.io/name: {{ include "grafana.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + {{/* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). diff --git a/bitnami/grafana/templates/configmap.yaml b/bitnami/grafana/templates/configmap.yaml index f25dddd33..2b5afd85f 100644 --- a/bitnami/grafana/templates/configmap.yaml +++ b/bitnami/grafana/templates/configmap.yaml @@ -2,11 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ include "grafana.fullname" . }}-envvars - labels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - helm.sh/chart: {{ include "grafana.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + labels: {{ include "grafana.labels" . | nindent 4 }} data: GF_SECURITY_ADMIN_USER: {{ .Values.admin.user | quote }} {{- if .Values.plugins }} diff --git a/bitnami/grafana/templates/dashboard-provider.yaml b/bitnami/grafana/templates/dashboard-provider.yaml index e14b7fe41..bbcd741b3 100644 --- a/bitnami/grafana/templates/dashboard-provider.yaml +++ b/bitnami/grafana/templates/dashboard-provider.yaml @@ -3,11 +3,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ include "grafana.fullname" . }}-provider - labels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - helm.sh/chart: {{ include "grafana.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + labels: {{ include "grafana.labels" . | nindent 4 }} data: default-provider.yaml: |- apiVersion: 1 diff --git a/bitnami/grafana/templates/deployment.yaml b/bitnami/grafana/templates/deployment.yaml index a8482285b..871674304 100644 --- a/bitnami/grafana/templates/deployment.yaml +++ b/bitnami/grafana/templates/deployment.yaml @@ -2,17 +2,11 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "grafana.fullname" . }} - labels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - helm.sh/chart: {{ include "grafana.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + labels: {{ include "grafana.labels" . | nindent 4 }} spec: replicas: {{ .Values.replicaCount }} selector: - matchLabels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} + matchLabels: {{ include "grafana.matchLabels" . | nindent 6 }} {{- if .Values.updateStrategy }} strategy: {{ toYaml .Values.updateStrategy | nindent 4 }} {{- end }} @@ -39,6 +33,18 @@ spec: fsGroup: {{ .Values.securityContext.fsGroup }} runAsNonRoot: {{ .Values.securityContext.runAsNonRoot }} {{- end }} +{{- with .Values.nodeSelector }} + nodeSelector: +{{- tpl (toYaml .) $ | indent 8 }} +{{- end }} +{{- with .Values.affinity }} + affinity: +{{- tpl (toYaml .) $ | indent 8 }} +{{- end }} +{{- with .Values.tolerations }} + tolerations: +{{- tpl (toYaml .) $ | indent 8 }} +{{- end }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" @@ -159,15 +165,3 @@ spec: configMap: name: {{ .name }} {{- end }} -{{- with .Values.nodeSelector }} - nodeSelector: -{{- tpl (toYaml .) $ | indent 8 }} -{{- end }} -{{- with .Values.affinity }} - affinity: -{{- tpl (toYaml .) $ | indent 8 }} -{{- end }} -{{- with .Values.tolerations }} - tolerations: -{{- tpl (toYaml .) $ | indent 8 }} -{{- end }} diff --git a/bitnami/grafana/templates/ingress.yaml b/bitnami/grafana/templates/ingress.yaml index 830650e14..7d12af3da 100644 --- a/bitnami/grafana/templates/ingress.yaml +++ b/bitnami/grafana/templates/ingress.yaml @@ -3,11 +3,7 @@ apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ include "grafana.fullname" . }} - labels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - helm.sh/chart: {{ include "grafana.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + labels: {{ include "grafana.labels" . | nindent 4 }} {{- with .Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/bitnami/grafana/templates/pvc.yaml b/bitnami/grafana/templates/pvc.yaml index 41b294d91..c3f721ce3 100644 --- a/bitnami/grafana/templates/pvc.yaml +++ b/bitnami/grafana/templates/pvc.yaml @@ -3,11 +3,7 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: name: {{ template "grafana.fullname" . }} - labels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - helm.sh/chart: {{ include "grafana.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + labels: {{ include "grafana.labels" . | nindent 4 }} spec: accessModes: - {{ .Values.persistence.accessMode | quote }} diff --git a/bitnami/grafana/templates/secret.yaml b/bitnami/grafana/templates/secret.yaml index 9393bf66f..3851c8a3c 100644 --- a/bitnami/grafana/templates/secret.yaml +++ b/bitnami/grafana/templates/secret.yaml @@ -2,21 +2,17 @@ apiVersion: v1 kind: Secret metadata: name: {{ template "grafana.fullname" . }}-secret - labels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - helm.sh/chart: {{ include "grafana.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + labels: {{ include "grafana.labels" . | nindent 4 }} type: Opaque data: {{- if .Values.admin.password }} - GF_SECURITY_ADMIN_PASSWORD: {{ .Values.admin.password }} + GF_SECURITY_ADMIN_PASSWORD: {{ .Values.admin.password | b64enc | quote }} {{- else }} GF_SECURITY_ADMIN_PASSWORD: {{ randAlphaNum 10 | b64enc | quote }} {{- end }} {{- if and .Values.smtp.enabled (not .Values.smtp.existingSecret) }} {{- if and .Values.smtp.user .Values.smtp.password }} - GF_SMTP_USER: {{ .Values.smtp.user }} - GF_SMTP_PASSWORD: {{ .Values.smtp.password }} + GF_SMTP_USER: {{ .Values.smtp.user | b64enc | quote }} + GF_SMTP_PASSWORD: {{ .Values.smtp.password | b64enc | quote }} {{- end }} {{- end }} diff --git a/bitnami/grafana/templates/service.yaml b/bitnami/grafana/templates/service.yaml index 3bd3219cd..2961a0cf9 100644 --- a/bitnami/grafana/templates/service.yaml +++ b/bitnami/grafana/templates/service.yaml @@ -2,11 +2,7 @@ apiVersion: v1 kind: Service metadata: name: {{ include "grafana.fullname" . }} - labels: - app.kubernetes.io/name: {{ include "grafana.name" . }} - helm.sh/chart: {{ include "grafana.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + labels: {{ include "grafana.labels" . | nindent 4 }} {{- if .Values.service.annotations }} annotations: {{ toYaml .Values.service.annotations | nindent 4 }} {{- end }} @@ -23,6 +19,4 @@ spec: {{- if .Values.service.nodePort }} nodePort: {{ .Values.service.nodePort }} {{- end }} - selector: - app.kubernetes.io/name: {{ include "grafana.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} + selector: {{ include "grafana.matchLabels" . | nindent 4 }} diff --git a/bitnami/grafana/values.yaml b/bitnami/grafana/values.yaml index b4089703b..6bada71a2 100644 --- a/bitnami/grafana/values.yaml +++ b/bitnami/grafana/values.yaml @@ -35,17 +35,18 @@ image: ## # fullnameOverride: -# Number of grafana Pod replicas +## Number of grafana Pod replicas +## replicaCount: 1 ## Set up update strategy for Grafana installation. Set to Recreate if you use persistent volume that cannot be mounted by more than one pods to makesure the pods is destroyed first. ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy ## Example: -## updateStrategy: -## type: RollingUpdate -## rollingUpdate: -## maxSurge: 25% -## maxUnavailable: 25% +# updateStrategy: +# type: RollingUpdate +# rollingUpdate: +# maxSurge: 25% +# maxUnavailable: 25% updateStrategy: type: RollingUpdate @@ -56,13 +57,14 @@ updateStrategy: ## Admin access configuration ## If a password is not provided a random password will be generated -# +## admin: user: "admin" # password: ## SMTP configuration ## Use either a secret container the credentials or set the credentials through command line. +## smtp: enabled: false # Provide credentials by command line @@ -105,6 +107,7 @@ ldap: ## Parameters to override the default grafana.ini and custom.ini files. ## It is needed to create a configmap containing the grafana.ini and custom.ini files. +## config: useGrafanaIniFile: false grafanaIniConfigMap: @@ -113,6 +116,7 @@ config: ## Create dasboard provider to load dashboards, a default one is created to load ## dashboards from "/opt/bitnami/grafana/dashboards" +## dashboardsProvider: enabled: false ## ConfigMap with a custom provider file. @@ -126,16 +130,19 @@ dashboardsProvider: ## dashboardsConfigMaps: ## - mydashboard ## - myotherdashboard +## dashboardsConfigMaps: [] ## Create datasources from a custom secret ## The secret must contain the files +## datasources: secretName: ## Enable persistence using Persistent Volume Claims ## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/ ## +## persistence: enabled: true ## wordpress data Persistent Volume Storage Class @@ -155,6 +162,7 @@ persistence: ## Configure extra options for liveness and readiness probes ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#configure-probes) +## livenessProbe: initialDelaySeconds: 120 periodSeconds: 10 @@ -168,7 +176,8 @@ readinessProbe: failureThreshold: 6 successThreshold: 1 -# Service configuration +## Service configuration +## service: port: 3000 type: ClusterIP @@ -188,7 +197,8 @@ service: ## # loadBalancerIP: -# Ingress configuration +## Ingress configuration +## ingress: enabled: false annotations: {} @@ -203,8 +213,8 @@ ingress: # hosts: # - chart-example.local -# SecurityContext configuration - +## SecurityContext configuration +## securityContext: enabled: true runAsUser: 1001