{{ if .Values.voila.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: voila
spec:
  replicas: 1
  selector:
    matchLabels:
      app: voila
  template:
    metadata:
      name: voila
      labels:
        app: voila
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: voila
        image: docker.io/goalprofit/voila:{{.Values.voila.version}}
        imagePullPolicy: Always
        resources:
          limits:
            memory: "{{.Values.voila.ram_limit}}"
        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 }}
          - name: OPENAI_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-openai
                key: key
                optional: true
          - name: TNL_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-tnl
                key: key
                optional: true
          - name: SERVICE_LOGIN
            valueFrom:
              secretKeyRef:
                name: secret-service
                key: username
                optional: false
          - name: SERVICE_PASSWORD
            valueFrom:
              secretKeyRef:
                name: secret-service
                key: password
                optional: false
        volumeMounts:
        - mountPath: /home/jovyan/work
          name: customer
          subPath: data/jupyter
        - mountPath: /in
          name: customer
          subPath: in
        - mountPath: /downloads
          name: customer
          subPath: data/downloads
        ports:
          - containerPort: 8866

      imagePullSecrets:
      - name: regcred

      volumes:
      - name: customer
        {{ include "app.customer_volume" . | nindent 8}}
      {{ include "app.affinity" . | nindent 6}}

---
apiVersion: v1
kind: Service
metadata:
  name: voila
spec:
  type: ClusterIP
  selector:
    app: voila
  ports:
    - name: http
      protocol: TCP
      port: 8866
      targetPort: 8866
{{ end }}
