# helm_charts_deployment-maya-apiserver.yaml
{{- if .Values.apiserver.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "openebs.fullname" . }}-apiserver
  labels:
    app: {{ template "openebs.name" . }}
    chart: {{ template "openebs.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: apiserver
    name: maya-apiserver
    openebs.io/component-name: maya-apiserver
    openebs.io/version: {{ .Values.release.version }}
spec:
  replicas: {{ .Values.apiserver.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: apiserver
        name: maya-apiserver
        openebs.io/component-name: maya-apiserver
        openebs.io/version: {{ .Values.release.version }}
    spec:
      serviceAccountName: {{ template "openebs.serviceAccountName" . }}
      containers:
      - name: {{ template "openebs.name" . }}-apiserver
        image: "{{ .Values.image.repository }}{{ .Values.apiserver.image }}:{{ .Values.apiserver.imageTag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - containerPort: {{ .Values.apiserver.ports.internalPort }}
        env:
        # OPENEBS_IO_KUBE_CONFIG enables maya api service to connect to K8s
        # based on this config. This is ignored if empty.
        # This is supported for maya api server version 0.5.2 onwards
        #- name: OPENEBS_IO_KUBE_CONFIG
        #  value: "/home/ubuntu/.kube/config"
        # OPENEBS_IO_K8S_MASTER enables maya api service to connect to K8s
        # based on this address. This is ignored if empty.
        # This is supported for maya api server version 0.5.2 onwards
        #- name: OPENEBS_IO_K8S_MASTER
        #  value: "http://172.28.128.3:8080"
        # OPENEBS_NAMESPACE provides the namespace of this deployment as an
        # environment variable
        - name: OPENEBS_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        # OPENEBS_SERVICE_ACCOUNT provides the service account of this pod as
        # environment variable
        - name: OPENEBS_SERVICE_ACCOUNT
          valueFrom:
            fieldRef:
              fieldPath: spec.serviceAccountName
        # OPENEBS_MAYA_POD_NAME provides the name of this pod as
        # environment variable
        - name: OPENEBS_MAYA_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        # If OPENEBS_IO_CREATE_DEFAULT_STORAGE_CONFIG is false then OpenEBS default
        # storageclass and storagepool will not be created.
        - name: OPENEBS_IO_CREATE_DEFAULT_STORAGE_CONFIG
          value: "{{ .Values.defaultStorageConfig.enabled }}"
        # OPENEBS_IO_INSTALL_DEFAULT_CSTOR_SPARSE_POOL decides whether default cstor sparse pool should be
        # configured as a part of openebs installation.
        # If "true" a default cstor sparse pool will be configured, if "false" it will not be configured.
        # This value takes effect only if OPENEBS_IO_CREATE_DEFAULT_STORAGE_CONFIG
        # is set to true
        - name: OPENEBS_IO_INSTALL_DEFAULT_CSTOR_SPARSE_POOL
          value: "{{ .Values.apiserver.sparse.enabled }}"
        # OPENEBS_IO_CSTOR_TARGET_DIR can be used to specify the hostpath
        # to be used for saving the shared content between the side cars
        # of cstor volume pod.
        # The default path used is /var/openebs/sparse
        - name: OPENEBS_IO_CSTOR_TARGET_DIR
          value: "{{ .Values.ndm.sparse.path }}"
        # 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.ndm.sparse.path }}"
        # OPENEBS_IO_JIVA_POOL_DIR can be used to specify the hostpath
        # to be used for default Jiva StoragePool loaded by OpenEBS
        # The default path used is /var/openebs
        # This value takes effect only if OPENEBS_IO_CREATE_DEFAULT_STORAGE_CONFIG
        # is set to true
        - name: OPENEBS_IO_JIVA_POOL_DIR
          value: "{{ .Values.jiva.defaultStoragePath }}"
        # OPENEBS_IO_LOCALPV_HOSTPATH_DIR can be used to specify the hostpath
        # to be used for default openebs-hostpath storageclass loaded by OpenEBS
        # The default path used is /var/openebs/local
        # This value takes effect only if OPENEBS_IO_CREATE_DEFAULT_STORAGE_CONFIG
        # is set to true
        - name: OPENEBS_IO_LOCALPV_HOSTPATH_DIR
          value: "{{ .Values.localprovisioner.basePath }}"
        # OPENEBS_IO_BASE_DIR used by the OpenEBS to store debug information and
        # so forth that are generated in the course of running OpenEBS containers.
        - name: OPENEBS_IO_BASE_DIR
          value: "{{ .Values.varDirectoryPath.baseDir }}"
        - name: OPENEBS_IO_JIVA_CONTROLLER_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.jiva.image }}:{{ .Values.jiva.imageTag }}"
        - name: OPENEBS_IO_JIVA_REPLICA_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.jiva.image }}:{{ .Values.jiva.imageTag }}"
        - name: OPENEBS_IO_JIVA_REPLICA_COUNT
          value: "{{ .Values.jiva.replicas }}"
        - name: OPENEBS_IO_CSTOR_TARGET_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.cstor.target.image }}:{{ .Values.cstor.target.imageTag }}"
        - name: OPENEBS_IO_CSTOR_POOL_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.cstor.pool.image }}:{{ .Values.cstor.pool.imageTag }}"
        - name: OPENEBS_IO_CSTOR_POOL_MGMT_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.cstor.poolMgmt.image }}:{{ .Values.cstor.poolMgmt.imageTag }}"
        - name: OPENEBS_IO_CSTOR_VOLUME_MGMT_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.cstor.volumeMgmt.image }}:{{ .Values.cstor.volumeMgmt.imageTag }}"
        - name: OPENEBS_IO_VOLUME_MONITOR_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.policies.monitoring.image }}:{{ .Values.policies.monitoring.imageTag }}"
        - name: OPENEBS_IO_CSTOR_POOL_EXPORTER_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.policies.monitoring.image }}:{{ .Values.policies.monitoring.imageTag }}"
        - name: OPENEBS_IO_HELPER_IMAGE
          value: "{{ .Values.image.repository }}{{ .Values.helper.image }}:{{ .Values.helper.imageTag }}"
        # OPENEBS_IO_ENABLE_ANALYTICS if set to true sends anonymous usage
        # events to Google Analytics
        - name: OPENEBS_IO_ENABLE_ANALYTICS
          value: "{{ .Values.analytics.enabled }}"
        # OPENEBS_IO_ANALYTICS_PING_INTERVAL can be used to specify the duration (in hours)
        # for periodic ping events sent to Google Analytics. Default is 24 hours.
        - name: OPENEBS_IO_ANALYTICS_PING_INTERVAL
          value: "{{ .Values.analytics.pingInterval }}"
        - name: OPENEBS_IO_INSTALLER_TYPE
          value: "charts-helm"
        # OPENEBS_IO_INSTALL_CRD environment variable is used to enable/disable CRD installation
        # from Maya API server. By default the CRDs will be installed
        - name: OPENEBS_IO_INSTALL_CRD
          value: "{{ .Values.crd.enableInstall }}"
        livenessProbe:
          exec:
            command:
            - /usr/local/bin/mayactl
            - version
          initialDelaySeconds: {{ .Values.apiserver.healthCheck.initialDelaySeconds }}
          periodSeconds: {{ .Values.apiserver.healthCheck.periodSeconds }}
{{- if .Values.apiserver.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.apiserver.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.apiserver.tolerations }}
      tolerations:
{{ toYaml .Values.apiserver.tolerations | indent 8 }}
{{- end }}
{{- if .Values.apiserver.affinity }}
      affinity:
{{ toYaml .Values.apiserver.affinity | indent 8 }}
{{- end }}
{{- end }}