# grafana_charts_overrides-exporter-dep.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    {{- toYaml .Values.overrides_exporter.annotations | nindent 4 }}
  labels:
    app: {{ template "enterprise-metrics.name" . }}-overrides-exporter
    chart: {{ template "enterprise-metrics.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  name: {{ template "enterprise-metrics.fullname" . }}-overrides-exporter
spec:
  replicas: {{ .Values.overrides_exporter.replicas }}
  selector:
    matchLabels:
      app: {{ template "enterprise-metrics.name" . }}-overrides-exporter
      release: {{ .Release.Name }}
  strategy:
    {{- toYaml .Values.overrides_exporter.strategy | nindent 4 }}
  template:
    metadata:
      labels:
        app: {{ template "enterprise-metrics.name" . }}-overrides-exporter
        # The name label is important for cortex-mixin compatibility which expects certain names for services.
        name: overrides-exporter
        gossip_ring_member: "true"
        target: overrides-exporter
        release: {{ .Release.Name }}
        {{- with .Values.overrides_exporter.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      annotations:
        {{- if .Values.useExternalConfig }}
        checksum/config: {{ .Values.externalConfigVersion }}
        {{- else }}
        checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
        {{- end}}
        {{- with .Values.overrides_exporter.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ template "enterprise-metrics.serviceAccountName" . }}
      {{- if .Values.overrides_exporter.priorityClassName }}
      priorityClassName: {{ .Values.overrides_exporter.priorityClassName }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.overrides_exporter.securityContext | nindent 8 }}
      {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}
      {{- end }}
      {{- end }}
      {{- with .Values.overrides_exporter.hostAliases }}
      hostAliases:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      initContainers:
        {{- toYaml .Values.overrides_exporter.initContainers | nindent 8 }}
      containers:
        - name: overrides-exporter
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            - "-target=overrides-exporter"
            - "-config.file=/etc/enterprise-metrics/enterprise-metrics.yaml"
            {{- if .Values.minio.enabled }}
            - -admin.client.backend-type=s3
            - -admin.client.s3.endpoint={{ .Release.Name }}-minio.{{ .Release.Namespace }}.svc:9000
            - -admin.client.s3.bucket-name=enterprise-metrics-admin
            - -admin.client.s3.access-key-id=enterprise-metrics
            - -admin.client.s3.secret-access-key=supersecret
            - -admin.client.s3.insecure=true
            {{- end }}
            {{- range $key, $value := .Values.overrides_exporter.extraArgs }}
            - "-{{ $key }}={{ $value }}"
            {{- end }}
          volumeMounts:
            {{- if .Values.overrides_exporter.extraVolumeMounts }}
              {{ toYaml .Values.overrides_exporter.extraVolumeMounts | nindent 12}}
            {{- end }}
            - name: config
              mountPath: /etc/enterprise-metrics
            - name: runtime-config
              mountPath: /var/enterprise-metrics
            - name: license
              mountPath: /license
            - name: storage
              mountPath: "/data"
              subPath: {{ .Values.overrides_exporter.persistence.subPath }}
          ports:
            - name: http-metrics
              containerPort: {{ .Values.config.server.http_listen_port }}
              protocol: TCP
            - name: grpc
              containerPort: {{ .Values.config.server.grpc_listen_port }}
              protocol: TCP
          livenessProbe:
            {{- toYaml .Values.overrides_exporter.livenessProbe | nindent 12 }}
          readinessProbe:
            {{- toYaml .Values.overrides_exporter.readinessProbe | nindent 12 }}
          resources:
            {{- toYaml .Values.overrides_exporter.resources | nindent 12 }}
          securityContext:
            readOnlyRootFilesystem: true
          env:
            {{- if .Values.overrides_exporter.env }}
            {{ toYaml .Values.overrides_exporter.env | nindent 12 }}
            {{- end }}
        {{- with .Values.overrides_exporter.extraContainers }}
        {{ toYaml . | nindent 8 }}
        {{- end }}
      nodeSelector:
        {{- toYaml .Values.overrides_exporter.nodeSelector | nindent 8 }}
      affinity:
        {{- toYaml .Values.overrides_exporter.affinity | nindent 8 }}
      tolerations:
        {{- toYaml .Values.overrides_exporter.tolerations | nindent 8 }}
      terminationGracePeriodSeconds: {{ .Values.overrides_exporter.terminationGracePeriodSeconds }}
      volumes:
        - name: config
          secret:
          {{- if .Values.useExternalConfig }}
            secretName: {{ .Values.externalConfigSecretName }}
          {{- else }}
            secretName: {{ template "enterprise-metrics.fullname" . }}
          {{- end }}
        - name: runtime-config
          configMap:
            name: {{ template "enterprise-metrics.fullname" . }}-runtime
        {{- if .Values.overrides_exporter.extraVolumes }}
        {{ toYaml .Values.overrides_exporter.extraVolumes | nindent 8}}
        {{- end }}
        - name: license
          secret:
            secretName: {{ .Values.license.secretName }}
        - name: storage
          emptyDir: {}
        {{- if .Values.minio.enabled }}
        - name: minio-configuration
          projected:
            sources:
            - configMap:
                name: {{ .Release.Name }}-minio
            - secret:
                name: {{ .Release.Name }}-minio
        {{- if .Values.minio.tls.enabled }}
        - name: cert-secret-volume-mc
          secret:
            secretName: {{ .Values.minio.tls.certSecret }}
            items:
            - key: {{ .Values.minio.tls.publicCrt }}
              path: CAs/public.crt
        {{- end }}
        {{- end }}