Skip to content
This repository was archived by the owner on Dec 3, 2021. It is now read-only.

Commit 537cf70

Browse files
committed
Move container commands into separate file and correct resume issue.
1 parent 7032026 commit 537cf70

File tree

4 files changed

+116
-41
lines changed

4 files changed

+116
-41
lines changed

Vagrantfile

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Vagrant.configure("2") do |config|
108108

109109
# Copy selfmedicate and the manifests folder to the VM.
110110
config.vm.provision "file", source: "selfmedicate.sh", destination: "$HOME/selfmedicate.sh"
111+
config.vm.provision "file", source: "container-start.sh", destination: "$HOME/container-start.sh"
111112
config.vm.provision "file", source: "manifests", destination: "$HOME/manifests"
112113

113114
# Provisioning antidote vagrant vm

container-start.sh

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
PROGNAME=$(basename $0)
4+
SUBCOMMAND=$1
5+
6+
RED='\033[31m'
7+
GREEN='\033[32m'
8+
YELLOW='\033[33m'
9+
WHITE='\033[37m'
10+
NC='\033[0m'
11+
12+
KUBECTL=${KUBECTL:="kubectl"}
13+
14+
sub_run(){
15+
$KUBECTL apply -f "https://cloud.weave.works/k8s/net?k8s-version=$($KUBECTL version | base64 | tr -d '\n')"
16+
$KUBECTL create -f manifests/multusinstall.yml
17+
sub_wait_system
18+
19+
$KUBECTL create -f manifests/nginx-controller.yaml > /dev/null
20+
$KUBECTL create -f manifests/syringe-k8s.yaml > /dev/null
21+
$KUBECTL create -f manifests/antidote-web.yaml > /dev/null
22+
sub_wait_platform
23+
}
24+
print_progress() {
25+
percentage=$1
26+
chars=$(echo "40 * $percentage"/1| bc)
27+
v=$(printf "%-${chars}s" "#")
28+
s=$(printf "%-$((40 - chars))s")
29+
echo "${v// /#}""${s// /-}"
30+
}
31+
32+
sub_wait_system(){
33+
running_system_pods=0
34+
total_system_pods=$($KUBECTL get pods -n=kube-system | tail -n +2 | wc -l)
35+
while [ $running_system_pods -lt $total_system_pods ]
36+
do
37+
running_system_pods=$($KUBECTL get pods -n=kube-system | grep Running | wc -l)
38+
percentage="$( echo "$running_system_pods/$total_system_pods" | bc -l )"
39+
echo -ne $(print_progress $percentage) "${YELLOW}Installing additional infrastructure components...${NC}\r"
40+
sleep 5
41+
done
42+
43+
# Clear line and print finished progress
44+
echo -ne "$pc%\033[0K\r"
45+
echo -ne $(print_progress 1) "${GREEN}Done.${NC}\n"
46+
}
47+
48+
sub_wait_platform(){
49+
running_platform_pods=0
50+
total_platform_pods=$($KUBECTL get pods | tail -n +2 | wc -l)
51+
while [ $running_platform_pods -lt $total_platform_pods ]
52+
do
53+
running_platform_pods=$($KUBECTL get pods | grep Running | wc -l)
54+
percentage="$( echo "$running_platform_pods/$total_platform_pods" | bc -l )"
55+
echo -ne $(print_progress $percentage) "${YELLOW}Starting the antidote platform...${NC}\r"
56+
sleep 5
57+
done
58+
59+
# Clear line and print finished progress
60+
echo -ne "$pc%\033[0K\r"
61+
echo -ne $(print_progress 1) "${GREEN}Done.${NC}\n"
62+
}
63+
64+
sub_help(){
65+
echo "Usage: $PROGNAME <subcommand> [options]"
66+
echo "Subcommands:"
67+
echo " run Start the Antidote containers"
68+
echo " wait_system Reload Antidote components"
69+
echo " wait_platform Stop local instance of Antidote"
70+
echo " resume Resume stopped Antidote instance"
71+
echo ""
72+
echo "options:"
73+
echo "-h show brief help"
74+
echo ""
75+
echo "For help with each subcommand run:"
76+
echo "$PROGNAME <subcommand> -h|--help"
77+
echo ""
78+
}
79+
80+
while getopts "h" OPTION
81+
do
82+
case $OPTION in
83+
h)
84+
sub_help
85+
exit
86+
;;
87+
\?)
88+
sub_help
89+
exit
90+
;;
91+
esac
92+
done
93+
94+
# Direct to appropriate subcommand
95+
subcommand=$1
96+
case $subcommand in
97+
"")
98+
sub_help
99+
;;
100+
*)
101+
shift
102+
sub_${subcommand} $@
103+
if [ $? = 127 ]; then
104+
echo "Error: '$subcommand' is not a known subcommand." >&2
105+
echo " Run '$PROGNAME --help' for a list of known subcommands." >&2
106+
exit 1
107+
fi
108+
;;
109+
esac
110+
111+
exit 0

