{{- if .Values.ndmOperator.enabled }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "openebs-ndm.operator.fullname" . }}
  {{- with .Values.ndmOperator.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
  labels:
    {{- include "openebs-ndm.operator.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.ndmOperator.replicas }}
  strategy:
    type: "Recreate"
    rollingUpdate: null
  selector:
    matchLabels:
      {{- include "openebs-ndm.operator.matchLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.ndmOperator.podAnnotations }}
      annotations: {{ toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "openebs-ndm.operator.labels" . | nindent 8 }}
        {{- with .Values.ndmOperator.podLabels}}
        {{ toYaml . }}
        {{- end}}
    spec:
      serviceAccountName: {{ template "openebs-ndm.serviceAccountName" . }}
      containers:
      - name: {{ template "openebs-ndm.operator.fullname" . }}
        image: "{{ .Values.ndmOperator.image.registry }}{{ .Values.ndmOperator.image.repository }}:{{ .Values.ndmOperator.image.tag }}"
        imagePullPolicy: {{ .Values.ndmOperator.image.pullPolicy }}
        resources:
{{ toYaml .Values.ndmOperator.resources | indent 12 }}
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8585
          initialDelaySeconds: {{ .Values.ndmOperator.healthCheck.initialDelaySeconds }}
          periodSeconds: {{ .Values.ndmOperator.healthCheck.periodSeconds }}
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8585
          initialDelaySeconds: {{ .Values.ndmOperator.readinessCheck.initialDelaySeconds }}
          periodSeconds: {{ .Values.ndmOperator.readinessCheck.periodSeconds }}
        env:
        - name: WATCH_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: SERVICE_ACCOUNT
          valueFrom:
            fieldRef:
              fieldPath: spec.serviceAccountName
        - name: OPERATOR_NAME
          value: "node-disk-operator"
        - name: CLEANUP_JOB_IMAGE
          value: "{{ .Values.helperPod.image.registry }}{{ .Values.helperPod.image.repository }}:{{ .Values.helperPod.image.tag }}"
{{- if .Values.imagePullSecrets }}
        - name: OPENEBS_IO_IMAGE_PULL_SECRETS
          value: "{{- range $index, $secret := .Values.imagePullSecrets}}{{if $index}},{{end}}{{ $secret.name }}{{- end}}"
{{- end }}
{{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
{{- end }}
{{- if .Values.ndmOperator.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.ndmOperator.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.ndmOperator.securityContext }}
      securityContext:
{{ toYaml .Values.ndmOperator.securityContext | indent 8 }}
{{- end }}
{{- if .Values.ndmOperator.tolerations }}
      tolerations:
{{ toYaml .Values.ndmOperator.tolerations | indent 8 }}
{{- end }}
{{- end }}
