-
Notifications
You must be signed in to change notification settings - Fork 121
/
plugins_install.sh
executable file
·164 lines (140 loc) · 4.91 KB
/
plugins_install.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# This script will install and uninstall the desired plugins needed to run
# genie test suite
#plugins can be independantly installed as well using differnt options
desiredState="Running"
maxWaitSeconds=100 # Set interval (duration) in seconds.
elapsedSeconds=0 # updated after every cycle of plugin state verification
isFlannelUp=false
isWeaveUp=false
isCalicoUp=false
isRomanaUp=false
Install_Flannel() {
status=(`kubectl get pod --all-namespaces | grep -E "kube-flannel" | awk '{print $4}'`)
if [ "$status" == "$desiredState" ]; then
echo "Flannel already running"
else
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
echo "Flannel is started"
fi
}
Install_Weave() {
status=(`kubectl get pod --all-namespaces | grep -E "weave-net" | awk '{print $4}'`)
if [ "$status" == "$desiredState" ]; then
echo "Weave already running"
else
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
echo "Weave is started"
fi
}
Install_Romana() {
status=(`kubectl get pod --all-namespaces | grep -E "romana-agent" | awk '{print $4}'`)
if [ "$status" == "$desiredState" ]; then
echo "Romana already running"
else
kubectl apply -f https://raw.githubusercontent.com/romana/romana/master/containerize/specs/romana-kubeadm.yml
echo "Romana is started"
fi
}
Install_Calico() {
status=(`kubectl get pod --all-namespaces | grep -E "calico" | awk '{print $4}'`)
if [ "$status" == "$desiredState" ]; then
echo "Calico already running"
else
kubectl apply -f https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml
echo "Calico is started"
fi
}
# CAdvisor will be used to get network usage statistics to support smart plugin selection
Install_CAdvisor() {
docker rm $(docker ps -q -f status=exited)
sudo docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=4194:4194 --detach=true --name=cadvisor google/cadvisor:latest --logtostderr --port=4194
}
Delete_AllPlugins() {
kubectl delete -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
kubectl delete -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
kubectl delete -f https://raw.githubusercontent.com/romana/romana/master/containerize/specs/romana-kubeadm.yml
kubectl delete -f https://docs.projectcalico.org/v2.6/getting-started/kubernetes/installation/hosted/kubeadm/1.6/calico.yaml
echo "All plugins deleted"
}
Plugins_CNI()
{
Install_Flannel
Install_Weave
Install_Romana
Install_Calico
Install_CAdvisor
while [ $elapsedSeconds -lt $maxWaitSeconds ]
do
if [ $isFlannelUp == false ]; then
Flannel_status=(`kubectl get pod --all-namespaces | grep -E "kube-flannel" | awk '{print $4}'`)
if [ "$Flannel_status" == "$desiredState" ] ; then
echo "Flannel is running"
isFlannelUp=true
fi
fi
if [ $isWeaveUp == false ]; then
Weave_status=(`kubectl get pod --all-namespaces | grep -E "weave-net" | awk '{print $4}'`)
if [ "$Weave_status" == "$desiredState" ]; then
echo "Weave is running"
isWeaveUp=true
fi
fi
if [ $isRomanaUp == false ];then
Romana_status=(`kubectl get pod --all-namespaces | grep -E "romana-agent" | awk '{print $4}'`)
if [ "$Romana_status" == "$desiredState" ]; then
echo "Romana is running"
isRomanaUp=true
fi
fi
if [ $isCalicoUp == false ];then
Calico_status=(`kubectl get pod --all-namespaces | grep -E "calico" | awk '{print $4}'`)
if [ "$Calico_status" == "$desiredState" ]; then
echo "Calico is running"
isCalicoUp=true
fi
fi
if [ $isFlannelUp == true ] && [ $isWeaveUp == true ] && [ $isRomanaUp == true ] && [ $isCalicoUp == true ]; then
echo "All desired plugins came to running state"
break;
fi
elapsedSeconds=`expr $elapsedSeconds + 1`
done
}
options () {
echo "please provide Valid option"
echo "valid options are......."
echo "1.-all---to install all plugin only"
echo "2.-flannel ----to install flannel only"
echo "3.-weave---to install Weave only"
echo "4.-calico----to install Calico only"
echo "5.-romana---To install romana only"
echo "6.-deleteall---To delete all"
}
run () {
echo $@
echo $1
flag=0
declare -a input=("-all" "-flannel" "-weave" "-romana" "-calico" "-deleteall")
for i in "${input[@]}"
do
if [ "$i" == "$1" ]; then
flag=1
fi
done
if [ $flag -eq 0 ]; then
options
exit 1
fi
case $1 in
"-all" ) Plugins_CNI;;
"-flannel" ) Install_Flannel ;;
"-weave" ) Install_Weave ;;
"-romana" ) Install_Romana ;;
"-calico" ) Install_Calico ;;
"-deleteall" ) Delete_AllPlugins ;;
*)
;;
esac
}
run $@