This repository was archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfake-k8s.test.sh
executable file
·85 lines (72 loc) · 2.06 KB
/
fake-k8s.test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
# Gets the release from the argument
releases=()
while [[ $# -gt 0 ]]; do
releases+=("${1}")
shift
done
function test_release() {
local release="${1}"
local name="cluster-${release//./-}"
local targets
local i
KUBE_VERSION="${release}" ./fake-k8s create cluster --name "${name}" --quiet-pull --prometheus-port 9090
for ((i = 0; i < 30; i++)); do
./fake-k8s --name "${name}" kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: fake-pod
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: fake-pod
template:
metadata:
labels:
app: fake-pod
spec:
containers:
- name: fake-pod
image: fake
EOF
if ./fake-k8s --name="${name}" kubectl get pod 2>/dev/null | grep Running >/dev/null 2>&1; then
break
fi
sleep 1
done
echo kubectl --context="fake-k8s-${name}" config view --minify
./fake-k8s --name="${name}" kubectl config view --minify
echo kubectl --context="fake-k8s-${name}" get pod
./fake-k8s --name="${name}" kubectl get pod
if ! ./fake-k8s --name="${name}" kubectl get pod | grep Running >/dev/null 2>&1; then
echo "=== release ${release} is not works ==="
failed+=("${release}_not_works")
./fake-k8s --name="${name}" logs kube-apiserver
fi
for ((i = 0; i < 30; i++)); do
targets="$(curl -s http://127.0.0.1:9090/api/v1/targets | jq -r '.data.activeTargets[] | "\(.health) \(.scrapePool)"')"
if [[ "$(echo "${targets}" | grep "^up " | wc -l)" -eq "6" ]]; then
break
fi
sleep 1
done
echo "${targets}"
if ! [[ "$(echo "${targets}" | grep "^up " | wc -l)" -eq "6" ]]; then
echo "=== prometheus of release ${release} is not works ==="
failed+=("${release}_prometheus_not_works")
fi
./fake-k8s delete cluster --name "${name}" >/dev/null 2>&1 &
}
failed=()
for release in "${releases[@]}"; do
time test_release "${release}"
done
if [ "${#failed[*]}" -eq 0 ]; then
echo "=== All releases are works ==="
else
echo "=== Failed releases: ${failed[*]} ==="
exit 1
fi