apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "cstor.fullname" . }}-cvc-operator
  {{- with .Values.cvcOperator.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
  labels:
    {{- include "cstor.cvcOperator.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "cstor.cvcOperator.matchLabels" . | nindent 6 }}
  replicas: {{ .Values.cvcOperator.replicas }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        {{- include "cstor.cvcOperator.labels" . | nindent 8 }}
        {{- if .Values.cvcOperator.podLabels }}
        {{ toYaml .Values.cvcOperator.podLabels | nindent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ .Values.serviceAccount.cstorOperator.name }}
      containers:
        - name: {{ template "cstor.fullname" . }}-cvc-operator
          imagePullPolicy: {{ .Values.cvcOperator.image.pullPolicy }}
          image: "{{ .Values.cvcOperator.image.registry }}{{ .Values.cvcOperator.image.repository }}:{{ .Values.cvcOperator.image.tag }}"
          args:
            - "--v={{ .Values.cvcOperator.logLevel }}"
            - "--leader-election=false"
            - "--bind=$(OPENEBS_CVC_POD_IP)"
          resources:
{{ toYaml .Values.cvcOperator.resources | indent 12 }}
          env:
{{- if .Values.cvcOperator.baseDir }}
            # OPENEBS_IO_BASE_DIR is used to configure base directory for openebs on host path.
            # Where OpenEBS can store required files. Default base path will be /var/openebs
            - name: OPENEBS_IO_BASE_DIR
              value: "{{ .Values.cvcOperator.baseDir }}"
{{- end }}
            - name: OPENEBS_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: OPENEBS_SERVICEACCOUNT_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.serviceAccountName
            - name: OPENEBS_CVC_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: OPENEBS_IO_CSTOR_TARGET_IMAGE
              value: "{{ .Values.cvcOperator.target.image.registry }}{{ .Values.cvcOperator.target.image.repository }}:{{ .Values.cvcOperator.target.image.tag }}"
            - name:  OPENEBS_IO_CSTOR_VOLUME_MGMT_IMAGE
              value: "{{ .Values.cvcOperator.volumeMgmt.image.registry }}{{ .Values.cvcOperator.volumeMgmt.image.repository }}:{{ .Values.cvcOperator.volumeMgmt.image.tag }}"
            - name:  OPENEBS_IO_VOLUME_MONITOR_IMAGE
              value: "{{ .Values.cvcOperator.volumeExporter.image.registry }}{{ .Values.cvcOperator.volumeExporter.image.repository }}:{{ .Values.cvcOperator.volumeExporter.image.tag }}"
{{- if .Values.imagePullSecrets }}
            - name: OPENEBS_IO_IMAGE_PULL_SECRETS
              value: "{{- range $.Values.imagePullSecrets }}{{ .name }},{{- end }}"
{{- end }}
{{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 2 }}
{{- end }}
{{- if .Values.cvcOperator.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.cvcOperator.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.cvcOperator.securityContext }}
      securityContext:
{{ toYaml .Values.cvcOperator.securityContext | indent 8 }}
{{- end }}
{{- if .Values.cvcOperator.tolerations }}
      tolerations:
{{ toYaml .Values.cvcOperator.tolerations | indent 8 }}
{{- end }}
