apiVersion: apps/v1
kind: Deployment
metadata:
  name: stats-scratch
  namespace: processing
  labels:
    app.kubernetes.io/name: stats-scratch
  annotations:
    fluxcd.io/ignore: "true"
    fluxcd.io/automated: "false"
spec:
  selector:
    matchLabels:
      app: stats-scratch
  replicas: 0
  template:
    metadata:
      labels:
        app: stats-scratch
    spec:
      tolerations:
        - key: "hub.jupyter.org/dedicated"
          operator: "Equal"
          value: "worker"
          effect: "NoSchedule"
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: nodetype
                operator: In
                values:
                - spot
              - key: nodegroup
                operator: In
                values:
                - sandbox        

      volumes:
        - name: volume-home
          persistentVolumeClaim:
            claimName: claim-ebs-kirill

      containers:
      - name: sandbox
        image: 565417506782.dkr.ecr.us-west-2.amazonaws.com/geoscienceaustralia/sandbox:sudo-latest
        imagePullPolicy: IfNotPresent

        volumeMounts:
          - name: volume-home
            mountPath: /home/jovyan

        resources:
            requests:
              ## r5.4xl
              cpu: 15100m
              memory: 119Gi
        env:
            - name: DB_HOSTNAME
              value: db-reader
            - name: DB_PORT
              value: "5432"
            - name: DB_DATABASE
              value: africa
            - name: DB_USERNAME
              valueFrom:
                  secretKeyRef:
                      name: stats-db
                      key: postgres-username
            - name: DB_PASSWORD
              valueFrom:
                  secretKeyRef:
                      name: stats-db
                      key: postgres-password
            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                   secretKeyRef:
                       name: processing-aws-creds-stats
                       key: AWS_ACCESS_KEY_ID
            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                   secretKeyRef:
                       name: processing-aws-creds-stats
                       key: AWS_SECRET_ACCESS_KEY
            - name: AWS_DEFAULT_REGION
              valueFrom:
                   secretKeyRef:
                       name: processing-aws-creds-stats
                       key: AWS_DEFAULT_REGION
            - name: JUPYTERHUB_SERVICE_PREFIX
              value: ""
            - name: TASK_DB_S3
              value: "s3://deafrica-stats-processing/gmrun_09102020/gm_s2_2019.db"
        command: ['/bin/bash']
        args:
            - '-c'
            - |
                [ -f /build.info ] && cat /build.info

                while true ; do
                   for i in {1..10}; do
                     printf .
                     sleep 6
                   done
                   date
                done
