Skip to content

Commit

Permalink
fix: simplify kommander's grafana dashboard job
Browse files Browse the repository at this point in the history
This commit simplifies Kommanders's `set-grafana-home-dashboard` job by
using container commands over the previous setup of configmaps and
volumes.

This also solves the issue of the post-install hook not
being triggered properly
  • Loading branch information
samvantran committed Feb 19, 2020
1 parent e7bfb52 commit 4b195d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 95 deletions.
2 changes: 1 addition & 1 deletion stable/kommander/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ maintainers:
- name: alejandroEsc
- name: jimmidyson
name: kommander
version: 0.4.10
version: 0.4.11
113 changes: 19 additions & 94 deletions stable/kommander/templates/grafana/hooks-home-dashboard.yaml
Original file line number Diff line number Diff line change
@@ -1,116 +1,41 @@
{{- if .Values.grafana.enabled }}
---
# Unable to get post-install job hook working, which is why
# this is a regular Job. The retries in the configmap script
# should ensure that this successfully runs once the Grafana
# server is up.
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.grafana.hooks.jobName | quote }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "kommander.labels" . | indent 4 }}
spec:
template:
metadata:
name: {{ .Values.grafana.hooks.jobName | quote }}
spec:
restartPolicy: Never
containers:
- name: {{ .Values.grafana.hooks.jobName | quote }}
image: {{ .Values.grafana.hooks.image | quote }}
command: ["/bin/sh", "-c", "/job/run.sh"]
env:
- name: X_FORWARDED_USER
valueFrom:
secretKeyRef:
name: {{ .Values.grafana.hooks.secretKeyRef }}
key: username
volumeMounts:
- mountPath: /job
name: job
volumes:
- name: job
configMap:
name: {{ .Values.grafana.hooks.jobName }}
defaultMode: 0777
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.grafana.hooks.jobName }}-upgrade-hook
name: {{ .Values.grafana.hooks.jobName }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "kommander.labels" . | indent 4 }}
annotations:
helm.sh/hook: post-upgrade
helm.sh/hook-weight: "-4"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "5"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
metadata:
name: {{ .Values.grafana.hooks.jobName }}-upgrade-hook
name: {{ .Values.grafana.hooks.jobName }}
spec:
restartPolicy: OnFailure
containers:
- name: {{ .Values.grafana.hooks.jobName }}-upgrade-hook
- name: {{ .Values.grafana.hooks.jobName }}
image: {{ .Values.grafana.hooks.image | quote }}
command: ["/bin/sh", "-c", "/job/run.sh"]
env:
- name: X_FORWARDED_USER
valueFrom:
secretKeyRef:
name: {{ .Values.grafana.hooks.secretKeyRef }}
key: username
volumeMounts:
- mountPath: /job
name: job
volumes:
- name: job
configMap:
name: {{ .Values.grafana.hooks.jobName }}
defaultMode: 0777
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.grafana.hooks.jobName }}
data:
run.sh: |-
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
CURL="curl --verbose --fail --max-time 30 --retry 20 --retry-connrefused"
DASHBOARD_ID=$($CURL -H "X-Forwarded-User: $X_FORWARDED_USER" {{ .Values.grafana.hooks.serviceURL }}/api/dashboards/uid/{{ .Values.grafana.hooks.homeDashboardUID }} | jq '.dashboard.id')
echo "setting home dashboard to ID" $DASHBOARD_ID
$CURL -X PUT -H "Content-Type: application/json" -H "X-Forwarded-User: $X_FORWARDED_USER" -d '{"homeDashboardId":'"$DASHBOARD_ID"'}' {{ .Values.grafana.hooks.serviceURL }}/api/org/preferences
---
apiVersion: batch/v1
kind: Job
metadata:
name: cleanup-{{ .Values.grafana.hooks.jobName }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "kommander.labels" . | indent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: cleanup-{{ .Values.grafana.hooks.jobName }}
spec:
serviceAccountName: {{ .Values.grafana.hooks.kommanderServiceAccount }}
containers:
- name: kubectl
image: bitnami/kubectl:1.16.2
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- kubectl delete configmap {{ .Values.grafana.hooks.jobName }} --namespace={{ .Release.Namespace }}
restartPolicy: OnFailure
command:
- sh
- "-c"
- |
/bin/bash <<'EOF'
set -o nounset
set -o errexit
set -o pipefail
CURL="curl --verbose --fail --max-time 30 --retry 20 --retry-connrefused"
DASHBOARD_ID=$($CURL -H "X-Forwarded-User: $X_FORWARDED_USER" {{ .Values.grafana.hooks.serviceURL }}/api/dashboards/uid/{{ .Values.grafana.hooks.homeDashboardUID }} | jq '.dashboard.id')
echo "setting home dashboard to ID" $DASHBOARD_ID
$CURL -X PUT -H "Content-Type: application/json" -H "X-Forwarded-User: $X_FORWARDED_USER" -d '{"homeDashboardId":'"$DASHBOARD_ID"'}' {{ .Values.grafana.hooks.serviceURL }}/api/org/preferences
EOF
{{- end }}

0 comments on commit 4b195d6

Please sign in to comment.