forked from CentaurusInfra/mizar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kind-setup.sh
executable file
·109 lines (94 loc) · 3.45 KB
/
kind-setup.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
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# SPDX-License-Identifier: MIT
# Copyright (c) 2020 The Authors.
# Authors: Sherif Abdelwahab <@zasherif>
# Phu Tran <@phudtran>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:The above copyright
# notice and this permission notice shall be included in all copies or
# substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS",
# WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Checks for status: Provisioned for given object
function get_status() {
OBJECT=$1
kubectl get $OBJECT 2> /tmp/kubetctl.err | awk '
NR==1 {
for (i=1; i<=NF; i++) {
f[$i] = i
}
}
{ print $f["STATUS"] }
' | grep Provisioned > /dev/null
return $?
}
# Checks for status Provisioned of array of objects
function check_ready() {
objects=("droplets" "vpcs" "nets" "dividers" "bouncers")
sum=0
for i in "${objects[@]}"
do
get_status $i
let sum+=$((sum + $?))
done
if [[ $sum == 0 ]]; then
return 1
else
sleep 2
echo -n "."
return 0
fi
}
CWD=$(pwd)
KINDCONF="${HOME}/mizar/build/tests/kind/config"
MIZARCONF="${HOME}/mizar/build/tests/mizarcni.config"
KINDHOME="${HOME}/.kube/config"
USER=${1:-user}
NODES=${2:-3}
timeout=120
kind delete cluster
docker network rm kind 2> /dev/null
# All interfaces in the network have an MTU of 9000 to
# simulate a real datacenter. Since all container traffic
# goes through the docker bridge, we must ensure the bridge
# interfaces also has the same MTU to prevent ip fragmentation.
docker network create -d bridge \
--subnet=172.18.0.0/16 \
--gateway=172.18.0.1 \
--opt com.docker.network.driver.mtu=9000 \
kind
if [[ "$USER" == "dev" ]]; then
DOCKER_ACC="localhost:5000"
else
DOCKER_ACC="fwnetworking"
fi
docker image build -t $DOCKER_ACC/kindnode:latest -f k8s/kind/Dockerfile .
source k8s/kind/create_cluster.sh $KINDCONF $USER $NODES
api_ip=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' kind-control-plane`
sed "s/server: https:\/\/127.0.0.1:[[:digit:]]\+/server: https:\/\/$api_ip:6443/" $KINDCONF > $MIZARCONF
ln -snf $KINDCONF $KINDHOME
source install/create_crds.sh $CWD $USER
source install/create_service_account.sh $CWD $USER
source install/deploy_daemon.sh $CWD $USER $DOCKER_ACC
source install/deploy_operator.sh $CWD $USER $DOCKER_ACC
source install/create_testimage.sh $CWD $USER $DOCKER_ACC
end=$((SECONDS + $timeout))
echo -n "Waiting for cluster to come up."
while [[ $SECONDS -lt $end ]]; do
check_ready || break
done
echo
if [[ $SECONDS -lt $end ]]; then
echo "Cluster now ready!"
else
echo "ERROR: Cluster setup timed out after $timeout seconds!"
exit 1
fi