apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "cstor.fullname" . }}-cspc-operator
  {{- with .Values.cspcOperator.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
  labels:
    {{- include "cstor.cspcOperator.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "cstor.cspcOperator.matchLabels" . | nindent 6 }}
  replicas: {{ .Values.cspcOperator.replicas }}
  strategy:
    type: Recreate
  template:
    metadata:
      {{- with .Values.cspcOperator.podAnnotations }}
      annotations: {{ toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "cstor.cspcOperator.labels" . | nindent 8 }}
        {{- if .Values.cspcOperator.podLabels }}
        {{ toYaml .Values.cspcOperator.podLabels | nindent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ .Values.serviceAccount.cstorOperator.name }}
      containers:
        - name: {{ template "cstor.fullname" . }}-cspc-operator
          imagePullPolicy: {{ .Values.cspcOperator.image.pullPolicy }}
          image: "{{ .Values.cspcOperator.image.registry }}{{ .Values.cspcOperator.image.repository }}:{{ .Values.cspcOperator.image.tag }}"
          resources:
{{ toYaml .Values.cspcOperator.resources | indent 12 }}
          env:
            - name: OPENEBS_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: OPENEBS_SERVICEACCOUNT_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.serviceAccountName
            - name: CSPC_OPERATOR_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
{{- if .Values.cspcOperator.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.cspcOperator.baseDir | quote }}
{{- end }}
{{- if .Values.cspcOperator.sparseDir }}
            # OPENEBS_IO_CSTOR_POOL_SPARSE_DIR can be used to specify the hostpath
            # to be used for saving the shared content between the side cars
            # of cstor pool pod. This ENV is also used to indicate the location
            # of the sparse devices.
            # The default path used is /var/openebs/sparse
            - name: OPENEBS_IO_CSTOR_POOL_SPARSE_DIR
              value: "{{ .Values.cspcOperator.sparseDir }}"
{{- end }}
            - name: OPENEBS_IO_CSPI_MGMT_IMAGE
              value: "{{ .Values.cspcOperator.poolManager.image.registry }}{{ .Values.cspcOperator.poolManager.image.repository }}:{{ .Values.cspcOperator.poolManager.image.tag }}"
            - name: OPENEBS_IO_CSTOR_POOL_IMAGE
              value: "{{ .Values.cspcOperator.cstorPool.image.registry }}{{ .Values.cspcOperator.cstorPool.image.repository }}:{{ .Values.cspcOperator.cstorPool.image.tag }}"
            - name:  OPENEBS_IO_CSTOR_POOL_EXPORTER_IMAGE
              value: "{{ .Values.cspcOperator.cstorPoolExporter.image.registry }}{{ .Values.cspcOperator.cstorPoolExporter.image.repository }}:{{ .Values.cspcOperator.cstorPoolExporter.image.tag }}"
            - name: RESYNC_INTERVAL
              value: "{{ .Values.cspcOperator.resyncInterval }}"
{{- 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.cspcOperator.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.cspcOperator.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.cspcOperator.securityContext }}
      securityContext:
{{ toYaml .Values.cspcOperator.securityContext | indent 8 }}
{{- end }}
{{- if .Values.cspcOperator.tolerations }}
      tolerations:
{{ toYaml .Values.cspcOperator.tolerations | indent 8 }}
{{- end }}
