{{ if .Values.chat_solution.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: chat-solution
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chat-solution
  template:
    metadata:
      name: chat-solution
      labels:
        app: chat-solution
    spec:
      containers:
      - name: chat-solution
        image: docker.io/goalprofit/chat-solution:{{.Values.chat_solution.version}}
        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /work
          name: work
          subPath: data/dist/

        env:
{{ if .Values.local_user_id }}
        - name: LOCAL_USER_ID
          value: "{{.Values.local_user_id}}"
{{ end }}
{{ if .Values.local_user_name }}
        - name: LOCAL_USER_NAME
          value: "{{.Values.local_user_name}}"
{{ end }}
      imagePullSecrets:
      - name: regcred

      volumes:
      - name: work
        {{ include "app.customer_volume" . | nindent 8}}
---
apiVersion: v1
kind: Service
metadata:
  name: chat-solution
spec:
  type: ClusterIP
  selector:
    app: chat-solution
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: chat-solution
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/configuration-snippet: |
      auth_request /authenticator/check-basic;
      error_page 401 =302 /authenticator/login?redirect=$request_uri;
spec:
  ingressClassName: nginx
  rules:
    - host: {{ .Values.domain }}
      http:
        paths:
          - path: /chat-solution/?(.*)
            pathType: ImplementationSpecific
            backend:
              service:
                name: chat-solution
                port:
                  number: 80
{{ end }}