{{- if .Values.ui.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "katib.fullname" . }}-ui
  namespace: {{ include "katib.namespace" . }}
  labels:
    {{- include "katib.ui.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.ui.replicas }}
  selector:
    matchLabels:
      {{- include "katib.ui.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "katib.ui.selectorLabels" . | nindent 8 }}
        {{- if .Values.istio.enabled }}
        sidecar.istio.io/inject: "true"
        {{- else }}
        sidecar.istio.io/inject: "false"
        {{- end }}
        {{- with .Values.ui.labels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      {{- with .Values.ui.annotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      {{- with .Values.global.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.ui.podSecurityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: katib-ui
          image: {{ include "katib.image" (dict "registry" .Values.global.imageRegistry "repository" .Values.ui.image.repository "tag" (.Values.ui.image.tag | default .Values.global.imageTag) "global" .Values.global) }}
          {{- include "katib.imagePullPolicy" (dict "pullPolicy" .Values.ui.image.pullPolicy "Values" .Values) | nindent 10 }}
          command:
            - "./katib-ui"
          args:
            - "--port={{ .Values.ui.port.arg }}"
          env:
            - name: KATIB_CORE_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            {{- with .Values.ui.env }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          ports:
            - name: {{ .Values.ui.port.name }}
              containerPort: {{ .Values.ui.port.containerPort }}
          {{- with .Values.ui.securityContext }}
          securityContext:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.ui.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}
      serviceAccountName: {{ include "katib.ui.serviceAccountName" . }}
      {{- with .Values.ui.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.ui.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.ui.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}