apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 60

      securityContext:
        runAsUser: 472
        fsGroup: 472

      containers:
        - name: grafana
          # 7.3.4
          image: grafana/grafana@sha256:6d42886b3ebe286b92eca592e1251b5dc128e611678ccffbefb5701bbf7ef186
          imagePullPolicy: IfNotPresent

          envFrom:
            - configMapRef:
                name: grafana
            - secretRef:
                name: grafana
          # env:
          #   - name: ELASTICSEARCH_PASSWORD
          #     valueFrom:
          #         secretKeyRef:
          #           name: logging-es-elastic-user
          #           key: elastic
          
          ports:
            - containerPort: 3000
              name: http-ui
          
          resources:
            requests:
              cpu: 1
              memory: 1G
            limits:
              cpu: 2
              memory: 2G
          
          livenessProbe:
            httpGet:
              path: /api/health
              port: http-ui
            initialDelaySeconds: 15
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /api/health
              port: http-ui
            initialDelaySeconds: 15
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3

          volumeMounts:

            # storage
            # - mountPath: /var/lib/grafana
            #   name: data-grafana
            - mountPath: /tmp
              name: tmp-grafana

            # provisioning
            
            ## datasources
            - mountPath: /etc/grafana/provisioning/datasources
              name: grafana-datasources
            
            ## dashboards
            - mountPath: /etc/grafana/provisioning/dashboards
              name: grafana-dashboards
            
            # dashboards
            ## kubernetes
            ### networking
            # - mountPath: /etc/dashboards/kubernetes/k8s-networking-cluster.json
            #   subPath: k8s-networking-cluster.json
            #   name: grafana-dashboard-k8s-networking-cluster
            # - mountPath: /etc/dashboards/kubernetes/k8s-networking-kube-dns.json
            #   subPath: k8s-networking-kube-dns.json
            #   name: grafana-dashboard-k8s-networking-kube-dns
            # - mountPath: /etc/dashboards/kubernetes/k8s-networking-namespace-by-pod.json
            #   subPath: k8s-networking-namespace-by-pod.json
            #   name: grafana-dashboard-k8s-networking-namespace-by-pod
            # - mountPath: /etc/dashboards/kubernetes/k8s-networking-namespace-by-workload.json
            #   subPath: k8s-networking-namespace-by-workload.json
            #   name: grafana-dashboard-k8s-networking-namespace-by-workload
            # - mountPath: /etc/dashboards/kubernetes/k8s-networking-pod.json
            #   subPath: k8s-networking-pod.json
            #   name: grafana-dashboard-k8s-networking-pod
            # - mountPath: /etc/dashboards/kubernetes/k8s-networking-workload.json
            #   subPath: k8s-networking-workload.json
            #   name: grafana-dashboard-k8s-networking-workload
            ### resources
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-cluster-details.json
            #   subPath: k8s-resources-cluster-details.json
            #   name: grafana-dashboard-k8s-resources-cluster-details
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-cluster-summary.json
            #   subPath: k8s-resources-cluster-summary.json
            #   name: grafana-dashboard-k8s-resources-cluster-summary
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-cluster-use.json
            #   subPath: k8s-resources-cluster-use.json
            #   name: grafana-dashboard-k8s-resources-cluster-use
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-namespace-by-pod.json
            #   subPath: k8s-resources-namespace-by-pod.json
            #   name: grafana-dashboard-k8s-resources-namespace-by-pod
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-namespace-by-workload.json
            #   subPath: k8s-resources-namespace-by-workload.json
            #   name: grafana-dashboard-k8s-resources-namespace-by-workload
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-node-by-pod.json
            #   subPath: k8s-resources-node-by-pod.json
            #   name: grafana-dashboard-k8s-resources-node-by-pod
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-node-use.json
            #   subPath: k8s-resources-node-use.json
            #   name: grafana-dashboard-k8s-resources-node-use
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-node.json
            #   subPath: k8s-resources-node.json
            #   name: grafana-dashboard-k8s-resources-node
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-persistent-volumes.json
            #   subPath: k8s-resources-persistent-volumes.json
            #   name: grafana-dashboard-k8s-resources-persistent-volumes
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-pod-details.json
            #   subPath: k8s-resources-pod-details.json
            #   name: grafana-dashboard-k8s-resources-pod-details
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-pod-summary.json
            #   subPath: k8s-resources-pod-summary.json
            #   name: grafana-dashboard-k8s-resources-pod-summary
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-statefulset.json
            #   subPath: k8s-resources-statefulset.json
            #   name: grafana-dashboard-k8s-resources-statefulset
            # - mountPath: /etc/dashboards/kubernetes/k8s-resources-workload.json
            #   subPath: k8s-resources-workload.json
            #   name: grafana-dashboard-k8s-resources-workload
            ### system
            # - mountPath: /etc/dashboards/kubernetes/k8s-system-api-server.json
            #   subPath: k8s-system-api-server.json
            #   name: grafana-dashboard-k8s-system-api-server
            # - mountPath: /etc/dashboards/kubernetes/k8s-system-controller-manager.json
            #   subPath: k8s-system-controller-manager.json
            #   name: grafana-dashboard-k8s-system-controller-manager
            # - mountPath: /etc/dashboards/kubernetes/k8s-system-kubelet.json
            #   subPath: k8s-system-kubelet.json
            #   name: grafana-dashboard-k8s-system-kubelet
            # - mountPath: /etc/dashboards/kubernetes/k8s-system-kube-proxy.json
            #   subPath: k8s-system-kube-proxy.json
            #   name: grafana-dashboard-k8s-system-kube-proxy
            # - mountPath: /etc/dashboards/kubernetes/k8s-system-scheduler.json
            #   subPath: k8s-system-scheduler.json
            #   name: grafana-dashboard-k8s-system-scheduler
            ## monitoring
            - mountPath: /etc/dashboards/monitoring/grafana.json
              subPath: grafana.json
              name: grafana-dashboard-grafana-self
            - mountPath: /etc/dashboards/monitoring/prometheus.json
              subPath: prometheus.json
              name: grafana-dashboard-prometheus
            ## databases
            - mountPath: /etc/dashboards/databases/postgresql.json
              subPath: postgresql.json
              name: grafana-dashboard-postgresql
            ## brokers
            - mountPath: /etc/dashboards/brokers/strimzi-kafka-exporter.json
              subPath: strimzi-kafka-exporter.json
              name: grafana-dashboard-strimzi-kafka-exporter
            - mountPath: /etc/dashboards/brokers/strimzi-kafka.json
              subPath: strimzi-kafka.json
              name: grafana-dashboard-strimzi-kafka
            - mountPath: /etc/dashboards/brokers/strimzi-operators.json
              subPath: strimzi-operators.json
              name: grafana-dashboard-strimzi-operators
            - mountPath: /etc/dashboards/brokers/strimzi-zookeeper.json
              subPath: strimzi-zookeeper.json
              name: grafana-dashboard-strimzi-zookeeper
            ## services
            - mountPath: /etc/dashboards/services/go-services.json
              subPath: go-services.json
              name: grafana-dashboard-go-services
            - mountPath: /etc/dashboards/services/global-status.json
              subPath: global-status.json
              name: grafana-dashboard-global-status
            ## ci-cd
            - mountPath: /etc/dashboards/cicd/argo-cd.json
              subPath: argo-cd.json
              name: grafana-dashboard-argo-cd
            - mountPath: /etc/dashboards/cicd/argo-cd-notifications.json
              subPath: argo-cd-notifications.json
              name: grafana-dashboard-argo-cd-notifications

      volumes:
        # storage
        # - persistentVolumeClaim:
        #     claimName: data-grafana
        #   name: data-grafana
        - emptyDir: {}
          name: tmp-grafana

        # provisioning

        ## datasources
        - configMap:
            name: grafana-datasources
          name: grafana-datasources
        
        ## dashboards
        - configMap:
            name: grafana-dashboards
          name: grafana-dashboards
        
        # dashboards
        ## kubernetes
        ### networking
        # - configMap:
        #     name: grafana-dashboard-k8s-networking-cluster
        #   name: grafana-dashboard-k8s-networking-cluster
        # - configMap:
        #     name: grafana-dashboard-k8s-networking-kube-dns
        #   name: grafana-dashboard-k8s-networking-kube-dns
        # - configMap:
        #     name: grafana-dashboard-k8s-networking-namespace-by-pod
        #   name: grafana-dashboard-k8s-networking-namespace-by-pod
        # - configMap:
        #     name: grafana-dashboard-k8s-networking-namespace-by-workload
        #   name: grafana-dashboard-k8s-networking-namespace-by-workload
        # - configMap:
        #     name: grafana-dashboard-k8s-networking-pod
        #   name: grafana-dashboard-k8s-networking-pod
        # - configMap:
        #     name: grafana-dashboard-k8s-networking-workload
        #   name: grafana-dashboard-k8s-networking-workload
        ### resources
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-cluster-details
        #   name: grafana-dashboard-k8s-resources-cluster-details
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-cluster-summary
        #   name: grafana-dashboard-k8s-resources-cluster-summary
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-cluster-use
        #   name: grafana-dashboard-k8s-resources-cluster-use
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-namespace-by-pod
        #   name: grafana-dashboard-k8s-resources-namespace-by-pod
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-namespace-by-workload
        #   name: grafana-dashboard-k8s-resources-namespace-by-workload
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-node-by-pod
        #   name: grafana-dashboard-k8s-resources-node-by-pod
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-node-use
        #   name: grafana-dashboard-k8s-resources-node-use
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-node
        #   name: grafana-dashboard-k8s-resources-node
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-persistent-volumes
        #   name: grafana-dashboard-k8s-resources-persistent-volumes
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-pod-details
        #   name: grafana-dashboard-k8s-resources-pod-details
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-pod-summary
        #   name: grafana-dashboard-k8s-resources-pod-summary
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-statefulset
        #   name: grafana-dashboard-k8s-resources-statefulset
        # - configMap:
        #     name: grafana-dashboard-k8s-resources-workload
        #   name: grafana-dashboard-k8s-resources-workload
        ### system
        # - configMap:
        #     name: grafana-dashboard-k8s-system-api-server
        #   name: grafana-dashboard-k8s-system-api-server
        # - configMap:
        #     name: grafana-dashboard-k8s-system-controller-manager
        #   name: grafana-dashboard-k8s-system-controller-manager
        # - configMap:
        #     name: grafana-dashboard-k8s-system-kubelet
        #   name: grafana-dashboard-k8s-system-kubelet
        # - configMap:
        #     name: grafana-dashboard-k8s-system-kube-proxy
        #   name: grafana-dashboard-k8s-system-kube-proxy
        # - configMap:
        #     name: grafana-dashboard-k8s-system-scheduler
        #   name: grafana-dashboard-k8s-system-scheduler
        ## monitoring
        - configMap:
            name: grafana-dashboard-grafana-self
          name: grafana-dashboard-grafana-self
        - configMap:
            name: grafana-dashboard-prometheus
          name: grafana-dashboard-prometheus
        ## databases
        - configMap:
            name: grafana-dashboard-postgresql
          name: grafana-dashboard-postgresql
        ## brokers
        - configMap:
            name: grafana-dashboard-strimzi-kafka-exporter
          name: grafana-dashboard-strimzi-kafka-exporter
        - configMap:
            name: grafana-dashboard-strimzi-kafka
          name: grafana-dashboard-strimzi-kafka
        - configMap:
            name: grafana-dashboard-strimzi-operators
          name: grafana-dashboard-strimzi-operators
        - configMap:
            name: grafana-dashboard-strimzi-zookeeper
          name: grafana-dashboard-strimzi-zookeeper
        ## services
        - configMap:
            name: grafana-dashboard-go-services
          name: grafana-dashboard-go-services
        - configMap:
            name: grafana-dashboard-global-status
          name: grafana-dashboard-global-status
        ## ci-cd
        - configMap:
            name: grafana-dashboard-argo-cd
          name: grafana-dashboard-argo-cd
        - configMap:
            name: grafana-dashboard-argo-cd-notifications
          name: grafana-dashboard-argo-cd-notifications
