This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
e2e.sh
executable file
·98 lines (76 loc) · 3.16 KB
/
e2e.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
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
set -Eeuxo pipefail
cluster="init"
prepare_host() {
sudo apt -y update
sudo apt -y install linux-modules-extra-$(uname -r)
sudo mount --make-shared /sys
sudo mount --make-shared /
sudo mount --make-shared /dev
}
run_kind() {
echo "Download kind binary..."
wget -O kind 'https://kind.sigs.k8s.io/dl/v0.8.1/kind-linux-amd64' --no-check-certificate && chmod +x kind && sudo mv kind /usr/local/bin/
echo "Download kubectl..."
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/"${K8S_VERSION}"/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
echo
if [ $(kind get clusters | grep -c ^$cluster$) -eq 0 ]; then
echo "Create Kubernetes cluster with kind..."
# kind create cluster --image=kindest/node:"$K8S_VERSION"
kind create cluster --image storageos/kind-node:"$K8S_VERSION" --name "$cluster"
fi
echo "Export kubeconfig..."
kind get kubeconfig --name="$cluster" > kubeconfig.yaml
export KUBECONFIG="kubeconfig.yaml"
echo
echo "Get cluster info..."
kubectl cluster-info
echo
echo "Wait for kubernetes to be ready"
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done
echo
}
main() {
make test
make docker-build
prepare_host
run_kind
echo "Ready for e2e testing"
echo
echo "Prepare for k8s test"
echo
# Copy the init container image into KinD.
x=$(docker ps -f name=${cluster}-control-plane -q)
docker save storageos/init:test > init.tar
docker cp init.tar $x:/init.tar
# containerd load image from tar archive (KinD with containerd).
docker exec $x bash -c "ctr -n k8s.io images import --base-name docker.io/storageos/init:test /init.tar"
# Use busybox in place of the node container.
docker pull busybox:1.32
docker save busybox:1.32 > busybox.tar
docker cp busybox.tar $x:/busybox.tar
docker exec $x bash -c "ctr -n k8s.io images import --base-name docker.io/busybox:1.32 /busybox.tar"
# Create storageos daemonset with node v1.5.3
kubectl apply -f daemonset.yaml
sleep 5
# Get pod name.
stospod=$(kubectl get pods --template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep storageos)
echo "Waiting for the storageos pod to be ready"
until kubectl get pod $stospod --template='{{ (index .status.containerStatuses 0).ready }}' | grep -q true; do sleep 5; done
# until kubectl get pod $stospod --no-headers -o go-template='{{.status.phase}}' | grep -q Running; do sleep 5; done
echo "storageos pod found ready"
echo
echo "init container logs:"
kubectl logs $stospod -c storageos-init
echo
echo "Checking init container exit code"
exitCode=$(kubectl get pod $stospod --no-headers -o go-template='{{(index .status.initContainerStatuses 0).state.terminated.exitCode}}')
kubectl delete -f daemonset.yaml
if [ "$exitCode" == "0" ]; then
echo "init successful!"
exit 0
fi
echo "init failed"
exit 1
}
main