apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "grafana.fullname" . }}
  labels:
    app: {{ template "grafana.fullname" . }}
    chart: {{ template "grafana.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "grafana.fullname" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "grafana.fullname" . }}
        release: {{ .Release.Name }}
      annotations:
        prometheus.io/scrape: 'false'
        {{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
        {{- end }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 3000
              protocol: TCP
#          livenessProbe:
#            httpGet:
#              path: /
#              port: http
#          readinessProbe:
#            httpGet:
#              path: /
#              port: http
          env:
          - name: GF_PATHS_PROVISIONING
            value: /etc/grafana/provisioning/
          {{- if .Values.password }}
          - name: GF_SECURITY_ADMIN_USER
            value: {{ .Values.user }}
          - name: GF_SECURITY_ADMIN_PASSWORD
            value: {{ .Values.password }}
          {{- else }}
          - name: GF_AUTH_BASIC_ENABLED
            value: "false"
          - name: GF_AUTH_ANONYMOUS_ENABLED
            value: "true"
          - name: GF_AUTH_ANONYMOUS_ORG_ROLE
            value: Admin
          {{- end }}
          volumeMounts:
          - name: grafana
            mountPath: /var/lib/grafana
          - name: dashboards
            mountPath: /etc/grafana/dashboards
          - name: datasources
            mountPath: /etc/grafana/provisioning/datasources
          - name: providers
            mountPath: /etc/grafana/provisioning/dashboards
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
      volumes:
      - name: grafana
        emptyDir: {}
      - name: dashboards
        configMap:
          name: {{ template "grafana.fullname" . }}-dashboards
      - name: providers
        configMap:
          name: {{ template "grafana.fullname" . }}-providers
      - name: datasources
        configMap:
          name: {{ template "grafana.fullname" . }}-datasources
