podman

Форк
0
/
helpers.bash 
111 строк · 3.2 Кб
1
# -*- bash -*-
2

3
load ../system/helpers.bash
4

5
KUBECONFIG="$HOME/.kube/config"
6

7
##################
8
#  run_minikube  #  Local helper, with instrumentation for debugging failures
9
##################
10
function run_minikube() {
11
    # Number as first argument = expected exit code; default 0
12
    local expected_rc=0
13
    case "$1" in
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
18
    esac
19

20
    # stdout is only emitted upon error; this printf is to help in debugging
21
    printf "\n%s %s %s %s\n" "$(timestamp)" "\$" "minikube" "$*"
22
    run minikube "$@"
23
    # without "quotes", multiple lines are glommed together into one
24
    if [[ -n "$output" ]]; then
25
        echo "$(timestamp) $output"
26
    fi
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) ";
32
            else
33
                echo -n "(** EXPECTED $expected_rc **) ";
34
            fi
35
        fi
36
        echo "]"
37
    fi
38

39
    if [[ -n "$expected_rc" ]]; then
40
        if [[ "$status" -ne "$expected_rc" ]]; then
41
            # Further debugging
42
            echo "\$ minikube logs"
43
            run minikube logs
44
            echo "$output"
45

46
            die "exit code is $status; expected $expected_rc"
47
        fi
48
    fi
49
}
50

51

52
function setup(){
53
    # only set up the minikube cluster before the first test
54
    if [[ "$BATS_TEST_NUMBER" -eq 1 ]]; then
55
        run_minikube start
56
        wait_for_default_sa
57
    fi
58
    basic_setup
59
}
60

61
function teardown(){
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
65
        run_minikube delete
66
    fi
67

68
    # Prevents nasty red warnings in log
69
    run_podman rmi --ignore $(pause_image)
70

71
    basic_teardown
72
}
73

74
function wait_for_default_sa(){
75
    count=0
76
    sa_ready=false
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 ]]
80
    do
81
        run_minikube kubectl get sa
82
        if [[ "$output" != "No resources found in default namespace." ]]; then
83
            sa_ready=true
84
        fi
85
        count=$((count + 1))
86
        sleep 1
87
    done
88
    if [[ $sa_ready == false ]]; then
89
        die "Timed out waiting for default service account to be created"
90
    fi
91
}
92

93
function wait_for_pods_to_start(){
94
    count=0
95
    running=false
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 ]]
99
    do
100
        run_minikube kubectl get pods
101
        assert "$status" -eq 0
102
        if [[ "$output" =~ "Running" ]]; then
103
            running=true
104
        fi
105
        count=$((count + 1))
106
        sleep 1
107
    done
108
    if [[ $running == false ]]; then
109
        die "Timed out waiting for pod to move to 'Running' state"
110
    fi
111
}
112

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.