ci: improve logging for kubectl_retry helper

Rook deployments fail quite regulary in the CI environment now. It is
not clear what the cause is, hopefully a little better logging will
guide us to the issue.

Now executing `kubectl` in a sub-shell, ensuring that the redirection of
the command lands in the right files.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
(cherry picked from commit 1e21972956)
This commit is contained in:
Niels de Vos 2022-04-20 16:22:28 +02:00 committed by mergify[bot]
parent b50d8596ea
commit 2f7fb80498

View File

@ -11,7 +11,7 @@ kubectl_retry() {
stdout=$(mktemp rook-kubectl-stdout.XXXXXXXX)
stderr=$(mktemp rook-kubectl-stderr.XXXXXXXX)
while ! kubectl "${action}" "${@}" 2>"${stderr}" 1>"${stdout}"
while ! ( kubectl "${action}" "${@}" 2>"${stderr}" 1>"${stdout}" )
do
# in case of a failure when running "create", ignore errors with "AlreadyExists"
if [ "${action}" == 'create' ]
@ -47,7 +47,7 @@ kubectl_retry() {
# log stderr and empty the tmpfile
cat "${stderr}" > /dev/stderr
true > "${stderr}"
echo "kubectl_retry ${*} failed, will retry in ${KUBECTL_RETRY_DELAY} seconds"
echo "$(date): 'kubectl_retry ${*}' failed (${retries}/${KUBECTL_RETRY}), will retry in ${KUBECTL_RETRY_DELAY} seconds" > /dev/stderr
sleep ${KUBECTL_RETRY_DELAY}
@ -56,6 +56,8 @@ kubectl_retry() {
ret=0
done
echo "$(date): 'kubectl_retry ${*}' done (ret=${ret})" > /dev/stderr
# write output so that calling functions can consume it
cat "${stdout}" > /dev/stdout
cat "${stderr}" > /dev/stderr