ci: track jjb jobs by a jjb/session=<uuid> label

By using a template, it becomes possible to identify the Pod that has
been started by the Batch Job.

This prevents the script from getting the logs from an incorrect (old)
container.

Fixes: #1111
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-05-28 17:22:48 +02:00 committed by mergify[bot]
parent 69b16771ae
commit 6a631e61cb
3 changed files with 78 additions and 51 deletions

View File

@ -1,33 +1,45 @@
--- ---
apiVersion: batch/v1 kind: Template
kind: Job apiVersion: v1
metadata: metadata:
labels: name: my-template
app: jjb objects:
name: jjb-deploy - apiVersion: batch/v1
spec: kind: Job
ttlSecondsAfterFinished: 0 metadata:
backoffLimit: 1 labels:
template: app: jjb
labels: jjb/session: "${SESSION}"
app: jjb name: jjb-deploy
spec: spec:
containers: ttlSecondsAfterFinished: 0
- name: jjb backoffLimit: 1
image: 172.30.254.79:5000/ceph-csi/jjb:latest template:
env: metadata:
- name: GIT_REPO labels:
value: https://github.com/ceph/ceph-csi app: jjb-deploy
- name: GIT_REF jjb/session: "${SESSION}"
value: ci/centos spec:
- name: MAKE_TARGET containers:
value: deploy - name: jjb
volumeMounts: 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 - name: etc-jj
mountPath: /etc/jenkins_jobs configMap:
readOnly: true name: jenkins-jobs
volumes: restartPolicy: Never
- name: etc-jj parameters:
configMap: - name: SESSION
name: jenkins-jobs description: unique ID for the session to track the pod for the job
restartPolicy: Never required: true

View File

@ -1,23 +1,35 @@
--- ---
apiVersion: batch/v1 kind: Template
kind: Job apiVersion: v1
metadata: metadata:
labels:
app: jjb-validate
name: jjb-validate name: jjb-validate
spec: objects:
ttlSecondsAfterFinished: 0 - apiVersion: batch/v1
backoffLimit: 1 kind: Job
template: metadata:
labels: labels:
app: jjb-validate app: jjb-validate
jjb/session: "${SESSION}"
name: jjb-validate
spec: spec:
containers: ttlSecondsAfterFinished: 0
- name: jjb-validate backoffLimit: 1
image: 172.30.254.79:5000/ceph-csi/jjb:latest template:
env: metadata:
- name: GIT_REPO labels:
value: https://github.com/ceph/ceph-csi app: jjb-validate
- name: GIT_REF jjb/session: "${SESSION}"
value: ci/centos spec:
restartPolicy: Never 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

View File

@ -31,12 +31,15 @@ oc version
# the deploy directory where this script is located, contains files we need # the deploy directory where this script is located, contains files we need
cd "$(dirname "${0}")" 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 # loop until pod is available
while true while true
do 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=${?} ret=${?}
# break the loop when the command returned success and jjb_pod is not empty # break the loop when the command returned success and jjb_pod is not empty
@ -59,7 +62,7 @@ done
oc logs "${jjb_pod}" oc logs "${jjb_pod}"
# delete the job, so a next run can create it again # 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 # return the exit status of the pod
[ "${status}" = 'Succeeded' ] [ "${status}" = 'Succeeded' ]