apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-jupyterlab
  labels:
    tier: aihub-dag
    component: jupyterlab
    release: {{ .Release.Name }}
spec:
  selector:
    matchLabels:
      tier: aihub-dag
      component: jupyterlab
      release: {{ .Release.Name }}
  template:
    metadata:
      {{- with .Values.jupyterlab.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        tier: aihub-dag
        component: jupyterlab
        release: {{ .Release.Name }}
        date: "{{ now | unixEpoch }}"
    spec:
      {{- with .Values.jupyterlab.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.jupyterlab.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Release.Name }}-jupyterlab
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.jupyterlab.image.repository }}:{{ .Values.jupyterlab.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.jupyterlab.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 8888
              protocol: TCP
          volumeMounts:
            - name: jupyterlab-data
              mountPath: /workspace
              subPath:  {{ .Values.jupyterlab.config.workspace }}
            - name: {{ .Release.Name }}-jupyterlab-config
              mountPath: /root/.jupyter/jupyter_lab_config.py
              subPath: jupyter_lab_config.py
          resources:
            {{- toYaml .Values.jupyterlab.resources | nindent 12 }}
      volumes:
        - name: jupyterlab-data
          persistentVolumeClaim:
            claimName: jupyterlab-data0
        - name: {{ .Release.Name }}-jupyterlab-config
          configMap:
            name: {{ .Release.Name }}-jupyterlab-config
      {{- with .Values.jupyterlab.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.jupyterlab.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.jupyterlab.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