selfmedicate.sh

+3-41
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ sub_resume(){
6868
--extra-config=kubelet.network-plugin=cni \
6969
--kubernetes-version=$K8SVERSION
7070

71+
bash container-start.sh wait_system
72+
bash container-start.sh wait_platform
7173
echo -e "${GREEN}Finished!${NC} Antidote should now be available at http://antidote-local:30001/"
7274
}
7375

@@ -127,48 +129,8 @@ sub_start(){
127129

128130
sudo chown -R $USER $HOME/.kube $HOME/.minikube
129131

130-
$KUBECTL apply -f "https://cloud.weave.works/k8s/net?k8s-version=$($KUBECTL version | base64 | tr -d '\n')"
131-
$KUBECTL create -f manifests/multusinstall.yml
132-
133-
print_progress() {
134-
percentage=$1
135-
chars=$(echo "40 * $percentage"/1| bc)
136-
v=$(printf "%-${chars}s" "#")
137-
s=$(printf "%-$((40 - chars))s")
138-
echo "${v// /#}""${s// /-}"
139-
}
140-
141-
running_system_pods=0
142-
total_system_pods=$($KUBECTL get pods -n=kube-system | tail -n +2 | wc -l)
143-
while [ $running_system_pods -lt $total_system_pods ]
144-
do
145-
running_system_pods=$($KUBECTL get pods -n=kube-system | grep Running | wc -l)
146-
percentage="$( echo "$running_system_pods/$total_system_pods" | bc -l )"
147-
echo -ne $(print_progress $percentage) "${YELLOW}Installing additional infrastructure components...${NC}\r"
148-
sleep 5
149-
done
150-
151-
# Clear line and print finished progress
152-
echo -ne "$pc%\033[0K\r"
153-
echo -ne $(print_progress 1) "${GREEN}Done.${NC}\n"
154-
155-
$KUBECTL create -f manifests/nginx-controller.yaml > /dev/null
156-
$KUBECTL create -f manifests/syringe-k8s.yaml > /dev/null
157-
$KUBECTL create -f manifests/antidote-web.yaml > /dev/null
158-
159-
running_platform_pods=0
160-
total_platform_pods=$($KUBECTL get pods | tail -n +2 | wc -l)
161-
while [ $running_platform_pods -lt $total_platform_pods ]
162-
do
163-
running_platform_pods=$($KUBECTL get pods | grep Running | wc -l)
164-
percentage="$( echo "$running_platform_pods/$total_platform_pods" | bc -l )"
165-
echo -ne $(print_progress $percentage) "${YELLOW}Starting the antidote platform...${NC}\r"
166-
sleep 5
167-
done
132+
bash container-start.sh run
168133

169-
# Clear line and print finished progress
170-
echo -ne "$pc%\033[0K\r"
171-
echo -ne $(print_progress 1) "${GREEN}Done.${NC}\n"
172134
# Moved antidote up message to before image pull due to docker timeout issues.
173135
echo -e "${GREEN}Finished!${NC} Antidote should now be available at http://antidote-local:30001/"
174136

vagrant-provision.sh

+1
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,5 @@ install_minikube
147147
export CHANGE_MINIKUBE_NONE_USER
148148
echo "export CHANGE_MINIKUBE_NONE_USER=true" >> /etc/profile.d/vagrant.sh
149149
chmod +x /home/vagrant/selfmedicate.sh
150+
chmod +x /home/vagrant/container-start.sh
150151
echo "done"

0 commit comments

Comments
 (0)