kind: Job
apiVersion: batch/v1
metadata:
  # User will give a recognizable and meaningful name upon the R function call.
  name: JOB_NAME
  # A service R function will generate UUID to be put here.
  generateName: GENERATE_NAME
  namespace: K8S_NAMESPACE
  labels:
    app.kubernetes.io/managed-by: Connect
    batch-group: BATCH_GROUP_ID
  annotations:
    batch.kubernetes.io/job-tracking: ''
spec:
  parallelism: 1
  completions: 1
  backoffLimit: 0
  selector:
  template:
    metadata:
      # As we run 1 Pod at a time, there is no need to specify a different name.
      generateName: GENERATE_NAME
      creationTimestamp: null
      labels:
        job-name: JOB_NAME
        batch-group: BATCH_GROUP_ID
      annotations:
        # Not sure if these matter?
        USER_TAG_0: USER_TAG
        name: PROGRAM_BASE_NAME
        service_ports: '[]'
        stdin: ''
        user: SERVICE_USER
    spec:
      volumes:
        # I assume this will have to be set to the home directory of the service account
        - name: mount0
          nfs:
            server: DEFAULT_NFS_MOUNT_IP_ADDRESS
            path: /home/SERVICE_USER
      containers:
        - name: rs-launcher-container
          image:
          command:
            - /bin/bash
          args:
            - '-c'
            # This will have to point to the proper program to execute
            - cd ~ && R --slave --no-save --no-restore -f PROGRAM_FULL_PATH
          env:
            - name: HOME
              value: /home/SERVICE_USER
          resources:
            limits:
              cpu: 'CPU_LIMIT'
              memory: MEMORY_LIMIT
          volumeMounts:
            # This will need to be configured
            - name: mount0
              mountPath: /home/SERVICE_USER
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
          stdinOnce: true
      restartPolicy: Never
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      shareProcessNamespace: true
      securityContext:
        # These will need to be autoset
        runAsUser: RUN_AS_USER
        runAsGroup: RUN_AS_GROUP
      schedulerName: default-scheduler
  completionMode: NonIndexed
  suspend: false
