apiVersion: apps/v1
kind: Deployment
metadata:
  name: gpu-operator
  labels:
    {{- include "gpu-operator.labels" . | nindent 4 }}
    app.kubernetes.io/component: "gpu-operator"
    nvidia.com/gpu-driver-upgrade-drain.skip: "true"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/component: "gpu-operator"
      app: "gpu-operator"
  template:
    metadata:
      labels:
        {{- include "gpu-operator.labels" . | nindent 8 }}
        app.kubernetes.io/component: "gpu-operator"
        app: "gpu-operator"
        nvidia.com/gpu-driver-upgrade-drain.skip: "true"
      annotations:
        {{- toYaml .Values.operator.annotations | nindent 8 }}
    spec:
      serviceAccountName: gpu-operator
      {{- if .Values.operator.imagePullSecrets }}
      imagePullSecrets:
      {{- range .Values.operator.imagePullSecrets }}
        - name: {{ . }}
      {{- end }}
      {{- end }}
      {{- if .Values.operator.priorityClassName }}
      priorityClassName: {{ .Values.operator.priorityClassName }}
      {{- end }}
      containers:
      - name: gpu-operator
        image: {{ include "gpu-operator.fullimage" . }}
        imagePullPolicy: {{ .Values.operator.imagePullPolicy }}
        command: ["gpu-operator"]
        args:
        - --leader-elect
      {{- if .Values.operator.logging.develMode }}
        - --zap-devel
      {{- else }}
        {{- if .Values.operator.logging.timeEncoding }}
        - --zap-time-encoding={{- .Values.operator.logging.timeEncoding }}
        {{- end }}
        {{- if .Values.operator.logging.level }}
        - --zap-log-level={{- .Values.operator.logging.level }}
        {{- end }}
      {{- end }}
        env:
        - name: WATCH_NAMESPACE
          value: ""
        - name: OPERATOR_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: "DRIVER_MANAGER_IMAGE"
          value: "{{ include "driver-manager.fullimage" . }}"
        volumeMounts:
          - name: host-os-release
            mountPath: "/host-etc/os-release"
            readOnly: true
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8081
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8081
          initialDelaySeconds: 5
          periodSeconds: 10
      {{- with .Values.operator.resources }}
        resources:
          {{- toYaml . | nindent 10 }}
      {{- end }}
        ports:
          - name: metrics
            containerPort: 8080
      volumes:
        - name: host-os-release
          hostPath:
            path: "/etc/os-release"
    {{- with .Values.operator.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.operator.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.operator.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
