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

[stable/grafana] Utilize 5.x datasource and dashboard import tooling and general refactor #4713

Merged
merged 6 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stable/grafana/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: grafana
version: 0.8.5
version: 0.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky: I would argue 1.0.0 is more appropriate here, since this is a backwards incompatible change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

appVersion: 5.0.4
description: The leading tool for querying and visualizing time series and metrics.
home: https://grafana.net
Expand All @@ -9,4 +9,6 @@ sources:
maintainers:
- name: Ming Hsieh
email: [email protected]
- name: Ryan Luckie
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Github usernames

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

email: [email protected]
engine: gotpl
58 changes: 30 additions & 28 deletions stable/grafana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,33 @@ The command removes all the Kubernetes components associated with the chart and

## Configuration

| Parameter | Description | Default |
|-------------------------------------------|-------------------------------------|---------------------------------------------------|
| `server.image` | Container image to run | grafana/grafana:5.0.4 |
| `server.adminUser` | Admin user username | admin |
| `server.adminPassword` | Admin user password | Randomly generated |
| `server.antiAffinity.enabled` | Enable anti affinity | false |
| `server.antiAffinity.type` | Hard or soft anti affinity | hard |
| `server.persistentVolume.enabled` | Create a volume to store data | true |
| `server.persistentVolume.size` | Size of persistent volume claim | 1Gi RW |
| `server.persistentVolume.storageClass` | Type of persistent volume claim | `nil` (uses alpha storage class annotation) |
| `server.persistentVolume.accessMode` | ReadWriteOnce or ReadOnly | [ReadWriteOnce] |
| `server.persistentVolume.existingClaim` | Existing persistent volume claim | null |
| `server.persistentVolume.subPath` | Subdirectory of pvc to mount | null |
| `server.readinessProbe` | Server readiness probe | httpGet: {path: /api/health, port: 3000}, initialDelaySeconds: 30, timeoutSeconds: 30 |
| `server.replicaCount` | Desired number of grafana pods | 1 |
| `server.resources` | Server resource requests and limits | requests: {cpu: 100m, memory: 100Mi} |
| `server.tolerations` | node taints to tolerate (requires Kubernetes >=1.6) | null |
| `server.service.annotations` | Service annotations | null |
| `server.service.httpPort` | Service port | 80 |
| `server.service.loadBalancerIP` | IP to assign to load balancer | null |
| `server.service.loadBalancerSourceRanges` | List of IP CIDRs allowed access | null |
| `server.service.nodePort` | For service type "NodePort" | null |
| `server.service.externalIPs` | External IP addresses | null |
| `server.service.clusterIP` | Custom clusterIP to use for service | null |
| `server.service.type` | ClusterIP, NodePort, or LoadBalancer| ClusterIP |
| `server.setDatasource.enabled` | Creates grafana datasource with job | false |
| `server.extraEnv` | Extra environment variables to set in the server container. List of [EnvVar](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#envvar-v1-core) values | [] |
| `dashboardImports.enabled` | Creates grafana dashboards with job | false |

| Parameter | Description | Default |
|----------------------------|-------------------------------------|---------------------------------------------------------|
| `replicas` | Number of nodes | `1` |
| `image.repository` | Image repository | `grafana/grafana` |
| `image.tag` | Image tag. (`Must be >= 5.0.0`) Possible values listed [here](https://hub.docker.com/r/grafana/grafana/tags/).| `5.0.4`|
| `image.pullPolicy` | Image pull policy | `IfNotPresent` |
| `service.type` | Kubernetes service type | `ClusterIP` |
| `service.port` | Kubernetes port where service is exposed| `9000` |
| `service.annotations` | Service annotations | `80` |
| `ingress.enabled` | Enables Ingress | `false` |
| `ingress.annotations` | Ingress annotations | `{}` |
| `ingress.hosts` | Ingress accepted hostnames | `[]` |
| `ingress.tls` | Ingress TLS configuration | `[]` |
| `resources` | CPU/Memory resource requests/limits | `{}` |
| `nodeSelector` | Node labels for pod assignment | `{}` |
| `tolerations` | Toleration labels for pod assignment | `[]` |
| `affinity` | Affinity settings for pod assignment | `{}` |
| `persistence.enabled` | Use persistent volume to store data | `false` |
| `persistence.size` | Size of persistent volume claim | `10Gi` |
| `persistence.existingClaim`| Use an existing PVC to persist data | `nil` |
| `persistence.storageClass` | Type of persistent volume claim | `generic` |
| `persistence.accessModes` | Persistence access modes | `[]` |
| `persistence.subPath` | Mount a sub directory of the persistent volume if set | `""` |
| `env` | Extra environment variables passed to pods | `{}` |
| `datasource` | Configure grafana datasources | `{}` |
| `dashboardProviders` | Configure grafana dashboard providers | `{}` |
| `dashboards` | Dashboards to import | `{}` |
| `grafana.ini` | Grafana's primary configuration | `{}` |

33 changes: 16 additions & 17 deletions stable/grafana/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
1. Get your '{{ .Values.server.adminUser }}' user password by running:
1. Get your '{{ .Values.adminUser }}' user password by running:

kubectl get secret --namespace {{ .Release.Namespace }} {{ template "grafana.server.fullname" . }} -o jsonpath="{.data.grafana-admin-password}" | base64 --decode ; echo
kubectl get secret --namespace {{ .Release.Namespace }} {{ template "grafana.fullname" . }} -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

2. The Grafana server can be accessed via port {{ .Values.server.service.httpPort }} on the following DNS name from within your cluster:
2. The Grafana server can be accessed via port {{ .Values.service.httpPort }} on the following DNS name from within your cluster:

{{ template "grafana.server.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{ if .Values.server.ingress.enabled }}
{{ template "grafana.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{ if .Values.ingress.enabled }}
From outside the cluster, the server URL(s) are:
{{- range .Values.server.ingress.hosts }}
{{- range .Values.ingress.hosts }}
http://{{ . }}
{{- end }}
{{ else }}
Get the Grafana URL to visit by running these commands in the same shell:
{{ if contains "NodePort" .Values.server.service.type -}}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "grafana.server.fullname" . }})
{{ if contains "NodePort" .Values.service.type -}}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "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.server.service.type -}}
{{ 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 svc --namespace {{ .Release.Namespace }} -w {{ template "grafana.server.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "grafana.server.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.server.httpPort -}}
{{ else if contains "ClusterIP" .Values.server.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "grafana.fullname" . }},component={{ .Values.server.name }}" -o jsonpath="{.items[0].metadata.name}")
You can watch the status of by running 'kubectl get svc --namespace {{ .Release.Namespace }} -w {{ template "grafana.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "grafana.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.httpPort -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "echo" in this line needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timstoop good catch! fixed.

{{ else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "grafana.fullname" . }},component={{ .Values.name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 3000
{{- end }}
{{- end }}

3. Login with the password from step 1 and the username: {{ .Values.server.adminUser }}
3. Login with the password from step 1 and the username: {{ .Values.adminUser }}

{{- if .Values.server.persistentVolume.enabled }}
{{- else }}
{{- if not .Values.persistence.enabled }}
#################################################################################
###### WARNING: Persistence is disabled!!! You will lose your data when #####
###### the Grafana pod is terminated. #####
Expand Down
18 changes: 8 additions & 10 deletions stable/grafana/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@ Expand the name of the chart.
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- 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).
*/}}
{{- define "grafana.fullname" -}}
{{- $name := default "grafana" .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- 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).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "grafana.server.fullname" -}}
{{- define "grafana.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
Expand All @@ -32,3 +23,10 @@ If release name contains chart name it will be used as a full name.
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "grafana.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
55 changes: 46 additions & 9 deletions stable/grafana/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "grafana.fullname" . }}
labels:
app: {{ template "grafana.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
component: "{{ .Values.server.name }}"
heritage: "{{ .Release.Service }}"
release: "{{ .Release.Name }}"
name: {{ template "grafana.server.fullname" . }}-config
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
{{- if .Values.server.installPlugins }}
grafana-install-plugins: {{ .Values.server.installPlugins | quote }}
{{- if .Values.plugins }}
plugins: {{ default "" .Values.plugins | quote }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use the default function. Default values should come from values.yaml. Apply everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

{{- end }}
grafana.ini: |
{{- range $key, $value := index .Values "grafana.ini" }}
[{{ $key }}]
{{- range $elem, $elemVal := $value }}
{{ $elem }} = {{ $elemVal }}
{{- end }}
{{- end }}

{{- if .Values.datasources }}
{{- range $key, $value := .Values.datasources }}
{{ $key }}: |
{{ toYaml $value | indent 4 }}
{{- end -}}
{{- end -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The datasources configuration can contain passwords and other sensitive information. Seems like it should go into a Secret instead of a ConfigMap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. grafana.ini should probably also be a secret. Will fix in follow-up PR.


{{- if .Values.dashboardProviders }}
{{- range $key, $value := .Values.dashboardProviders }}
{{ $key }}: |
{{ toYaml $value | indent 4 }}
{{- end -}}
{{- end -}}

{{- if .Values.dashboards }}
download_dashboards.sh: |
#!/usr/bin/env sh
set -euf
mkdir -p /var/lib/grafana/dashboards
{{- range .Values.dashboards }}
{{ if .gnetId }}
curl -sk \
--connect-timeout 60 \
--max-time 60 \
-H "Accept: application/json" \
-H "Content-Type: application/json;charset=UTF-8" \
https://grafana.com/api/dashboards/{{ .gnetId }}/revisions/{{ default 1 .revision }}/download {{ if .datasource }}| sed 's|\"datasource\":[^,]*|\"datasource\": \"{{ .datasource }}\"|g'{{ end }} \
> /var/lib/grafana/dashboards/{{ .name }}.json
{{- end }}
{{- end }}
{{ toYaml .Values.serverConfigFile | indent 2 }}
{{- end }}
12 changes: 0 additions & 12 deletions stable/grafana/templates/dashboards-configmap.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions stable/grafana/templates/dashboards-import-configmap.yaml

This file was deleted.

32 changes: 0 additions & 32 deletions stable/grafana/templates/dashboards-import-job-configmap.yaml

This file was deleted.

52 changes: 0 additions & 52 deletions stable/grafana/templates/dashboards-import-job.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions stable/grafana/templates/dashboards-json-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "grafana.fullname" . }}-dashboards-json
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
{{- if .Values.dashboards }}
{{- range .Values.dashboards }}
{{ if .json }}
{{ .name }}.json: |
{{ .json }}
{{- end }}
{{- end }}
{{- end -}}
Loading