mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-01-18 02:39:30 +00:00
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:
parent
69b16771ae
commit
6a631e61cb
@ -1,16 +1,24 @@
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: Template
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: my-template
|
||||
objects:
|
||||
- apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
labels:
|
||||
app: jjb
|
||||
jjb/session: "${SESSION}"
|
||||
name: jjb-deploy
|
||||
spec:
|
||||
ttlSecondsAfterFinished: 0
|
||||
backoffLimit: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: jjb
|
||||
app: jjb-deploy
|
||||
jjb/session: "${SESSION}"
|
||||
spec:
|
||||
containers:
|
||||
- name: jjb
|
||||
@ -31,3 +39,7 @@ spec:
|
||||
configMap:
|
||||
name: jenkins-jobs
|
||||
restartPolicy: Never
|
||||
parameters:
|
||||
- name: SESSION
|
||||
description: unique ID for the session to track the pod for the job
|
||||
required: true
|
||||
|
@ -1,16 +1,24 @@
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: Template
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: jjb-validate
|
||||
objects:
|
||||
- apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
labels:
|
||||
app: jjb-validate
|
||||
jjb/session: "${SESSION}"
|
||||
name: jjb-validate
|
||||
spec:
|
||||
ttlSecondsAfterFinished: 0
|
||||
backoffLimit: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: jjb-validate
|
||||
jjb/session: "${SESSION}"
|
||||
spec:
|
||||
containers:
|
||||
- name: jjb-validate
|
||||
@ -21,3 +29,7 @@ spec:
|
||||
- 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
|
||||
|
@ -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' ]
|
||||
|
Loading…
Reference in New Issue
Block a user