{{- if .Values.dataplatform.exporter.enabled }}
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: dataplatform-exporter
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  name: {{ include "dataplatform.exporter-name" . }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
  namespace: {{ .Release.Namespace | quote }}
spec:
  replicas: 1
  {{- if .Values.dataplatform.exporter.updateStrategy }}
  strategy: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.updateStrategy "context" $) | nindent 4 }}
  {{- end }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: dataplatform-exporter
  template:
    metadata:
      annotations:
        {{- if .Values.dataplatform.exporter.podAnnotations }}
        {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.podAnnotations "context" $) | nindent 8 }}
        {{- end }}
        {{- if .Values.commonAnnotations }}
        {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 8 }}
        {{- end }}
      labels: {{- include "common.labels.standard" . | nindent 8 }}
        app.kubernetes.io/component: dataplatform-exporter
        {{- if .Values.dataplatform.exporter.podLabels }}
        {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.podLabels "context" $) | nindent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ include "dataplatform.serviceAccountName" . }}
      {{- include "dataplatform.exporter.imagePullSecrets" . | nindent 6 }}
      {{- if .Values.dataplatform.exporter.hostAliases }}
      hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.hostAliases "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.dataplatform.exporter.affinity }}
      affinity: {{- include "common.tplvalues.render" ( dict "value" .Values.dataplatform.exporter.affinity "context" $) | nindent 8 }}
      {{- else }}
      affinity:
        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.dataplatform.exporter.podAffinityPreset "component" "dataplatform-exporter" "context" $) | nindent 10 }}
        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.dataplatform.exporter.podAntiAffinityPreset "component" "dataplatform-exporter" "context" $) | nindent 10 }}
        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.dataplatform.exporter.nodeAffinityPreset.type "key" .Values.dataplatform.exporter.nodeAffinityPreset.key "values" .Values.dataplatform.exporter.nodeAffinityPreset.values) | nindent 10 }}
      {{- end }}
      {{- if .Values.dataplatform.exporter.nodeSelector }}
      nodeSelector: {{- include "common.tplvalues.render" ( dict "value" .Values.dataplatform.exporter.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.dataplatform.exporter.tolerations }}
      tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.tolerations "context" .) | nindent 8 }}
      {{- end }}
      {{- if .Values.dataplatform.exporter.priorityClassName }}
      priorityClassName: {{ .Values.dataplatform.exporter.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.dataplatform.exporter.podSecurityContext.enabled }}
      securityContext: {{- omit .Values.dataplatform.exporter.podSecurityContext "enabled" | toYaml | nindent 8 }}
      {{- end }}
      initContainers:
        {{- if .Values.dataplatform.exporter.initContainers }}
          {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.initContainers "context" $) | nindent 8 }}
        {{- end }}
      containers:
        - name: dataplatform-exporter
          image: {{ include "dataplatform.exporter.image" . }}
          imagePullPolicy: {{ .Values.dataplatform.exporter.image.pullPolicy | quote }}
          {{- if .Values.dataplatform.exporter.containerSecurityContext.enabled }}
          securityContext: {{- omit .Values.dataplatform.exporter.containerSecurityContext "enabled" | toYaml | nindent 12 }}
          {{- end }}
          {{- if .Values.dataplatform.exporter.command }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.command "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.dataplatform.exporter.args }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.args "context" $) | nindent 12 }}
          {{- end }}
          env:
            - name: METRIC_CONFIG_PATH
              value: "/data/bp.json"
            - name: DP_URI
              value: http://{{ include "dataplatform.emitter-name" . }}:{{ .Values.dataplatform.emitter.service.ports.http }}
          {{- if or .Values.dataplatform.exporter.extraEnvVarsCM .Values.dataplatform.exporter.extraEnvVarsSecret }}
          envFrom:
            {{- if .Values.dataplatform.exporter.extraEnvVarsCM }}
            - configMapRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.extraEnvVarsCM "context" $) }}
            {{- end }}
            {{- if .Values.dataplatform.exporter.extraEnvVarsSecret }}
            - secretRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.extraEnvVarsSecret "context" $) }}
            {{- end }}
          {{- end }}
          ports:
            - name: exporter-port
              containerPort: {{ .Values.dataplatform.exporter.containerPorts.http }}
          {{- if .Values.dataplatform.exporter.resources }}
          resources: {{- toYaml .Values.dataplatform.exporter.resources | nindent 12 }}
          {{- end }}
          {{- if .Values.dataplatform.exporter.livenessProbe.enabled }}
          livenessProbe:
            httpGet:
              path: "/metrics"
              port: {{ .Values.dataplatform.exporter.containerPorts.http }}
            initialDelaySeconds: {{ .Values.dataplatform.exporter.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.dataplatform.exporter.livenessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.dataplatform.exporter.livenessProbe.timeoutSeconds }}
            failureThreshold: {{ .Values.dataplatform.exporter.livenessProbe.failureThreshold }}
            successThreshold: {{ .Values.dataplatform.exporter.livenessProbe.successThreshold }}
          {{- else if .Values.dataplatform.exporter.customLivenessProbe }}
          livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.customLivenessProbe "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.dataplatform.exporter.readinessProbe.enabled }}
          readinessProbe:
            httpGet:
              path: "/metrics"
              port: {{ .Values.dataplatform.exporter.containerPorts.http }}
            initialDelaySeconds: {{ .Values.dataplatform.exporter.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.dataplatform.exporter.readinessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.dataplatform.exporter.readinessProbe.timeoutSeconds }}
            failureThreshold: {{ .Values.dataplatform.exporter.readinessProbe.failureThreshold }}
            successThreshold: {{ .Values.dataplatform.exporter.readinessProbe.successThreshold }}
          {{- else if .Values.dataplatform.exporter.customReadinessProbe }}
          readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.customReadinessProbe "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.dataplatform.exporter.startupProbe.enabled }}
          startupProbe:
            httpGet:
              path: "/v1/health"
              port: {{ .Values.dataplatform.exporter.containerPorts.http }}
            initialDelaySeconds: {{ .Values.dataplatform.exporter.startupProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.dataplatform.exporter.startupProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.dataplatform.exporter.startupProbe.timeoutSeconds }}
            failureThreshold: {{ .Values.dataplatform.exporter.startupProbe.failureThreshold }}
            successThreshold: {{ .Values.dataplatform.exporter.startupProbe.successThreshold }}
          {{- else if .Values.dataplatform.exporter.customStartupProbe }}
          startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.customStartupProbe "context" $) | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: exporter-config
              mountPath: /data/bp.json
              subPath: bp.json
          {{- if .Values.dataplatform.exporter.extraVolumeMounts }}
          {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.extraVolumeMounts "context" $) | nindent 12 }}
          {{- end }}
        {{- if .Values.dataplatform.exporter.sidecars }}
        {{- include "common.tplvalues.render" ( dict "value" .Values.dataplatform.exporter.sidecars "context" $) | nindent 8 }}
        {{- end }}
      volumes:
        - name: exporter-config
          configMap:
            name: {{ include "dataplatform.exporter-name" . }}-configuration
        {{- if .Values.dataplatform.exporter.extraVolumes }}
        {{- include "common.tplvalues.render" (dict "value" .Values.dataplatform.exporter.extraVolumes "context" $) | nindent 8 }}
        {{- end }}
{{ end }}
