3
load ../system/helpers.bash
5
KUBECONFIG="$HOME/.kube/config"
8
# run_minikube # Local helper, with instrumentation for debugging failures
10
function run_minikube() {
11
# Number as first argument = expected exit code; default 0
14
[0-9]) expected_rc=$1; shift;;
15
[1-9][0-9]) expected_rc=$1; shift;;
16
[12][0-9][0-9]) expected_rc=$1; shift;;
17
'?') expected_rc= ; shift;; # ignore exit code
20
# stdout is only emitted upon error; this printf is to help in debugging
21
printf "\n%s %s %s %s\n" "$(timestamp)" "\$" "minikube" "$*"
23
# without "quotes", multiple lines are glommed together into one
24
if [[ -n "$output" ]]; then
25
echo "$(timestamp) $output"
27
if [[ "$status" -ne 0 ]]; then
28
echo -n "$(timestamp) [ rc=$status ";
29
if [[ -n "$expected_rc" ]]; then
30
if [[ "$status" -eq "$expected_rc" ]]; then
31
echo -n "(expected) ";
33
echo -n "(** EXPECTED $expected_rc **) ";
39
if [[ -n "$expected_rc" ]]; then
40
if [[ "$status" -ne "$expected_rc" ]]; then
42
echo "\$ minikube logs"
46
die "exit code is $status; expected $expected_rc"
53
# only set up the minikube cluster before the first test
54
if [[ "$BATS_TEST_NUMBER" -eq 1 ]]; then
62
# only delete the minikube cluster if we are done with the last test
63
# the $DEBUG_MINIKUBE env can be set to preserve the cluster to debug if needed
64
if [[ "$BATS_TEST_NUMBER" -eq ${#BATS_TEST_NAMES[@]} ]] && [[ "$DEBUG_MINIKUBE" == "" ]]; then
68
# Prevents nasty red warnings in log
69
run_podman rmi --ignore $(pause_image)
74
function wait_for_default_sa(){
77
# timeout after 30 seconds
78
# if the default service account hasn't been created yet, there is something else wrong
79
while [[ $count -lt 30 ]] && [[ $sa_ready == false ]]
81
run_minikube kubectl get sa
82
if [[ "$output" != "No resources found in default namespace." ]]; then
88
if [[ $sa_ready == false ]]; then
89
die "Timed out waiting for default service account to be created"
93
function wait_for_pods_to_start(){
96
# timeout after 30 seconds
97
# if the pod hasn't started running after 30 seconds, there is something else wrong
98
while [[ $count -lt 30 ]] && [[ $running == false ]]
100
run_minikube kubectl get pods
101
assert "$status" -eq 0
102
if [[ "$output" =~ "Running" ]]; then
108
if [[ $running == false ]]; then
109
die "Timed out waiting for pod to move to 'Running' state"