CSCfi/pebbles

View on GitHub
pebbles/drivers/provisioning/templates/deployment.yaml.j2

Summary

Maintainability
Test Coverage
apiVersion: apps/v1
kind: Deployment
metadata:
  name: "{{name}}"
spec:
  selector:
    matchLabels:
      name: "{{name}}"
  template:
    metadata:
      labels:
        name: "{{name}}"
        application: pebbles-session
    spec:
      # no default service account token for the pod
      automountServiceAccountToken: false
      # tolerations are set by driver
      tolerations: [ ]
      initContainers:
        - name: autodownload
          image: "{{image}}"
          imagePullPolicy: "{{image_pull_policy}}"
          env: [ ]
          command:
            - sh
            - -c
            - |
              # Mirror contents from the image to session-data volume. 
              # Session-data will be mounted over volume_mount_path in pebbles-session container.
              cp -aT {{volume_mount_path}} /data
              
              # We don't want the default empty 'work' folder from upstream jupyter as it can be confused 
              # with the persistent 'my-work' folder. Only remove directory if it is empty.
              rmdir -v /data/work
              
              # Autodownload
              if [ -z $AUTODOWNLOAD_URL ]; then exit 0; fi
              cd /data
              if [ $AUTODOWNLOAD_METHOD = "http-get" ]; then
                wget $AUTODOWNLOAD_URL 2>/tmp/download_error.txt || (cp -v /tmp/download_error.txt .)
              fi
              if [ $AUTODOWNLOAD_METHOD = "git-clone" ]; then
                git clone $AUTODOWNLOAD_URL 2>/tmp/git_clone_error.txt || (cp -v /tmp/git_clone_error.txt .)
              fi
              if [ ! -z $SESSION_DIR_CHOWN_UID ]; then
                chown -R $SESSION_DIR_CHOWN_UID /data
              fi
          volumeMounts:
            - mountPath: "/data"
              name: session-data
      containers:
        - name: proxy
          image: docker.io/bitnami/nginx:1.19.8
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: nginx-config
              mountPath: /opt/bitnami/nginx/conf/server_blocks
          resources:
            requests:
              cpu: "100m"
              memory: "64Mi"
            limits:
              cpu: "200m"
              memory: "64Mi"

        - name: pebbles-session
          image: "{{image}}"
          imagePullPolicy: "{{image_pull_policy}}"
          args: [ ]
          env: [ ]
          volumeMounts:
            - mountPath: "{{volume_mount_path}}"
              name: session-data
            {% if pvc_name_shared %}
            - mountPath: "{{volume_mount_path}}/shared"
              name: shared-data
            {% endif %}
            {% if pvc_name_user_work %}
            - mountPath: "{{volume_mount_path}}/my-work"
              name: user-work
            {% endif %}
          # generic check if the pod is accepting connections, poll every 1 second
          readinessProbe:
            tcpSocket:
              port: {{port}}
              periodSeconds: 1
          resources:
            requests:
              cpu: "100m"
              memory: "{{memory_limit}}"
            limits:
              cpu: "{{cpu_limit}}"
              memory: "{{memory_limit}}"

      volumes:
        - name: session-data
          persistentVolumeClaim:
            claimName: "{{pvc_name_session}}"
            readOnly: false
        {% if pvc_name_user_work %}
        - name: user-work
          persistentVolumeClaim:
            claimName: "{{pvc_name_user_work}}"
        {% endif %}
        {% if pvc_name_shared %}
        - name: shared-data
          persistentVolumeClaim:
            claimName: "{{pvc_name_shared}}"
            readOnly: {{shared_data_read_only_mode}}
        {% endif %}
        - name: nginx-config
          configMap:
            name: "{{name}}"
            items:
              - key: "proxy.conf"
                path: "proxy.conf"