-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: simplify kommander's grafana dashboard job #433
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4b195d6
fix: simplify kommander's grafana dashboard job
samvantran ee2234a
Merge branch 'master' into svt/test-grafana-hooks
alejandroEsc 246dd77
Merge branch 'master' into svt/test-grafana-hooks
alejandroEsc 67f3c98
Merge branch 'master' into svt/test-grafana-hooks
alejandroEsc 3502a1f
Merge branch 'master' into svt/test-grafana-hooks
samvantran 29df202
Merge branch 'master' into svt/test-grafana-hooks
shaneutt 784a6d1
Update stable/kommander/templates/grafana/hooks-home-dashboard.yaml
samvantran 8c02d88
Merge branch 'master' into svt/test-grafana-hooks
samvantran ac6b6c3
Merge branch 'master' into svt/test-grafana-hooks
samvantran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ maintainers: | |
- name: alejandroEsc | ||
- name: jimmidyson | ||
name: kommander | ||
version: 0.4.26 | ||
version: 0.4.27 |
113 changes: 19 additions & 94 deletions
113
stable/kommander/templates/grafana/hooks-home-dashboard.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/search/?query={{ .Values.grafana.hooks.dashboardName | urlquery }} | jq '.[0].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') | ||
samvantran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a change here while this PR was open to go back to using the dashboard name to query for the dashboard ID - let's get that change in here as well