{{- if .Values.metrics.enabled }}
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
  name: {{ include "scdf.fullname" . }}-prometheus-proxy
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: prometheus-proxy
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  namespace: {{ .Release.Namespace }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  replicas: {{ .Values.metrics.replicaCount }}
  {{- if .Values.metrics.updateStrategy }}
  strategy: {{- toYaml .Values.metrics.updateStrategy | nindent 4 }}
  {{- end }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: prometheus-proxy
  template:
    metadata:
      {{- if .Values.metrics.podAnnotations }}
      annotations: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.podAnnotations "context" $) | nindent 8 }}
      {{- end }}
      labels: {{- include "common.labels.standard" . | nindent 8 }}
        app.kubernetes.io/component: prometheus-proxy
        {{- if .Values.metrics.podLabels }}
        {{- include "common.tplvalues.render" (dict "value" .Values.metrics.podLabels "context" $) | nindent 8 }}
        {{- end }}
    spec:
      {{- include "scdf.imagePullSecrets" . | nindent 6 }}
      serviceAccountName: {{ include "scdf.serviceAccountName" . }}
      {{- if .Values.metrics.hostAliases }}
      hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.hostAliases "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.metrics.affinity }}
      affinity: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.affinity "context" $) | nindent 8 }}
      {{- else }}
      affinity:
        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.metrics.podAffinityPreset "component" "prometheus-proxy" "context" $) | nindent 10 }}
        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.metrics.podAntiAffinityPreset "component" "prometheus-proxy" "context" $) | nindent 10 }}
        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.metrics.nodeAffinityPreset.type "key" .Values.metrics.nodeAffinityPreset.key "values" .Values.metrics.nodeAffinityPreset.values) | nindent 10 }}
      {{- end }}
      {{- if .Values.metrics.nodeSelector }}
      nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.metrics.tolerations }}
      tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.metrics.schedulerName }}
      schedulerName: {{ .Values.metrics.schedulerName }}
      {{- end }}
      {{- if .Values.metrics.topologySpreadConstraints }}
      topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.topologySpreadConstraints "context" .) | nindent 8 }}
      {{- end }}
      {{- if .Values.metrics.priorityClassName }}
      priorityClassName: {{ .Values.metrics.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.metrics.initContainers }}
        initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.initContainers "context" $) | trim | nindent 8 }}
      {{- end }}
      containers:
        - name: prometheus-proxy
          image: {{ include "scdf.metrics.image" . }}
          imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
          {{- if .Values.metrics.containerSecurityContext.enabled }}
          securityContext: {{- omit .Values.metrics.containerSecurityContext "enabled" | toYaml | nindent 12 }}
          {{- end }}
          {{- if .Values.metrics.command }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.command "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.metrics.args }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.args "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.metrics.lifecycleHooks }}
          lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.lifecycleHooks "context" $) | nindent 12 }}
          {{- end }}
          env:
            {{- if .Values.metrics.extraEnvVars }}
              {{- include "common.tplvalues.render" (dict "value" .Values.metrics.extraEnvVars "context" $) | nindent 12 }}
            {{- end }}
          envFrom:
            {{- if .Values.metrics.extraEnvVarsCM }}
            - configMapRef:
                name: {{ .Values.metrics.extraEnvVarsCM }}
            {{- end }}
            {{- if .Values.metrics.extraEnvVarsSecret }}
            - secretRef:
                name: {{ .Values.metrics.extraEnvVarsSecret }}
            {{- end }}
          ports:
            - name: http
              containerPort: {{ .Values.metrics.containerPorts.http }}
              protocol: TCP
            - name: rsocket
              containerPort: {{ .Values.metrics.containerPorts.rsocket }}
              protocol: TCP
          {{- if .Values.metrics.extraVolumeMounts }}
          volumeMounts: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.extraVolumeMounts "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.metrics.resources }}
          resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
          {{- end }}
      {{- if .Values.metrics.sidecars }}
        {{- include "common.tplvalues.render" (dict "value" .Values.metrics.sidecars "context" $) | trim | nindent 8 }}
      {{- end }}
      {{- if .Values.metrics.extraVolumes }}
      volumes: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.extraVolumes "context" $) | nindent 8 }}
      {{- end }}
{{- end }}
