apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: {{ template "kubedb.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    app: "{{ template "kubedb.name" . }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
  initializers:
    pending: []
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: "{{ template "kubedb.name" . }}"
      release: "{{ .Release.Name }}"
  template:
    metadata:
      labels:
        app: "{{ template "kubedb.name" . }}"
        release: "{{ .Release.Name }}"
{{- if and .Values.criticalAddon (eq .Release.Namespace "kube-system") }}
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
{{- end }}
    spec:
      serviceAccountName: {{ template "kubedb.serviceAccountName" . }}
      {{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 6 }}
      {{- end }}
      containers:
      - name: operator
        image: {{ .Values.dockerRegistry }}/operator:{{ .Values.imageTags.operator }}
        imagePullPolicy: {{ .Values.imagePullPolicy  }}
        args:
        - run
        - --v=3
        - --docker-registry={{ .Values.dockerRegistry }}
        - --exporter-tag={{ .Values.imageTags.exporter }}
        - --governing-service=kubedb
        - --rbac={{ .Values.rbac.create }}
        env:
        - name: OPERATOR_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
      - name: server
        image: {{ .Values.dockerRegistry }}/kubedb-server:{{ .Values.imageTags.apiserver }}
        imagePullPolicy: {{ .Values.imagePullPolicy  }}
        args:
        - run
        - --v=3
        - --secure-port=8443
        - --audit-log-path=-
        - --tls-cert-file=/var/serving-cert/tls.crt
        - --tls-private-key-file=/var/serving-cert/tls.key
        ports:
        - containerPort: 8443
        volumeMounts:
        - mountPath: /var/serving-cert
          name: serving-cert
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8443
            scheme: HTTPS
      volumes:
      - name: serving-cert
        secret:
          defaultMode: 420
          secretName: {{ template "kubedb.fullname" . }}-apiserver-cert
{{- if and .Values.criticalAddon (eq .Release.Namespace "kube-system") }}
      tolerations:
      - key: CriticalAddonsOnly
        operator: Exists
{{- end -}}
