{{- if .Values.langflow.frontend.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "langflow.fullname" . }}-frontend
  labels:
    app: {{ template "langflow.name" . }}
    chart: {{ template "langflow.chart" . }}
    release: {{ .Release.Name }}
    langflow-scope: "frontend"
spec:
  replicas: {{ .Values.langflow.frontend.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "langflow.name" . }}
      chart: {{ template "langflow.chart" . }}
      release: {{ .Release.Name }}
      langflow-scope: "frontend"
  template:
    metadata:
      {{- with .Values.langflow.frontend.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        app: {{ template "langflow.name" . }}
        chart: {{ template "langflow.chart" . }}
        release: {{ .Release.Name }}
        langflow-scope: "frontend"
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "langflow.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.langflow.frontend.podSecurityContext | nindent 8 }}
      volumes:
        {{- if .Values.secretProvider.enabled }}
        - name: secrets-store-inline
          csi:
            driver: secrets-store.csi.k8s.io
            readOnly: true
            volumeAttributes:
              secretProviderClass: "{{- .Values.secretProvider.name }}"
        {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.langflow.securityContext | nindent 12 }}
          image: "{{ .Values.langflow.frontend.image.repository }}:{{ .Values.langflow.frontend.image.tag | default .Values.langflow.global.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.langflow.frontend.image.pullPolicy | default .Values.langflow.global.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.langflow.frontend.service.port }}
              protocol: TCP
          volumeMounts:
            {{- if .Values.secretProvider.enabled }}
            - name: secrets-store-inline
              mountPath: "/mnt/secrets"
              readOnly: true
            {{- end }}
          livenessProbe:
            httpGet:
              path: /index.html
              port: http
            initialDelaySeconds: {{ .Values.langflow.frontend.probe.initialDelaySeconds }}
            periodSeconds: {{ .Values.langflow.frontend.probe.periodSeconds }}
            timeoutSeconds: {{ .Values.langflow.frontend.probe.timeoutSeconds }}
            failureThreshold: {{ .Values.langflow.frontend.probe.failureThreshold }}   
          readinessProbe:
            httpGet:
              path: /index.html
              port: http
            initialDelaySeconds: {{ .Values.langflow.frontend.probe.initialDelaySeconds }}
            periodSeconds: {{ .Values.langflow.frontend.probe.periodSeconds }}
            timeoutSeconds: {{ .Values.langflow.frontend.probe.timeoutSeconds }}
            failureThreshold: {{ .Values.langflow.frontend.probe.failureThreshold }}   
          env:
            - name: BACKEND_URL
              value: "http://{{ template "langflow.fullname" . }}-backend.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.langflow.backend.service.port }}"
            - name: FRONTEND_PORT
              value: "{{ .Values.langflow.frontend.service.port }}"
          resources:
            {{- toYaml .Values.langflow.frontend.resources | nindent 12 }}
      {{- with .Values.langflow.frontend.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.langflow.frontend.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.langflow.frontend.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}