Skip to content

Commit bddacfe

Browse files
committed
Refactor the boskos flow in periodic-kubernetes-containerd-conformance-test-ppc64le job
1 parent c768ebd commit bddacfe

File tree

1 file changed

+26
-52
lines changed

1 file changed

+26
-52
lines changed

config/jobs/periodic/kubernetes/test-kubernetes-periodics.yaml

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ periodics:
9494
env:
9595
- name: "BOSKOS_HOST"
9696
value: "boskos.test-pods.svc.cluster.local"
97+
- name: "USER"
98+
value: "periodic-k8s-containerd-conformance-job"
9799
resources:
98100
requests:
99101
memory: "5Gi"
@@ -112,20 +114,13 @@ periodics:
112114
113115
export PATH=$GOPATH/bin:$PATH
114116
export GO111MODULE=on
115-
117+
source "./hack/boskos.sh"
116118
117119
make install-deployer-tf
118120
TF_LATEST="v1.9.8"
119-
120121
RESOURCE_TYPE="powervs-k8s-conformance"
121-
USER="periodic-k8s-containerd-conformance-job"
122-
123-
trap cleanup EXIT
124122
125-
cleanup(){
126-
# stop the boskos heartbeat
127-
[[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}" || true
128-
}
123+
trap 'cleanup ${HEART_BEAT_PID:-}' EXIT
129124
130125
curl -fsSL https://releases.hashicorp.com/terraform/${TF_LATEST:1}/terraform_${TF_LATEST:1}_linux_amd64.zip -o ./terraform.zip
131126
unzip -o ./terraform.zip >/dev/null 2>&1
@@ -148,46 +143,32 @@ periodics:
148143
TIMESTAMP=$(date +%s)
149144
jq --arg key0 'k8s-build-version' --arg value0 $K8S_BUILD_VERSION '. | .[$key0]=$value0' <<<'{}' > $ARTIFACTS/metadata.json
150145
151-
152146
set +o errexit
147+
# If BOSKOS_HOST is set then acquire a resource from Boskos.
148+
if [ -n "${BOSKOS_HOST:-}" ]; then
149+
# Check out the resource from Boskos and store the produced environment
150+
# variables in a temporary file.
151+
account_env_var_file="$(mktemp)"
152+
checkout_account ${RESOURCE_TYPE} 1> "${account_env_var_file}"
153+
checkout_account_status="${?}"
153154
154-
heartbeat_account(){
155-
count=0
156-
url="http://${BOSKOS_HOST}/update?name=${BOSKOS_RESOURCE_NAME}&state=busy&owner=${USER}"
157-
while [ ${count} -lt 120 ]
158-
do
159-
status_code=$(curl -s -o /dev/null -w '%{http_code}' -X POST ${url})
160-
if [[ ${status_code} != 200 ]]; then
161-
echo "Heart beat to resource '${BOSKOS_RESOURCE_NAME}' failed due to invalid response, status code: ${status_code}"
162-
exit 1
163-
fi
164-
count=$(( $count + 1 ))
165-
sleep 60
166-
done
167-
}
155+
# If the checkout process was a success then load the
156+
# environment variables into this process.
157+
[ "${checkout_account_status}" = "0" ] && . "${account_env_var_file}"
168158
169-
if [ -n "${BOSKOS_HOST:-}" ]; then
170-
set +o xtrace
171-
url="http://${BOSKOS_HOST}/acquire?type=${RESOURCE_TYPE}&state=free&dest=busy&owner=${USER}"
172-
output=$(curl -X POST ${url})
173-
[ $? = 0 ] && status_code=200
159+
# Always remove the account environment variable file which
160+
# could contain sensitive information.
161+
rm -f "${account_env_var_file}"
174162
175-
if [[ ${status_code} == 200 && ${output} =~ "failed" ]]; then
176-
echo "Failed to acquire resource from Boskos of type ${RESOURCE_TYPE}"
177-
exit 1
178-
elif [[ ${status_code} == 200 ]]; then
179-
export BOSKOS_RESOURCE_NAME=$(echo ${output} | jq -r '.name')
180-
export BOSKOS_REGION=$(echo ${output} | jq -r '.userdata["region"]')
181-
export BOSKOS_RESOURCE_ID=$(echo ${output} | jq -r '.userdata["service-instance-id"]')
182-
export BOSKOS_ZONE=$(echo ${output} | jq -r '.userdata["zone"]')
183-
rm -rf output.json
184-
else
185-
echo "Failed to acquire resource due to invalid response, status code : ${status_code}"
186-
exit 1
187-
fi
163+
if [ ! "${checkout_account_status}" = "0" ]; then
164+
echo "error getting account from boskos" 1>&2
165+
exit "${checkout_account_status}"
166+
fi
188167
189-
heartbeat_account >> "$ARTIFACTS/boskos.log" 2>&1 &
190-
HEART_BEAT_PID=$(echo $!)
168+
# Run the heart beat process to tell Boskos that we are still
169+
# using the checked out resource periodically.
170+
heartbeat_account >> "$ARTIFACTS/boskos.log" 2>&1 &
171+
HEART_BEAT_PID=$(echo $!)
191172
fi
192173
193174
set -o xtrace
@@ -226,14 +207,7 @@ periodics:
226207
exit $rc2
227208
fi
228209
229-
if [ -n "${BOSKOS_HOST:-}" ]; then
230-
url="http://${BOSKOS_HOST}/release?name=${BOSKOS_RESOURCE_NAME}&dest=dirty&owner=${USER}"
231-
status_code=$(curl -w '%{http_code}' -X POST ${url})
232-
if [[ ${status_code} != 200 ]]; then
233-
echo "Failed to release resource: ${BOSKOS_RESOURCE_NAME}"
234-
exit 1
235-
fi
236-
fi
210+
[ -z "${BOSKOS_HOST:-}" ] || release_account >> "$ARTIFACTS/boskos.log" 2>&1
237211
238212
- name: periodic-kubernetes-containerd-e2e-node-tests-ppc64le
239213
labels:

0 commit comments

Comments
 (0)