Skip to content

Commit

Permalink
fix(KFLUXBUGS-1278): make iib errors available to users
Browse files Browse the repository at this point in the history
This commit exposes the iib error log if one occurred in the iib
operation and bubbles it up to the pipelineRun as a result. It also
changes the iib-add-fbc-fragment-to-index-image task to never fail.

Signed-off-by: Johnny Bieren <[email protected]>
  • Loading branch information
johnbieren committed Aug 29, 2024
1 parent 7570fb8 commit f930352
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: t-add-fbc-fragment-to-index-image
labels:
app.kubernetes.io/version: "0.2.0"
app.kubernetes.io/version: "0.2.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -62,6 +62,10 @@ spec:
description: Set the genericResult if FBC Fragment is Opt-In and should be published
- name: indexImageDigests
description: The digests for each arch for the manifest list of the index image
- name: iibLog
description: The link to the log from the IIB request
- name: exitCode
description: The exit code from the task
steps:
- name: s-add-fbc-fragment-to-index-image
image: >-
Expand Down Expand Up @@ -210,42 +214,43 @@ spec:
key: url
script: |
#!/usr/bin/env bash
TASKRUN="/tmp/$$.sh"
set -x
cat > ${TASKRUN} <<SH
#!/usr/bin/env bash
#
build_id=`jq -r ".id" $(results.jsonBuildInfo.path)`
state=""
while true; do
#
# fetching build information.
build_info=\$(/usr/bin/curl -s "\${IIB_SERVICE_URL}/builds/\${build_id}")
# get state from the build information.
state=\$(jq -r ".state" <<< \${build_info})
# remove the history as it breaks the results build up
jq -r 'del(.state_history)' <<< \${build_info} | jq -c . > $(results.jsonBuildInfo.path)
case \${state} in
"complete") break ;;
"failed") break ;;
*) echo -en "."; sleep 30; continue ;;
esac
done
echo
jq -cr '{ "state": .state, "state_reason": .state_reason }' $(results.jsonBuildInfo.path) | jq -Rc \
| tee $(results.buildState.path)
test \${state} = "complete" && exit 0 || exit 1
SH
watch_build_state() {
build_id=`jq -r ".id" $(results.jsonBuildInfo.path)`
state=""
while true; do

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
#
# fetching build information.
build_info=$(/usr/bin/curl -s "${IIB_SERVICE_URL}/builds/${build_id}")

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
# get state from the build information.
state="$(jq -r ".state" <<< ${build_info})"

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2086 Warning

Double quote to prevent globbing and word splitting.
# remove the history as it breaks the results build up
jq -r 'del(.state_history)' <<< ${build_info} | jq -c . > "$(results.jsonBuildInfo.path)"

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2086 Warning

Double quote to prevent globbing and word splitting.

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
url="$(jq -r ".logs.url" <<< ${build_info})"

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2086 Warning

Double quote to prevent globbing and word splitting.
echo IIB log url is: "${url}" > "$(results.iibLog.path)"

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
case ${state} in
"complete") break ;;

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
"failed") break ;;

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
*) echo -en "."; sleep 30; continue ;;

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
esac

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
done

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
echo

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
jq -cr '{ "state": .state, "state_reason": .state_reason }' "$(results.jsonBuildInfo.path)" | jq -Rc \

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
| tee "$(results.buildState.path)"

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
test "${state}" = "complete" && exit 0 || exit 1

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

Check warning

Code scanning / shellcheck

SC2317 Warning

Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
}
chmod +x ${TASKRUN}
echo -en "waiting for build state to exit..."
# adding timeout here due to the Task timeout not accepting $(params.buildTimeoutSeconds)
# as parameter.
timeout $(params.buildTimeoutSeconds) ${TASKRUN}
export -f watch_build_state
timeout "$(params.buildTimeoutSeconds)" bash -c watch_build_state
BUILDEXIT=$?
# it should continue only if the IIB build status is complete
if [ ${BUILDEXIT} -eq 0 ]; then
echo -n 0 > "$(results.exitCode.path)"
# get the manifest digests
indexImageCopy=`cat $(results.jsonBuildInfo.path) | jq -cr .internal_index_image_copy`
Expand All @@ -260,17 +265,21 @@ spec:
echo -n $indexImageDigests > $(results.indexImageDigests.path)
if [ -z "${indexImageDigests}" ] ; then
echo "Index image produced is not multi-arch with a manifest list"
exit 1
echo -n 1 > "$(results.exitCode.path)"
fi
else
if [ ${BUILDEXIT} -eq 124 ]; then
echo "Timeout while waiting for the build to finish"
echo "Build timeout" < $(results.buildState.path)
exit $BUILDEXIT
else
exit $BUILDEXIT
fi
echo -n "" > "$(results.indexImageDigests.path)"
echo -n "$BUILDEXIT" > "$(results.exitCode.path)"
fi
# We don't put the log in a result because tekton results are too limited for what we can put
# to be useful, but still print it for debugging
/usr/bin/curl -s "$(awk '{print $NF}' < "$(results.iibLog.path)")"
exit 0
volumes:
- name: service-account-secret
secret:
Expand Down
8 changes: 6 additions & 2 deletions internal-services/catalog/iib-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: iib
labels:
app.kubernetes.io/version: "0.2"
app.kubernetes.io/version: "0.3"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: fbc
Expand Down Expand Up @@ -92,3 +92,7 @@ spec:
value: $(tasks.t-add-fbc-fragment-to-index-image.results.genericResult)
- name: indexImageDigests
value: $(tasks.t-add-fbc-fragment-to-index-image.results.indexImageDigests)
- name: iibLog
value: $(tasks.t-add-fbc-fragment-to-index-image.results.iibLog)
- name: exitCode
value: $(tasks.t-add-fbc-fragment-to-index-image.results.exitCode)

0 comments on commit f930352

Please sign in to comment.