2020-04-01 11:35:10 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Create a new Job in OCP that runs the jbb-validate container once. This
|
|
|
|
# script will wait for completion of the validation, and uses the result of the
|
|
|
|
# container to report the status.
|
|
|
|
#
|
|
|
|
|
2020-05-26 14:53:32 +00:00
|
|
|
# error out in case a command fails
|
|
|
|
set -e
|
|
|
|
|
2020-04-01 11:35:10 +00:00
|
|
|
CMD="${1}"
|
|
|
|
|
|
|
|
get_pod_status() {
|
2020-05-26 14:53:32 +00:00
|
|
|
oc get "pod/${1}" --no-headers -o=jsonpath='{.status.phase}'
|
2020-04-01 11:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "${CMD}" in
|
|
|
|
"validate")
|
|
|
|
;;
|
|
|
|
"deploy")
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "no such command: ${CMD}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# make sure there is a valid OCP session
|
2020-05-26 14:53:32 +00:00
|
|
|
oc version
|
2020-04-01 11:35:10 +00:00
|
|
|
|
|
|
|
# the deploy directory where this script is located, contains files we need
|
2020-05-26 14:53:32 +00:00
|
|
|
cd "$(dirname "${0}")"
|
2020-04-01 11:35:10 +00:00
|
|
|
|
2020-05-28 15:22:48 +00:00
|
|
|
# unique ID for the session
|
|
|
|
SESSION=$(uuidgen)
|
|
|
|
|
|
|
|
oc process -f "jjb-${CMD}.yaml" -p=SESSION="${SESSION}" | oc create -f -
|
2020-04-01 11:35:10 +00:00
|
|
|
|
|
|
|
# loop until pod is available
|
|
|
|
while true
|
|
|
|
do
|
2020-05-28 15:22:48 +00:00
|
|
|
jjb_pod=$(oc get pods --no-headers -l "jjb/session=${SESSION}" -o=jsonpath='{.items[0].metadata.name}')
|
2020-05-26 14:53:32 +00:00
|
|
|
ret=${?}
|
|
|
|
|
|
|
|
# break the loop when the command returned success and jjb_pod is not empty
|
|
|
|
[ ${ret} = 0 ] && [ -n "${jjb_pod}" ] && break
|
2020-04-01 11:35:10 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
# loop until the pod has finished
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
status=$(get_pod_status "${jjb_pod}")
|
2020-05-26 14:53:32 +00:00
|
|
|
ret=${?}
|
|
|
|
|
2020-04-01 11:35:10 +00:00
|
|
|
# TODO: is Running as a status sufficient, did it terminate yet?
|
2020-05-26 14:53:32 +00:00
|
|
|
[ ${ret} = 0 ] && { [ "${status}" = "Succeeded" ] || [ "${status}" = "Failed" ]; } && break
|
2020-04-01 11:35:10 +00:00
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
|
|
|
|
# show the log of the finished pod
|
|
|
|
oc logs "${jjb_pod}"
|
|
|
|
|
|
|
|
# delete the job, so a next run can create it again
|
2020-05-28 15:22:48 +00:00
|
|
|
oc process -f "jjb-${CMD}.yaml" -p=SESSION="${SESSION}" | oc delete --wait -f -
|
2020-07-24 13:43:48 +00:00
|
|
|
# depending on the OpenShift version, the pod gets deleted automatically
|
|
|
|
oc delete --ignore-not-found pod "${jjb_pod}"
|
2020-04-01 11:35:10 +00:00
|
|
|
|
|
|
|
# return the exit status of the pod
|
|
|
|
[ "${status}" = 'Succeeded' ]
|