apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "open-webui.name" . }}
  labels:
    {{- include "open-webui.labels" . | nindent 4 }}
  {{- with .Values.webui.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  replicas: {{ .Values.webui.replicaCount }}
  selector:
    matchLabels:
      {{- include "open-webui.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "open-webui.labels" . | nindent 8 }}
      {{- with .Values.webui.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      enableServiceLinks: false
      automountServiceAccountToken: false
      containers:
      - name: {{ .Chart.Name }}
        {{- with .Values.webui.image }}
        image: {{ .repository }}:{{ .tag | default $.Chart.AppVersion }}
        imagePullPolicy: {{ .pullPolicy }}
        {{- end }}
        ports:
        - name: http
          containerPort: {{ .Values.webui.service.containerPort }}
        {{- with .Values.webui.resources }}
        resources: {{- toYaml . | nindent 10 }}
        {{- end }}
        volumeMounts:
        - name: data
          mountPath: /app/backend/data
        env:
        - name: OLLAMA_BASE_URL
          value: {{ include "ollama.url" . | quote }}
        tty: true
      {{- with .Values.webui.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
      {{- if and .Values.webui.persistence.enabled .Values.webui.persistence.existingClaim }}
      - name: data
        persistentVolumeClaim:
          claimName: {{ .Values.webui.persistence.existingClaim }}
      {{- else if not .Values.webui.persistence.enabled }}
      - name: data
        emptyDir: {}
      {{- else if and .Values.webui.persistence.enabled (not .Values.webui.persistence.existingClaim) }}
      - name: data
        persistentVolumeClaim:
          claimName: {{ include "open-webui.name" . }}
      {{- end }}