diff --git a/deploy/jjb-deploy.yaml b/deploy/jjb-deploy.yaml index d79fcf80f..4ee5b2ec0 100644 --- a/deploy/jjb-deploy.yaml +++ b/deploy/jjb-deploy.yaml @@ -1,33 +1,45 @@ --- -apiVersion: batch/v1 -kind: Job +kind: Template +apiVersion: v1 metadata: - labels: - app: jjb - name: jjb-deploy -spec: - ttlSecondsAfterFinished: 0 - backoffLimit: 1 - template: - labels: - app: jjb + name: my-template +objects: + - apiVersion: batch/v1 + kind: Job + metadata: + labels: + app: jjb + jjb/session: "${SESSION}" + name: jjb-deploy spec: - containers: - - name: jjb - image: 172.30.254.79:5000/ceph-csi/jjb:latest - env: - - name: GIT_REPO - value: https://github.com/ceph/ceph-csi - - name: GIT_REF - value: ci/centos - - name: MAKE_TARGET - value: deploy - volumeMounts: + ttlSecondsAfterFinished: 0 + backoffLimit: 1 + template: + metadata: + labels: + app: jjb-deploy + jjb/session: "${SESSION}" + spec: + containers: + - name: jjb + image: 172.30.254.79:5000/ceph-csi/jjb:latest + env: + - name: GIT_REPO + value: https://github.com/ceph/ceph-csi + - name: GIT_REF + value: ci/centos + - name: MAKE_TARGET + value: deploy + volumeMounts: + - name: etc-jj + mountPath: /etc/jenkins_jobs + readOnly: true + volumes: - name: etc-jj - mountPath: /etc/jenkins_jobs - readOnly: true - volumes: - - name: etc-jj - configMap: - name: jenkins-jobs - restartPolicy: Never + configMap: + name: jenkins-jobs + restartPolicy: Never +parameters: + - name: SESSION + description: unique ID for the session to track the pod for the job + required: true diff --git a/deploy/jjb-validate.yaml b/deploy/jjb-validate.yaml index 15e3c9326..fcb77dbd6 100644 --- a/deploy/jjb-validate.yaml +++ b/deploy/jjb-validate.yaml @@ -1,23 +1,35 @@ --- -apiVersion: batch/v1 -kind: Job +kind: Template +apiVersion: v1 metadata: - labels: - app: jjb-validate name: jjb-validate -spec: - ttlSecondsAfterFinished: 0 - backoffLimit: 1 - template: - labels: - app: jjb-validate +objects: + - apiVersion: batch/v1 + kind: Job + metadata: + labels: + app: jjb-validate + jjb/session: "${SESSION}" + name: jjb-validate spec: - containers: - - name: jjb-validate - image: 172.30.254.79:5000/ceph-csi/jjb:latest - env: - - name: GIT_REPO - value: https://github.com/ceph/ceph-csi - - name: GIT_REF - value: ci/centos - restartPolicy: Never + ttlSecondsAfterFinished: 0 + backoffLimit: 1 + template: + metadata: + labels: + app: jjb-validate + jjb/session: "${SESSION}" + spec: + containers: + - name: jjb-validate + image: 172.30.254.79:5000/ceph-csi/jjb:latest + env: + - name: GIT_REPO + value: https://github.com/ceph/ceph-csi + - name: GIT_REF + value: ci/centos + restartPolicy: Never +parameters: + - name: SESSION + description: unique ID for the session to track the pod for the job + required: true diff --git a/deploy/jjb.sh b/deploy/jjb.sh index af187b40a..2f2355923 100755 --- a/deploy/jjb.sh +++ b/deploy/jjb.sh @@ -31,12 +31,15 @@ oc version # the deploy directory where this script is located, contains files we need cd "$(dirname "${0}")" -oc create -f "jjb-${CMD}.yaml" +# unique ID for the session +SESSION=$(uuidgen) + +oc process -f "jjb-${CMD}.yaml" -p=SESSION="${SESSION}" | oc create -f - # loop until pod is available while true do - jjb_pod=$(oc get pods --no-headers -l "job-name=jjb-${CMD}" -o=jsonpath='{.items[0].metadata.name}') + jjb_pod=$(oc get pods --no-headers -l "jjb/session=${SESSION}" -o=jsonpath='{.items[0].metadata.name}') ret=${?} # break the loop when the command returned success and jjb_pod is not empty @@ -59,7 +62,7 @@ done oc logs "${jjb_pod}" # delete the job, so a next run can create it again -oc delete --wait -f "jjb-${CMD}.yaml" +oc process -f "jjb-${CMD}.yaml" -p=SESSION="${SESSION}" | oc delete --wait -f - # return the exit status of the pod [ "${status}" = 'Succeeded' ]