-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-check-minikube-infra-connectivity.sh
executable file
·64 lines (51 loc) · 1.85 KB
/
01-check-minikube-infra-connectivity.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
#!/usr/bin/env bash
. common.sh
my-kubectl_pod_running() {
local context=$1
podstatus=$(kubectl --context=$context get pod my-kubectl -o jsonpath='{.status.phase}')
if [[ "${podstatus}" == "Running" ]]
then
echo "0"
return
fi
echo "1"
}
kubectl config view --flatten > kubeconfig
([ $? -eq 0 ] && log::info "generated kubeconfig") || log::error "Could not generate kubeconfig"
log::info "kubeconfig -> $(pwd)/kubeconfig"
for CLUSTERNAME in "${clusters[@]}"; do
# kubectl --context=${CLUSTERNAME} create -f my-kubectl.yaml;
cat <<'EOF' | kubectl --context=${CLUSTERNAME} create -f -
apiVersion: v1
kind: Pod
metadata:
name: my-kubectl
namespace: default
spec:
containers:
- name: my-kubectl
image: busybox
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always
EOF
wait_until "pod_in_namespace_for_context_is_running my-kubectl default ${CLUSTERNAME}" 10 45
done
for CLUSTERNAME in "${clusters[@]}"
do
kubectl --context ${CLUSTERNAME} cp kubeconfig my-kubectl:kubeconfig;
([ $? -eq 0 ] && log::info "kubeconfig copied into my-kubectl in ${CLUSTERNAME}") || ( log::error "Couldn't copy kubeconfig in ${CLUSTERNAME}" && exit -1; )
kubectl --context ${CLUSTERNAME} cp $(readlink -e $(which kubectl)) my-kubectl:kubectl;
([ $? -eq 0 ] && log::info "kubectl copied to my-kubectl in ${CLUSTERNAME} ") || ( log::error "Couldn't copy kubectl in ${CLUSTERNAME}" && exit -1; )
done
for((i=0;i<${#clusters[@]};i++))
do for((j=0;j<${#clusters[@]};j++))
do [ "${clusters[$i]}" != "${clusters[$j]}" ] && kubectl --context=${clusters[$i]} exec -it my-kubectl -- /kubectl --kubeconfig=/kubeconfig --context=${clusters[$j]} cluster-info
done
done
for((i=0;i<${#clusters[@]};i++))
do
kubectl --context=${clusters[$i]} delete pod my-kubectl --wait=false;
done