{{- if .Values.updater.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  {{- if .Values.updater.annotations }}
  annotations:
  {{- .Values.updater.annotations | toYaml | nindent 4 }}
  {{- end }}
  name: {{ include "vpa.fullname" . }}-updater
  labels:
    app.kubernetes.io/component: updater
    {{- include "vpa.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.updater.replicaCount }}
  {{- if .Values.updater.revisionHistoryLimit }}
  revisionHistoryLimit: {{ .Values.updater.revisionHistoryLimit }}
  {{- end }}
  selector:
    matchLabels:
      app.kubernetes.io/component: updater
      {{- include "vpa.selectorLabels" . | nindent 6 }}
  template:
    metadata:
    {{- with .Values.updater.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      labels:
      {{- with .Values.updater.podLabels }}
          {{- toYaml . | nindent 8 }}
      {{- end }}
        app.kubernetes.io/component: updater
        {{- include "vpa.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.priorityClassName }}
      priorityClassName: {{ . }}
      {{- end }}
      serviceAccountName: {{ include "vpa.serviceAccountName" . }}-updater
      securityContext:
        {{- toYaml .Values.updater.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.updater.securityContext | nindent 12 }}
          image: {{ printf "%s:%s" .Values.updater.image.repository (.Values.updater.image.tag | default .Chart.AppVersion) }}
          imagePullPolicy: {{ .Values.updater.image.pullPolicy }}
          {{- if .Values.updater.extraArgs }}
          args:
          {{- range $key, $value := .Values.updater.extraArgs }}
            - --{{ $key }}={{ $value }}
          {{- end }}
          {{- end }}
          env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          {{- if .Values.updater.livenessProbe }}
          livenessProbe:
            {{- toYaml .Values.updater.livenessProbe | nindent 12 }}
          {{- end }}
          {{- if .Values.updater.readinessProbe }}
          readinessProbe:
            {{- toYaml .Values.updater.readinessProbe | nindent 12 }}
          {{- end }}
          ports:
            - name: metrics
              containerPort: 8943
              protocol: TCP
          resources:
            {{- toYaml .Values.updater.resources | nindent 12 }}
      {{- with .Values.updater.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.updater.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.updater.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
