apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: multicluster-observability-grafana
    observability.open-cluster-management.io/name: "{{MULTICLUSTEROBSERVABILITY_CR_NAME}}"
  name: grafana
  namespace: open-cluster-management-observability
spec:
  replicas: 2
  selector:
    matchLabels:
      app: multicluster-observability-grafana
      observability.open-cluster-management.io/name: "{{MULTICLUSTEROBSERVABILITY_CR_NAME}}"
  template:
    metadata:
      labels:
        app: multicluster-observability-grafana
        observability.open-cluster-management.io/name: "{{MULTICLUSTEROBSERVABILITY_CR_NAME}}"
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 70
            podAffinityTerm:
              topologyKey: topology.kubernetes.io/zone
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - multicluster-observability-grafana
          - weight: 30
            podAffinityTerm:
              topologyKey: kubernetes.io/hostname
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - multicluster-observability-grafana
      containers:
      - args:
        - -config=/etc/grafana/grafana.ini
        image: quay.io/stolostron/grafana:2.4.0-SNAPSHOT-2021-09-23-07-02-14
        imagePullPolicy: IfNotPresent
        name: grafana
        ports:
        - containerPort: 3001
          name: http
          protocol: TCP
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 4m
            memory: 100Mi
        volumeMounts:
        - mountPath: /var/lib/grafana
          name: grafana-storage
        - mountPath: /etc/grafana/provisioning/datasources
          name: grafana-datasources
        - mountPath: /etc/grafana
          name: grafana-config
      - name: grafana-dashboard-loader
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: quay.io/stolostron/grafana-dashboard-loader:2.3.0-SNAPSHOT-2021-07-26-18-43-26
        imagePullPolicy: IfNotPresent
        resources:
          requests:
            cpu: 4m
            memory: 50Mi  
      serviceAccount: grafana
      imagePullSecrets:
      - name: multiclusterhub-operator-pull-secret
      serviceAccountName: grafana
      volumes:
      - emptyDir: {}
        name: grafana-storage
      - name: grafana-datasources
        secret:
          defaultMode: 420
          secretName: grafana-datasources
      - name: grafana-config
        secret:
          defaultMode: 420
          secretName: grafana-config
