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

Commit 2a3515a

Browse files
committed
Merge branch 'seperate_scripts' of git://github.com/smk4664/antidote-selfmedicate into smk4664-seperate_scripts
2 parents 20e3e1c + 537cf70 commit 2a3515a

File tree

4 files changed

+119
-46
lines changed

4 files changed

+119
-46
lines changed

Vagrantfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ Vagrant.configure("2") do |config|
110110

111111
# Copy selfmedicate and the manifests folder to the VM.
112112
config.vm.provision "file", source: "selfmedicate.sh", destination: "$HOME/selfmedicate.sh"
113-
#config.vm.provision "file", source: "manifests", destination: "$HOME/manifests"
114-
# Woraround bug in older Vagrant versions using rsync instead of file
115-
config.vm.synced_folder "manifests", "/home/vagrant/manifests"
113+
config.vm.provision "file", source: "container-start.sh", destination: "$HOME/container-start.sh"
114+
config.vm.synced_folder "manifests", "$HOME/manifests"
116115

117116
# Provisioning antidote vagrant vm
118117
# This will install docker, kubectl and minikube

container-start.sh

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

selfmedicate.sh

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

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

@@ -128,50 +130,8 @@ sub_start(){
128130

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

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

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

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)