{{- if .Values.dbManager.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "katib.fullname" . }}-db-manager
  namespace: {{ include "katib.namespace" . }}
  labels:
    {{- include "katib.dbManager.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.dbManager.replicas }}
  selector:
    matchLabels:
      {{- include "katib.dbManager.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "katib.dbManager.selectorLabels" . | nindent 8 }}
        sidecar.istio.io/inject: "false"
        {{- with .Values.dbManager.labels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      {{- with .Values.dbManager.annotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      {{- with .Values.global.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.dbManager.podSecurityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: katib-db-manager
          image: {{ include "katib.image" (dict "registry" .Values.global.imageRegistry "repository" .Values.dbManager.image.repository "tag" (.Values.dbManager.image.tag | default .Values.global.imageTag) "global" .Values.global) }}
          {{- include "katib.imagePullPolicy" (dict "pullPolicy" .Values.dbManager.image.pullPolicy "Values" .Values) | nindent 10 }}
          command:
            - "./katib-db-manager"
          env:
            {{- include "katib.database.env" . | nindent 12 }}
            {{- with .Values.dbManager.env }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          ports:
            - name: {{ .Values.dbManager.port.name }}
              containerPort: {{ .Values.dbManager.port.containerPort }}
              {{- include "katib.protocol" (dict "protocol" "TCP" "Values" .Values) | nindent 14 }}
          livenessProbe:
            grpc:
              port: {{ .Values.dbManager.probes.liveness.port }}
            initialDelaySeconds: {{ .Values.dbManager.probes.liveness.initialDelaySeconds }}
            periodSeconds: {{ .Values.dbManager.probes.liveness.periodSeconds }}
            failureThreshold: {{ .Values.dbManager.probes.liveness.failureThreshold }}
          {{- with .Values.dbManager.securityContext }}
          securityContext:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.dbManager.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}
      {{- with .Values.dbManager.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.dbManager.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.dbManager.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }} 