Skip to content

Commit 2d8eb92

Browse files
committed
Added error checks for 'curl' calls. Rename variables to use lower case.
1 parent db72f42 commit 2d8eb92

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

hack/run-e2e-kind.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -373,41 +373,53 @@ function setup-mcad-env {
373373
do
374374
echo -n "." && sleep 1;
375375
done
376-
377376
}
378377

379378
function extend-resources {
380379
# Patch nodes to provide GPUs resources without physical GPUs.
381380
# This is intended to allow testing of GPU specific features such as histograms.
382381

383382
# Start communication with cluster
384-
echo -n "Starting proxy "
385-
386383
kubectl proxy > /dev/null 2>&1 &
387-
PROXY_PID=$!
384+
proxy_pid=$!
385+
386+
echo "Starting background proxy connection (pid=${proxy_pid})..."
387+
388+
curl 127.0.0.1:8001 > /dev/null 2>&1
389+
390+
if [[ ! $? -eq 0 ]]; then
391+
echo "Calling 'kubectl proxy' did not create a successful connection to the kubelet needed to patch the nodes. Exiting."
392+
exit 1
393+
else
394+
echo "Connected to the kubelet for patching the nodes"
395+
fi
388396

389-
echo "(pid=${PROXY_PID})..."
390397

391398
# Variables
392-
RESOURCE_NAME="nvidia.com~1gpu"
393-
RESOURCE_COUNT="8"
399+
resource_name="nvidia.com~1gpu"
400+
resource_count="8"
394401

395402
# Patch nodes
396-
for NODE_NAME in $(kubectl get nodes --no-headers -o custom-columns=":metadata.name")
403+
for node_name in $(kubectl get nodes --no-headers -o custom-columns=":metadata.name")
397404
do
398-
echo "- Patching node (add): ${NODE_NAME}"
405+
echo "- Patching node (add): ${node_name}"
406+
407+
patching_status=$(curl --header "Content-Type: application/json-patch+json" \
408+
--request PATCH \
409+
--data '[{"op": "add", "path": "/status/capacity/'${resource_name}'", "value": "'${resource_count}'"}]' \
410+
http://localhost:8001/api/v1/nodes/${node_name}/status | jq -r '.status')
399411

400-
curl --header "Content-Type: application/json-patch+json" \
401-
--request PATCH \
402-
--data '[{"op": "add", "path": "/status/capacity/'${RESOURCE_NAME}'", "value": "'${RESOURCE_COUNT}'"}]' \
403-
http://localhost:8001/api/v1/nodes/${NODE_NAME}/status
412+
if [[ ${patching_status} = "Failure" ]]; then
413+
echo "Failed to patch node '${node_name}' with GPU resources"
414+
exit 1
415+
fi
404416

405417
echo
406418
done
407419

408420
# Stop communication with cluster
409-
echo "Killing proxy (pid=${PROXY_PID})..."
410-
kill ${PROXY_PID}
421+
echo "Killing proxy (pid=${proxy_pid})..."
422+
kill -9 ${proxy_pid}
411423

412424
# Run kuttl tests to confirm GPUs were added correctly
413425
kuttl_test="${ROOT_DIR}/test/kuttl-test-extended-resources.yaml"

0 commit comments

Comments
 (0)