apiVersion: batch/v1
kind: Job
metadata:
  name: sdc-stage-libs-job
spec:
  template:
    metadata:
      name: sdc-stage-libs-job
    spec:
      containers:
      - name: sdc-stage-libs-job
        image: busybox:latest
        command: ["/bin/sh", "-c"]
        args:
        - >
          BASE_URL=https://archives.streamsets.com/datacollector
          && SDC_VERSION=3.16.1
          && for s in `cat /tmp/sdc-stage-libs`; 
          do 
            wget ${BASE_URL}/${SDC_VERSION}/tarball/${s}-${SDC_VERSION}.tgz; 
            tar -xvf ${s}-${SDC_VERSION}.tgz -C /tmp;
          done
          && cp -R /tmp/streamsets-datacollector-${SDC_VERSION}/streamsets-libs/* /streamsets-libs
          && for s in `cat /tmp/sdc-enterprise-stage-libs`; 
          do 
            wget ${BASE_URL}/latest/tarball/enterprise/${s}.tgz; 
            tar -xvf ${s}.tgz -C /tmp;
          done
          && cp -R /tmp/streamsets-libs/* /streamsets-libs
          && echo 'Here is a listing of the /streamsets-libs dir'
          && ls -l /streamsets-libs
        volumeMounts:
        - name: sdc-stage-libs-list
          mountPath: /tmp/sdc-stage-libs
          subPath: sdc-stage-libs
        - name: sdc-stage-libs-list
          mountPath: /tmp/sdc-enterprise-stage-libs
          subPath: sdc-enterprise-stage-libs
        - name: sdc-stage-libs-pvc
          mountPath: /streamsets-libs
      restartPolicy: Never
      volumes:
      - name: sdc-stage-libs-list
        configMap:
          name: sdc-stage-libs-list
          items:
            - key: sdc-stage-libs
              path: sdc-stage-libs
            - key: sdc-enterprise-stage-libs
              path: sdc-enterprise-stage-libs
      - name: sdc-stage-libs-pvc
        persistentVolumeClaim:
          claimName: sdc-stage-libs-pvc