{{ if .Values.streamlit.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: streamlit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: streamlit
  template:
    metadata:
      name: streamlit
      labels:
        app: streamlit
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: streamlit
        image: docker.io/goalprofit/streamlit:{{.Values.streamlit.version}}
        imagePullPolicy: Always
        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: TNL_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-tnl
                key: key
                optional: true
          - name: OPENAI_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-openai
                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
          - name: JI_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-ji
                key: key
                optional: true                
        ports:
          - containerPort: 8501

      imagePullSecrets:
      - name: regcred

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

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