# helm_charts_deployment-maya-provisioner.yaml
{{- if .Values.provisioner.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "openebs.fullname" . }}-provisioner
  labels:
    app: {{ template "openebs.name" . }}
    chart: {{ template "openebs.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: provisioner
    name: openebs-provisioner
    openebs.io/component-name: openebs-provisioner
    openebs.io/version: {{ .Values.release.version }}
spec:
  replicas: {{ .Values.provisioner.replicas }}
  strategy:
    type: "Recreate"
    rollingUpdate: null
  selector:
    matchLabels:
      app: {{ template "openebs.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "openebs.name" . }}
        release: {{ .Release.Name }}
        component: provisioner
        name: openebs-provisioner
        openebs.io/component-name: openebs-provisioner
        openebs.io/version: {{ .Values.release.version }}
    spec:
      serviceAccountName: {{ template "openebs.serviceAccountName" . }}
      containers:
      - name: {{ template "openebs.name" . }}-provisioner
        image: "{{ .Values.image.repository }}{{ .Values.provisioner.image }}:{{ .Values.provisioner.imageTag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
        # OPENEBS_IO_K8S_MASTER enables openebs provisioner to connect to K8s
        # based on this address. This is ignored if empty.
        # This is supported for openebs provisioner version 0.5.2 onwards
        #- name: OPENEBS_IO_K8S_MASTER
        #  value: "http://10.128.0.12:8080"
        # OPENEBS_IO_KUBE_CONFIG enables openebs provisioner to connect to K8s
        # based on this config. This is ignored if empty.
        # This is supported for openebs provisioner version 0.5.2 onwards
        #- name: OPENEBS_IO_KUBE_CONFIG
        #  value: "/home/ubuntu/.kube/config"
        # OPENEBS_NAMESPACE is the namespace that this provisioner will
        # lookup to find maya api service
        - name: OPENEBS_NAMESPACE
          value: "{{ .Release.Namespace }}"
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        # OPENEBS_MAYA_SERVICE_NAME provides the maya-apiserver K8s service name,
        # that provisioner should forward the volume create/delete requests.
        # If not present, "maya-apiserver-service" will be used for lookup.
        # This is supported for openebs provisioner version 0.5.3-RC1 onwards
        - name: OPENEBS_MAYA_SERVICE_NAME
          value: "{{ template "openebs.fullname" . }}-apiservice"
        # The following values will be set as annotations to the PV object.
        # Refer : https://github.com/openebs/external-storage/pull/15
        #- name: OPENEBS_MONITOR_URL
        #  value: "{{ .Values.provisioner.monitorUrl }}"
        #- name: OPENEBS_MONITOR_VOLKEY
        #  value: "{{ .Values.provisioner.monitorVolumeKey }}"
        #- name: MAYA_PORTAL_URL
        #  value: "{{ .Values.provisioner.mayaPortalUrl }}"
         # Process name used for matching is limited to the 15 characters
         # present in the pgrep output.
         # So fullname can't be used here with pgrep (>15 chars).A regular expression
         # that matches the entire command name has to specified.
         # Anchor `^` : matches any string that starts with `openebs-provis`
         # `.*`: matches any string that has `openebs-provis` followed by zero or more char
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - test `pgrep -c "^openebs-provisi.*"` = 1
          initialDelaySeconds: {{ .Values.provisioner.healthCheck.initialDelaySeconds }}
          periodSeconds: {{ .Values.provisioner.healthCheck.periodSeconds }}
{{- if .Values.provisioner.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.provisioner.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.provisioner.tolerations }}
      tolerations:
{{ toYaml .Values.provisioner.tolerations | indent 8 }}
{{- end }}
{{- if .Values.provisioner.affinity }}
      affinity:
{{ toYaml .Values.provisioner.affinity | indent 8 }}
{{- end }}
{{- end }}