-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathkubeadm_test.sh
101 lines (90 loc) · 3.31 KB
/
kubeadm_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -exuo pipefail
# Get the master node IP from the yml file generated by vagrant
contiv_master=$(grep -B 3 master cluster/.cfg_kubeadm.yaml | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}" | xargs)
node_os=${CONTIV_NODE_OS:-"centos"}
# Default user is vagrant for non-ubuntu and ubuntu for ubuntu boxes.
if [ "$node_os" == "ubuntu" ]; then
def_user="ubuntu"
def_key="$HOME/.ssh/id_rsa"
else
def_user="vagrant"
def_key=""
fi
user=${CONTIV_SSH_USER:-"$def_user"}
# If BUILD_VERSION is not defined, we use a local dev build, that must have been created with make release
install_version="contiv-${BUILD_VERSION:-devbuild}"
default_net_cidr="${DEFAULT_NET:-20.1.1.0/24}"
default_net_gw="${DEFAULT_NET:-20.1.1.1}"
release_local_tarball="contiv-full-${BUILD_VERSION}.tgz"
if [ -f "release/${release_local_tarball}" ]; then
# extract docker images under shared mount direcotry
tar -xzf release/$release_local_tarball ${install_version}/contiv_cache/*.tar
pushd cluster
for vm in $(vagrant status | awk '/kubeadm/{print $1}'); do
keyfile=$(mktemp)
vagrant ssh-config $vm >$keyfile
for img in $(ls -1 ../${install_version}/contiv_cache/*.tar); do
scp -F $keyfile $img $vm:/tmp/
ssh -F $keyfile $vm -- sudo docker load -i /tmp/$(basename $img)
done
rm -f $keyfile
done
popd
pushd cluster
ssh_key=${CONTIV_SSH_KEY:-"$def_key"}
if [ "$ssh_key" == "" ]; then
ssh_key=$(vagrant ssh-config kubeadm-master | grep IdentityFile | awk '{print $2}' | xargs)
fi
popd
dest_path=${CONTIV_TARGET:-"/home/$user"}
ssh_opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
# Copy the installation folder
scp $ssh_opts -i $ssh_key release/${release_local_tarball} $user@$contiv_master:$dest_path/${install_version}.tgz
curl_cmd="echo 'Devbuild'"
else
# github redirects you to a signed AWS URL, so we need to follow redirects with -L
curl_cmd="curl -L -O https://github.com/contiv/install/releases/download/${BUILD_VERSION}/${install_version}.tgz"
fi
# Extract the install bundle and launch the installer
set +e # read returns 1 when it succeeds
read -r -d '' COMMANDS <<-EOF
sudo rm -rf ${install_version} && \\
${curl_cmd} && tar oxf ${install_version}.tgz && \\
cd ${install_version} && \\
sudo ./install/k8s/install.sh -n ${contiv_master}
EOF
set -e
cd cluster
vagrant ssh kubeadm-master -- "$COMMANDS"
set +e
read -r -d '' SETUP_DEFAULT_NET <<-EOF
cd ${install_version} && \\
netctl net create -s ${default_net_cidr} -g ${default_net_gw} default-net
EOF
set -e
echo "*****************"
# Wait for CONTIV to start for up to 10 minutes
sleep 10
for i in {0..20}; do
response=$(curl -k -s -H "Content-Type: application/json" -X POST -d '{"username": "admin", "password": "admin"}' https://$contiv_master:10000/api/v1/auth_proxy/#/ || true)
if [[ $response == *"token"* ]]; then
echo "Install SUCCESS"
echo ""
cat <<EOF
NOTE: Because the Contiv Admin Console is using a self-signed certificate for this demo,
you will see a security warning when the page loads. You can safely dismiss it.
You can access the Contiv master node with:
cd cluster && vagrant ssh kubeadm-master
EOF
if [ "$install_version" != "contiv-devbuild" ]; then
vagrant ssh kubeadm-master -- "${SETUP_DEFAULT_NET}"
fi
exit 0
else
echo "$i. Retry login to Contiv"
sleep 30
fi
done
echo "Install FAILED"
exit 1