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

Commit

Permalink
[stable/grafana] Namespace override (#18986)
Browse files Browse the repository at this point in the history
* [stable/grafana] Namespace override

Signed-off-by: Alexander Katsyuba <arruzk@gmail.com>

* [stable/grafana] Bump chart version

Signed-off-by: Alexander Katsyuba <arruzk@gmail.com>

* [stable/grafana] Fix nil pointer exception

Signed-off-by: Alexander Katsyuba <arruzk@gmail.com>
  • Loading branch information
arruzk authored and k8s-ci-robot committed Jan 2, 2020
1 parent 95280d2 commit 1208876
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 34 deletions.
2 changes: 1 addition & 1 deletion stable/grafana/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: grafana
version: 4.2.3
version: 4.3.0
appVersion: 6.5.2
kubeVersion: "^1.8.0-0"
description: The leading tool for querying and visualizing time series and metrics.
Expand Down
1 change: 1 addition & 0 deletions stable/grafana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ This version requires Helm >= 2.12.0.
| `testFramework.tag` | `test-framework` image tag. | `0.4.0` |
| `testFramework.securityContext` | `test-framework` securityContext | `{}` |
| `downloadDashboards.env` | Environment variables to be passed to the `download-dashboards` container | `{}` |
| `namespaceOverride` | Override the deployment namespace | `""` (`Release.Namespace`) |


### Example of extraVolumeMounts
Expand Down
16 changes: 8 additions & 8 deletions stable/grafana/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
1. Get your '{{ .Values.adminUser }}' user password by running:

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

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

{{ template "grafana.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{ template "grafana.fullname" . }}.{{ template "grafana.namespace" . }}.svc.cluster.local
{{ if .Values.ingress.enabled }}
If you bind grafana to 80, please update values in values.yaml and reinstall:
```
Expand All @@ -29,17 +29,17 @@
{{ else }}
Get the Grafana URL to visit by running these commands in the same shell:
{{ 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}")
export NODE_PORT=$(kubectl get --namespace {{ template "grafana.namespace" . }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "grafana.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ template "grafana.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 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}')
You can watch the status of by running 'kubectl get svc --namespace {{ template "grafana.namespace" . }} -w {{ template "grafana.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ template "grafana.namespace" . }} {{ template "grafana.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
http://$SERVICE_IP:{{ .Values.service.port -}}
{{ else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "grafana.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 3000
export POD_NAME=$(kubectl get pods --namespace {{ template "grafana.namespace" . }} -l "app={{ template "grafana.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace {{ template "grafana.namespace" . }} port-forward $POD_NAME 3000
{{- end }}
{{- end }}

Expand Down
11 changes: 11 additions & 0 deletions stable/grafana/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ Create the name of the service account
{{ default "default" .Values.serviceAccount.nameTest }}
{{- end -}}
{{- end -}}

{{/*
Allow the release namespace to be overridden for multi-namespace deployments in combined charts
*/}}
{{- define "grafana.namespace" -}}
{{- if .Values.namespaceOverride -}}
{{- .Values.namespaceOverride -}}
{{- else -}}
{{- .Release.Namespace -}}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion stable/grafana/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: {{ template "grafana.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
roleRef:
kind: ClusterRole
name: {{ template "grafana.fullname" . }}-clusterrole
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/configmap-dashboard-provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
{{ toYaml . | indent 4 }}
{{- end }}
name: {{ template "grafana.fullname" . }}-config-dashboards
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
data:
provider.yaml: |-
apiVersion: 1
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/dashboards-json-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "grafana.fullname" $ }}-dashboards-{{ $provider }}
namespace: {{ $.Release.Namespace }}
namespace: {{ template "grafana.namespace" $ }}
labels:
app: {{ template "grafana.name" $ }}
chart: {{ template "grafana.chart" $ }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/headless-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "grafana.fullname" . }}-headless
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
3 changes: 2 additions & 1 deletion stable/grafana/templates/poddisruptionbudget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: {{ template "grafana.name" . }}
name: {{ template "grafana.name" . }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/podsecuritypolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand Down
4 changes: 2 additions & 2 deletions stable/grafana/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand All @@ -20,7 +20,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: {{ template "grafana.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
{{- if .Values.rbac.namespaced }}
roleRef:
kind: Role
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/secret-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "grafana.fullname" . }}-env
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ metadata:
{{ toYaml . | indent 4 }}
{{- end }}
name: {{ template "grafana.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
{{- end }}
2 changes: 1 addition & 1 deletion stable/grafana/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ template "grafana.chart" . }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/tests/test-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "grafana.fullname" . }}-test
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/tests/test-podsecuritypolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: {{ template "grafana.fullname" . }}-test
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand Down
2 changes: 1 addition & 1 deletion stable/grafana/templates/tests/test-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ template "grafana.fullname" . }}-test
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand Down
4 changes: 2 additions & 2 deletions stable/grafana/templates/tests/test-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ template "grafana.fullname" . }}-test
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
labels:
app: {{ template "grafana.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand All @@ -16,5 +16,5 @@ roleRef:
subjects:
- kind: ServiceAccount
name: {{ template "grafana.serviceAccountNameTest" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
{{- end }}
2 changes: 1 addition & 1 deletion stable/grafana/templates/tests/test-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ metadata:
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "grafana.serviceAccountNameTest" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
{{- end }}
2 changes: 1 addition & 1 deletion stable/grafana/templates/tests/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
release: "{{ .Release.Name }}"
annotations:
"helm.sh/hook": test-success
namespace: {{ .Release.Namespace }}
namespace: {{ template "grafana.namespace" . }}
spec:
serviceAccountName: {{ template "grafana.serviceAccountNameTest" . }}
{{- if .Values.testFramework.securityContext }}
Expand Down
4 changes: 4 additions & 0 deletions stable/grafana/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,7 @@ sidecar:
# Otherwise the namespace in which the sidecar is running will be used.
# It's also possible to specify ALL to search in all namespaces
searchNamespace: null

## Override the deployment namespace
##
namespaceOverride: ""

0 comments on commit 1208876

Please sign in to comment.