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
|
kind: Job
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: jjb
|
app: jjb
|
||||||
|
jjb/session: "${SESSION}"
|
||||||
name: jjb-deploy
|
name: jjb-deploy
|
||||||
spec:
|
spec:
|
||||||
ttlSecondsAfterFinished: 0
|
ttlSecondsAfterFinished: 0
|
||||||
backoffLimit: 1
|
backoffLimit: 1
|
||||||
template:
|
template:
|
||||||
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: jjb
|
app: jjb-deploy
|
||||||
|
jjb/session: "${SESSION}"
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: jjb
|
- name: jjb
|
||||||
@ -31,3 +39,7 @@ spec:
|
|||||||
configMap:
|
configMap:
|
||||||
name: jenkins-jobs
|
name: jenkins-jobs
|
||||||
restartPolicy: Never
|
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
|
kind: Job
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: jjb-validate
|
app: jjb-validate
|
||||||
|
jjb/session: "${SESSION}"
|
||||||
name: jjb-validate
|
name: jjb-validate
|
||||||
spec:
|
spec:
|
||||||
ttlSecondsAfterFinished: 0
|
ttlSecondsAfterFinished: 0
|
||||||
backoffLimit: 1
|
backoffLimit: 1
|
||||||
template:
|
template:
|
||||||
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: jjb-validate
|
app: jjb-validate
|
||||||
|
jjb/session: "${SESSION}"
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: jjb-validate
|
- name: jjb-validate
|
||||||
@ -21,3 +29,7 @@ spec:
|
|||||||
- name: GIT_REF
|
- name: GIT_REF
|
||||||
value: ci/centos
|
value: ci/centos
|
||||||
restartPolicy: Never
|
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
|
# 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' ]
|
||||||
|
Loading…
Reference in New Issue
Block a user