{{- if eq .Values.global.grafanaLocation "on-cluster" }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: drycc-monitor-grafana
  labels:
    heritage: drycc
  annotations:
    component.drycc.cc/version: {{ .Values.grafana.imageTag }}
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  selector:
    matchLabels:
      app: drycc-monitor-grafana
  template:
    metadata:
      labels:
        app: drycc-monitor-grafana
    spec:
      securityContext:
        fsGroup: 1001
        runAsGroup: 1001
        runAsUser: 1001
      containers:
      - name: drycc-monitor-grafana
        image: {{.Values.grafana.imageRegistry}}/{{.Values.grafana.imageOrg}}/grafana:{{.Values.grafana.imageTag}}
        imagePullPolicy: {{.Values.grafana.imagePullPolicy}}
        {{- if or (.Values.grafana.limitsCpu) (.Values.grafana.limitsMemory)}}
        resources:
          limits:
            {{- if (.Values.grafana.limitsCpu) }}
            cpu: {{.Values.grafana.limitsCpu}}
            {{- end}}
            {{- if (.Values.grafana.limitsMemory) }}
            memory: {{.Values.grafana.limitsMemory}}
            {{- end}}
        {{- end}}
        ports:
        - containerPort: 3000
          name: ui
        {{- include "grafana.envs" . | indent 8 }}
      {{- if .Values.grafana.persistence.enabled }}
        volumeMounts:
        - name: grafana-data
          mountPath: /var/lib/grafana
      volumes:
      - name: grafana-data
        persistentVolumeClaim:
          claimName: drycc-monitor-grafana
      {{- end }}
{{- end }}
