{{ if .Values.enabledComponents.dgxcAdmissionController }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "dgxcController.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "dgxcController.name" . }}
    helm.sh/chart: {{ include "dgxcController.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.dgxcController.replicas | required ".Values.dgxcController.replicas required" }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "dgxcController.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: {{ .Values.dgxcController.name }}
        app.kubernetes.io/name: {{ include "dgxcController.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        nvidia.com/dgx-application-deploy: {{ include "dgx-application-deploy" . }}
        {{- with .Values.extraPodLabels }}
        {{ toYaml . }}
        {{- end }}
      {{- with .Values.podAnnotations }}
      annotations:
        {{ toYaml . }}
      {{- end }}
    spec:
      serviceAccountName: {{ .Values.serviceAccount.name }}
      imagePullSecrets:
        - name: {{ .Values.imagePullSecret | required ".Values.imagePullSecret" }}
      initContainers:
        - name: init
          image: {{ .Values.dgxcController.image | required ".Values.dgxcController.image is required." | quote }}
          args: [ "admission-init", "--config", "/etc/{{ .Values.dgxcController.name}}/config.yaml", "--zap-log-level=debug" ]
          imagePullPolicy: Always
          volumeMounts:
            - name: {{ .Values.dgxcController.name}}-config
              mountPath: /etc/{{ .Values.dgxcController.name}}/
              readOnly: true
            - name: {{ .Values.dgxcController.name}}-certs
              mountPath: {{ .Values.dgxcController.certs.mountPath }}
      containers:
        - name: controller
          image: {{ .Values.dgxcController.image | required "dgxcController.image is required." | quote }}
          args: ["admission", "--config", "/etc/{{ .Values.dgxcController.name}}/config.yaml", "--zap-log-level=debug"]
          imagePullPolicy: Always
          ports: []
          volumeMounts:
            - name: {{ .Values.dgxcController.name}}-certs
              mountPath: {{ .Values.dgxcController.certs.mountPath }}
              readOnly: true
            - name: {{ .Values.dgxcController.name}}-config
              mountPath: /etc/{{ .Values.dgxcController.name}}/
              readOnly: true
{{/*        - name: app-share-ns*/}}
{{/*          command:*/}}
{{/*            - sleep*/}}
{{/*            - infinity*/}}
{{/*          image: nvcr.io/nvidian/nsvis-corestorage/ubuntu:latest*/}}
{{/*          imagePullPolicy: IfNotPresent*/}}
{{/*          terminationMessagePath: /dev/termination-log*/}}
{{/*          terminationMessagePolicy: File*/}}
{{/*          volumeMounts:*/}}
{{/*            - name: {{ .Values.dgxcController.name}}-certs*/}}
{{/*              mountPath: {{ .Values.dgxcController.certs.mountPath }}*/}}
{{/*              readOnly: true*/}}
{{/*            - name: {{ .Values.dgxcController.name}}-config*/}}
{{/*              mountPath: /etc/{{ .Values.dgxcController.name}}-/*/}}
{{/*              readOnly: true*/}}
      {{ if .Values.kubernetesAffinity.enabled }}
      {{- include "kubernetesAffinityConfig" . | nindent 6 }}
      {{ end }}
      tolerations:
      - effect: NoSchedule
        key: "{{ .Values.systemTolerationKeyName }}"
        operator: Equal
        value: "{{ .Values.systemTolerationValueName }}"
      - effect: NoExecute
        key: "{{ .Values.systemTolerationKeyName }}"
        operator: Equal
        value: "{{ .Values.systemTolerationValueName }}"
      volumes:
        - name: {{ .Values.dgxcController.name}}-certs
          emptyDir: {}
        - name: {{ .Values.dgxcController.name}}-config
          configMap:
            name: {{ .Values.dgxcController.name}}-config
{{ end }}
