Skip to content

Commit 2fdcb58

Browse files
authored
Merge pull request #53 from Amulyam24/boskos-log
Improve logging for Boskos operations
2 parents 9d1341c + 6503aef commit 2fdcb58

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

hack/boskos.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,40 @@ set -o pipefail
2121
USER=${USER:-"k8s-prow-job"}
2222
RESOURCE_TYPE=${RESOURCE_TYPE:-"powervs"}
2323

24+
error() {
25+
echo "$@" >&2
26+
exit 1
27+
}
28+
2429
trap 'cleanup ${HEART_BEAT_PID:-}' EXIT
2530

2631
release_account(){
2732
url="http://${BOSKOS_HOST}/release?name=${BOSKOS_RESOURCE_NAME}&dest=dirty&owner=${USER}"
2833
status_code=$(curl -w '%{http_code}' -X POST ${url})
2934

3035
if [[ ${status_code} != 200 ]]; then
31-
echo "Failed to release resource: ${BOSKOS_RESOURCE_NAME}"
32-
exit 1
33-
fi
36+
error "Failed to release resource ${BOSKOS_RESOURCE_NAME} of type ${RESOURCE_TYPE} used by ${USER}"
37+
fi
38+
39+
echo "Successfully released resource ${BOSKOS_RESOURCE_NAME} of type ${RESOURCE_TYPE}, previously used by ${USER}"
3440
}
3541

3642
checkout_account(){
3743
resource_type=$1
38-
set +o xtrace
44+
set +o xtrace # Disable debug before checkout
3945
url="http://${BOSKOS_HOST}/acquire?type=${resource_type}&state=free&dest=busy&owner=${USER}"
4046
output=$(curl -X POST ${url})
4147
[ $? = 0 ] && status_code=200
4248

4349
if [[ ${status_code} == 200 && ${output} =~ "failed" ]]; then
44-
echo "Failed to acquire resource from Boskos of type ${RESOURCE_TYPE}"
45-
exit 1
50+
error "Failed to acquire free resource of type ${RESOURCE_TYPE}"
4651
elif [[ ${status_code} == 200 ]]; then
4752
export BOSKOS_RESOURCE_NAME=$(echo ${output} | jq -r '.name')
4853
export BOSKOS_REGION=$(echo ${output} | jq -r '.userdata["region"]')
4954
export BOSKOS_RESOURCE_ID=$(echo ${output} | jq -r '.userdata["service-instance-id"]')
5055
export BOSKOS_ZONE=$(echo ${output} | jq -r '.userdata["zone"]')
5156
else
52-
echo "Failed to acquire resource due to invalid response, status code : ${status_code}"
53-
exit 1
57+
error "Failed to acquire free resource of type ${RESOURCE_TYPE} due to invalid response, status code : ${status_code}"
5458
fi
5559
}
5660

@@ -61,10 +65,10 @@ heartbeat_account(){
6165
do
6266
status_code=$(curl -s -o /dev/null -w '%{http_code}' -X POST ${url})
6367
if [[ ${status_code} != 200 ]]; then
64-
echo "Heart beat to resource '${BOSKOS_RESOURCE_NAME}' failed due to invalid response, status code: ${status_code}"
65-
exit 1
68+
error "Heart beat to resource '${BOSKOS_RESOURCE_NAME}' failed due to invalid response, status code: ${status_code}"
6669
fi
6770
count=$(( $count + 1 ))
71+
echo "Resource ${BOSKOS_RESOURCE_NAME} of type ${RESOURCE_TYPE} is currently being used by ${USER}"
6872
sleep 60
6973
done
7074
}
@@ -90,6 +94,7 @@ checkout_account_status=$?
9094
# If checkout is successful, source the environment variables
9195
if [ "$checkout_account_status" -eq 0 ]; then
9296
source "${account_env_var_file}"
97+
echo "Successfully acquired free resource ${BOSKOS_RESOURCE_NAME} of type ${RESOURCE_TYPE} by user ${USER}"
9398
else
9499
echo "Error getting account from Boskos" 1>&2
95100
rm -f "${account_env_var_file}"

0 commit comments

Comments
 (0)