apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: {{ template "openebs.fullname" . }}-snapshot-operator
  labels:
    app: {{ template "openebs.name" . }}
    chart: {{ template "openebs.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: snapshot-operator
spec:
  replicas: {{ .Values.snapshotOperator.replicas }}
  strategy:
    type: {{ .Values.snapshotOperator.upgradeStrategy }}
  template:
    metadata:
      labels:
        app: {{ template "openebs.name" . }}
        release: {{ .Release.Name }}
        component: snapshot-operator
    spec:
      serviceAccountName: {{ template "openebs.serviceAccountName" . }}
      containers:
      - name: {{ template "openebs.name" . }}-snapshot-controller
        image: "{{ .Values.snapshotOperator.controller.image }}:{{ .Values.snapshotOperator.controller.imageTag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
        # OPENEBS_IO_K8S_MASTER enables openebs snapshot controller to connect to K8s
        # based on this address. This is ignored if empty.
        # This is supported for openebs snapshot controller version 0.6-RC1 onwards
        #- name: OPENEBS_IO_K8S_MASTER
        #  value: "http://10.128.0.12:8080"
        # OPENEBS_IO_KUBE_CONFIG enables openebs snapshot controller to connect to K8s
        # based on this config. This is ignored if empty.
        # This is supported for openebs snapshot controller version 0.6-RC1 onwards
        #- name: OPENEBS_IO_KUBE_CONFIG
        #  value: "/home/ubuntu/.kube/config"
        # OPENEBS_NAMESPACE is the namespace that this snapshot controller 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 snapshot controller should forward the volume snapshot requests.
        # If not present, "maya-apiserver-service" will be used for lookup.
        # This is supported for openebs snapshot controller version 0.6-RC1 onwards
        - name: OPENEBS_MAYA_SERVICE_NAME
          value: "{{ template "openebs.fullname" . }}-apiservice"
      - name: {{ template "openebs.name" . }}-snapshot-provisioner
        image: "{{ .Values.snapshotOperator.provisioner.image }}:{{ .Values.snapshotOperator.provisioner.imageTag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
        # OPENEBS_IO_K8S_MASTER enables openebs snapshot provisioner to connect to K8s
        # based on this address. This is ignored if empty.
        # This is supported for openebs snapshot provisioner version 0.6-RC1 onwards
        #- name: OPENEBS_IO_K8S_MASTER
        #  value: "http://10.128.0.12:8080"
        # OPENEBS_IO_KUBE_CONFIG enables openebs snapshot provisioner to connect to K8s
        # based on this config. This is ignored if empty.
        # This is supported for openebs snapshot provisioner version 0.6-RC1 onwards
        #- name: OPENEBS_IO_KUBE_CONFIG
        #  value: "/home/ubuntu/.kube/config"
        # OPENEBS_NAMESPACE is the namespace that this snapshot 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 snapshot provisioner should forward the volume snapshot PV requests.
        # If not present, "maya-apiserver-service" will be used for lookup.
        # This is supported for openebs snapshot provisioner version 0.6-RC1 onwards
        - name: OPENEBS_MAYA_SERVICE_NAME
          value: "{{ template "openebs.fullname" . }}-apiservice"
{{- if .Values.snapshotOperator.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.snapshotOperator.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.snapshotOperator.tolerations }}
      tolerations:
{{ toYaml .Values.snapshotOperator.tolerations | indent 8 }}
{{- end }}
{{- if .Values.snapshotOperator.affinity }}
      affinity:
{{ toYaml .Values.snapshotOperator.affinity | indent 8 }}
{{- end }}
