rancher-partner-charts/charts/kubecost/cost-analyzer/2.0.2/templates/grafana-deployment.yaml

311 lines
12 KiB
YAML

{{- if (eq (include "cost-analyzer.grafanaEnabled" .) "true") }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "grafana.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "grafana.name" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.grafana.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
replicas: {{ .Values.grafana.replicas }}
selector:
matchLabels:
app: {{ template "grafana.name" . }}
release: {{ .Release.Name }}
strategy:
type: {{ .Values.grafana.deploymentStrategy }}
{{- if ne .Values.grafana.deploymentStrategy "RollingUpdate" }}
rollingUpdate: null
{{- end }}
template:
metadata:
labels:
app: {{ template "grafana.name" . }}
release: {{ .Release.Name }}
{{- if .Values.global.additionalLabels }}
{{ toYaml .Values.global.additionalLabels | nindent 8 }}
{{- end }}
{{- with .Values.grafana.podAnnotations }}
annotations:
{{ toYaml . | indent 8 }}
{{- end }}
spec:
serviceAccountName: {{ template "grafana.serviceAccountName" . }}
{{- if .Values.grafana.schedulerName }}
schedulerName: "{{ .Values.grafana.schedulerName }}"
{{- end }}
{{- if .Values.grafana.securityContext }}
securityContext:
{{- toYaml .Values.grafana.securityContext | nindent 8 }}
{{- else if and (.Values.global.platforms.openshift.enabled) (.Values.global.platforms.openshift.securityContext) }}
securityContext:
{{- toYaml .Values.global.platforms.openshift.securityContext | nindent 8 }}
{{- else if .Values.global.securityContext }}
securityContext:
{{- toYaml .Values.global.securityContext | nindent 8 }}
{{- end }}
{{- if .Values.grafana.priorityClassName }}
priorityClassName: "{{ .Values.grafana.priorityClassName }}"
{{- end }}
{{- if .Values.grafana.dashboards }}
initContainers:
- name: download-dashboards
image: "{{ .Values.grafana.downloadDashboardsImage.repository }}:{{ .Values.grafana.downloadDashboardsImage.tag }}"
imagePullPolicy: {{ .Values.grafana.downloadDashboardsImage.pullPolicy }}
command: ["sh", "/etc/grafana/download_dashboards.sh"]
{{- with .Values.global.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: config
mountPath: "/etc/grafana/download_dashboards.sh"
subPath: download_dashboards.sh
- name: storage
mountPath: "/var/lib/grafana"
{{- if .Values.grafana.persistence.subPath }}
subPath: {{ .Values.grafana.persistence.subPath }}
{{- end }}
{{- range .Values.grafana.extraSecretMounts }}
- name: {{ .name }}
mountPath: {{ .mountPath }}
readOnly: {{ .readOnly }}
{{- end }}
{{- end }}
{{- if .Values.grafana.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.grafana.image.pullSecrets }}
- name: {{ . }}
{{- end}}
{{- end }}
containers:
{{- if .Values.grafana.sidecar.dashboards.enabled }}
- name: {{ template "grafana.name" . }}-sc-dashboard
image: "{{ .Values.grafana.sidecar.image.repository }}:{{ .Values.grafana.sidecar.image.tag }}"
imagePullPolicy: {{ .Values.grafana.sidecar.image.pullPolicy }}
{{- if .Values.global.containerSecurityContext }}
securityContext:
{{- toYaml .Values.global.containerSecurityContext | nindent 12 -}}
{{- end }}
env:
- name: LABEL
value: "{{ .Values.grafana.sidecar.dashboards.label }}"
- name: FOLDER
value: "{{ .Values.grafana.sidecar.dashboards.folder }}"
- name: ERROR_THROTTLE_SLEEP
value: "{{ .Values.grafana.sidecar.dashboards.error_throttle_sleep }}"
{{- with .Values.grafana.sidecar.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: sc-dashboard-volume
mountPath: {{ .Values.grafana.sidecar.dashboards.folder | quote }}
{{- end}}
{{- if .Values.grafana.sidecar.datasources.enabled }}
- name: {{ template "grafana.name" . }}-sc-datasources
image: "{{ .Values.grafana.sidecar.image.repository }}:{{ .Values.grafana.sidecar.image.tag }}"
imagePullPolicy: {{ .Values.grafana.sidecar.image.pullPolicy }}
{{- with .Values.global.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: LABEL
value: "{{ .Values.grafana.sidecar.datasources.label }}"
- name: FOLDER
value: "/etc/grafana/provisioning/datasources"
- name: ERROR_THROTTLE_SLEEP
value: "{{ .Values.grafana.sidecar.datasources.error_throttle_sleep }}"
resources:
{{ toYaml .Values.grafana.sidecar.resources | indent 12 }}
volumeMounts:
- name: sc-datasources-volume
mountPath: "/etc/grafana/provisioning/datasources"
{{- end}}
- name: grafana
image: "{{ .Values.grafana.image.repository }}:{{ .Values.grafana.image.tag }}"
imagePullPolicy: {{ .Values.grafana.image.pullPolicy }}
{{- with .Values.global.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: config
mountPath: "/etc/grafana/grafana.ini"
subPath: grafana.ini
- name: ldap
mountPath: "/etc/grafana/ldap.toml"
subPath: ldap.toml
{{- if .Values.grafana.dashboards }}
{{- range $provider, $dashboards := .Values.grafana.dashboards }}
{{- range $key, $value := $dashboards }}
{{- if hasKey $value "json" }}
- name: dashboards-{{ $provider }}
mountPath: "/var/lib/grafana/dashboards/{{ $provider }}/{{ $key }}.json"
subPath: "{{ $key }}.json"
{{- end }}
{{- end }}
{{- end }}
{{- end -}}
{{- if .Values.grafana.dashboardsConfigMaps }}
{{- range keys .Values.grafana.dashboardsConfigMaps }}
- name: dashboards-{{ . }}
mountPath: "/var/lib/grafana/dashboards/{{ . }}"
{{- end }}
{{- end }}
{{- if or (.Values.grafana.datasources) (include "cost-analyzer.grafanaEnabled" .) }}
- name: config
mountPath: "/etc/grafana/provisioning/datasources/datasources.yaml"
subPath: datasources.yaml
{{- end }}
{{- if .Values.grafana.dashboardProviders }}
- name: config
mountPath: "/etc/grafana/provisioning/dashboards/dashboardproviders.yaml"
subPath: dashboardproviders.yaml
{{- end }}
{{- if .Values.grafana.sidecar.dashboards.enabled }}
- name: sc-dashboard-volume
mountPath: {{ .Values.grafana.sidecar.dashboards.folder | quote }}
- name: sc-dashboard-provider
mountPath: "/etc/grafana/provisioning/dashboards/sc-dashboardproviders.yaml"
subPath: provider.yaml
{{- end}}
{{- if .Values.grafana.sidecar.datasources.enabled }}
- name: sc-datasources-volume
mountPath: "/etc/grafana/provisioning/datasources"
{{- end}}
- name: storage
mountPath: "/var/lib/grafana"
{{- if .Values.grafana.persistence.subPath }}
subPath: {{ .Values.grafana.persistence.subPath }}
{{- end }}
{{- range .Values.grafana.extraSecretMounts }}
- name: {{ .name }}
mountPath: {{ .mountPath }}
readOnly: {{ .readOnly }}
{{- end }}
ports:
- name: service
containerPort: {{ .Values.grafana.service.port }}
protocol: TCP
- name: grafana
containerPort: 3000
protocol: TCP
env:
- name: GF_SECURITY_ADMIN_USER
valueFrom:
secretKeyRef:
name: {{ template "grafana.fullname" . }}
key: admin-user
- name: GF_SECURITY_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "grafana.fullname" . }}
key: admin-password
{{- if .Values.grafana.plugins }}
- name: GF_INSTALL_PLUGINS
valueFrom:
configMapKeyRef:
name: {{ template "grafana.fullname" . }}
key: plugins
{{- end }}
{{- if .Values.grafana.smtp.existingSecret }}
- name: GF_SMTP_USER
valueFrom:
secretKeyRef:
name: {{ .Values.grafana.smtp.existingSecret }}
key: user
- name: GF_SMTP_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.grafana.smtp.existingSecret }}
key: password
{{- end }}
{{- range $key, $value := .Values.grafana.env }}
- name: "{{ $key }}"
value: "{{ $value }}"
{{- end }}
{{- if .Values.grafana.envFromSecret }}
envFrom:
- secretRef:
name: {{ .Values.grafana.envFromSecret }}
{{- end }}
livenessProbe:
{{ toYaml .Values.grafana.livenessProbe | indent 12 }}
readinessProbe:
{{ toYaml .Values.grafana.readinessProbe | indent 12 }}
resources:
{{ toYaml .Values.grafana.resources | indent 12 }}
{{- with .Values.grafana.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.grafana.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.grafana.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
- name: config
configMap:
name: {{ template "grafana.fullname" . }}
{{- if .Values.grafana.dashboards }}
{{- range keys .Values.grafana.dashboards }}
- name: dashboards-{{ . }}
configMap:
name: {{ template "grafana.fullname" $ }}-dashboards-{{ . }}
{{- end }}
{{- end }}
{{- if .Values.grafana.dashboardsConfigMaps }}
{{- range $provider, $name := .Values.grafana.dashboardsConfigMaps }}
- name: dashboards-{{ $provider }}
configMap:
name: {{ $name }}
{{- end }}
{{- end }}
- name: ldap
secret:
{{- if .Values.grafana.ldap.existingSecret }}
secretName: {{ .Values.grafana.ldap.existingSecret }}
{{- else }}
secretName: {{ template "grafana.fullname" . }}
{{- end }}
items:
- key: ldap-toml
path: ldap.toml
- name: storage
{{- if .Values.grafana.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.grafana.persistence.existingClaim | default (include "grafana.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end -}}
{{- if .Values.grafana.sidecar.dashboards.enabled }}
- name: sc-dashboard-volume
emptyDir: {}
- name: sc-dashboard-provider
configMap:
name: {{ template "grafana.fullname" . }}-config-dashboards
{{- end }}
{{- if .Values.grafana.sidecar.datasources.enabled }}
- name: sc-datasources-volume
emptyDir: {}
{{- end -}}
{{- range .Values.grafana.extraSecretMounts }}
- name: {{ .name }}
secret:
secretName: {{ .secretName }}
defaultMode: {{ .defaultMode }}
{{- end }}
{{ end }}