-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# wait_kubeapi [RETRIES] | ||
# wait_kubeapi 30 | ||
wait_kubeapi() { | ||
# Wait for Kubernetes API to be available | ||
command -v kubectl >/dev/null 2>&1 || { error "This function requires kubectl to be installed."; return 1; } | ||
local retries="${1:-30}" | ||
echo -n "Connecting to Kubernetes API" | ||
for (( i=0;; i++ )); do | ||
if [[ ${i} -eq "${retries}" ]]; then | ||
echo " timeout!" | ||
return 99 | ||
fi | ||
sleep 1 | ||
(kubectl version) &>/dev/null && break | ||
echo -n "." | ||
done | ||
echo " connected." | ||
exec 3>&- | ||
exec 3<&- | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bats | ||
|
||
source ../functions/10-common.sh | ||
source ../functions/wait_kubeapi.sh | ||
|
||
@test "wait_kubeapi: connecting to mock kubeapi" { | ||
kubectl() { | ||
echo "Mocked kubectl command" | ||
sleep 1 | ||
} | ||
run wait_kubeapi 5 | ||
[ "$status" -eq 0 ] | ||
[[ "${lines[0]}" == "Connecting to Kubernetes API"* ]] | ||
} | ||
|
||
@test "wait_kubeapi: timeout connecting mock kubeapi" { | ||
kubectl() { | ||
echo "Mocked kubectl command" | ||
exit 1 | ||
} | ||
run wait_kubeapi 1 | ||
[ "$status" -eq 99 ] | ||
[[ "${lines[0]}" == *". timeout!" ]] | ||
} |