{{ if .Values.jupyter.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jupyter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jupyter
  template:
    metadata:
      name: jupyter
      labels:
        app: jupyter
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: jupyter
        image: docker.io/goalprofit/jupyter:{{.Values.jupyter.version}}
        imagePullPolicy: Always
#        resources:
#          limits:
#            memory: "{{.Values.jupyter.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: TNL_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-tnl
                key: key
                optional: true
          - name: AZURE_OPENAI_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-openai-azure-apikey
                key: key
                optional: true
          - name: AZURE_OPENAI_API_ENDPOINT
            valueFrom:
              secretKeyRef:
                name: secret-openai-azure-endpoint
                key: key
                optional: true
          - name: AZURE_OPENAI_API_VERSION
            valueFrom:
              secretKeyRef:
                name: secret-openai-azure-apiversion
                key: key
                optional: true
          - name: OPENAI_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-openai
                key: key
                optional: true
          - name: JI_API_KEY
            valueFrom:
              secretKeyRef:
                name: secret-ji
                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: 8888

      imagePullSecrets:
      - name: regcred

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

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