Skip to content

Commit 3d5c51f

Browse files
committed
tests: fix: wait for controller flip
Signed-off-by: Dr. Jan-Philip Gehrcke <[email protected]>
1 parent b172342 commit 3d5c51f

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

tests/bats/helpers.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,17 @@ get_all_cd_daemon_logs_for_cd_name() {
121121
--timestamps
122122
}
123123

124-
# Intended use case: one pod in Running state; then this function returns the
125-
# specific name of that pod.
124+
# Intended use case: one pod in Running or ContainerCreating state; then this
125+
# function returns the specific name of that pod. Specifically, ignore pods that
126+
# were just deleted or are terminating (this is important during the small time
127+
# window of restarting the controller, say in response to a deployment podspec
128+
# template mutation).
126129
get_current_controller_pod_name() {
127-
kubectl get pod -l nvidia-dra-driver-gpu-component=controller -n nvidia-dra-driver-gpu | awk '{print $1}'
130+
kubectl get pod \
131+
-l nvidia-dra-driver-gpu-component=controller \
132+
-n nvidia-dra-driver-gpu \
133+
| grep -iv "NAME" \
134+
| grep -iv 'completed' \
135+
| grep -iv 'terminating' \
136+
| awk '{print $1}'
128137
}

tests/bats/tests.bats

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ setup() {
66
_common_setup
77
}
88

9-
109
# Currently, the tests defined in this file deliberately depend on each other
1110
# and are expected to execute in the order defined. In the future, we want to
1211
# build test dependency injection (with fixtures), and work towards clean
1312
# _isolation_ between tests. To that end, we will hopefully find fast and
1413
# reliable strategies to conceptually prevent cross-contamination from
1514
# happening. Tools like `etcdctl` will be helpful.
1615

16+
# Hint: when developing/testing a specific test, for faster iteration add the
17+
# comment `# bats test_tags=bats:focus` on top of the current test. This can
18+
# help (requires the test to be self-contained though, i.e. it sets up its
19+
# dependencies' does not rely on a previous test for that).
1720

1821
# Note(JP): bats swallows output of setup upon success (regardless of cmdline
1922
# args such as `--show-output-of-passing-tests`). Ref:
@@ -59,6 +62,7 @@ log_objects() {
5962
kubectl get resourceclaims || true
6063
kubectl get computedomain || true
6164
kubectl get pods -o wide || true
65+
kubectl get pods -o wide -n nvidia-dra-driver-gpu || true
6266
}
6367

6468
# A test that covers local dev tooling, we don't want to
@@ -370,14 +374,17 @@ log_objects() {
370374
# Reconfigure (only the) log verbosity for CD daemons spawned in the future.
371375
# The deployment mutation via `set env` below is expected to restart the
372376
# controller. Wait for the old controller pod to go away (to be sure that the
373-
# new LOG_VERBOSITY_CD_DAEMON setting applies).
374-
CPOD="$(get_current_controller_pod_name)"
377+
# new LOG_VERBOSITY_CD_DAEMON setting applies), and make sure controller
378+
# deployment is still READY before moving on (make sure 1/1 READY).
379+
CPOD_OLD="$(get_current_controller_pod_name)"
375380
log_objects
376381
kubectl set env deployment nvidia-dra-driver-gpu-controller -n nvidia-dra-driver-gpu LOG_VERBOSITY_CD_DAEMON=0
377-
echo "waiting for pod $CPOD"
378-
kubectl wait --for=delete pods "$CPOD" -n nvidia-dra-driver-gpu --timeout=10s
379-
echo "done waiting"
380-
log_objects
382+
echo "wait --for=delete: $CPOD_OLD"
383+
kubectl wait --for=delete pods "$CPOD_OLD" -n nvidia-dra-driver-gpu --timeout=10s
384+
echo "returned: wait --for=delete"
385+
CPOD_NEW="$(get_current_controller_pod_name)"
386+
kubectl wait --for=condition=READY pods "$CPOD_NEW" -n nvidia-dra-driver-gpu --timeout=10s
387+
echo "new controller pod is in effect"
381388

382389
# Spawn new workload
383390
kubectl apply -f demo/specs/imex/channel-injection.yaml

0 commit comments

Comments
 (0)