blob: fcd1d1a228f925382625a415fca44a3f1c281495 [file] [log] [blame]
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001#!/usr/bin/env bash
2# Copyright 2019 Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# trap ctrl-c and call ctrl_c()
17trap ctrl_c INT
18
19function ctrl_c() {
20 tput cnorm
21 echo ""
22 echo "ctrl-c trapped"
23 echo "Thank you for trying 'votlha up'"
24 exit
25}
26
Test User08ebbd92019-07-03 17:15:39 +000027VOLTCTL_VERSION=${VOLTCTL_VERSION:-0.0.5-dev}
28KIND_VERSION=${KIND_VERSION:-v0.4.0}
29_VOLTCTL_VERSION=$(echo $VOLTCTL_VERSION | sed -e 's/-/_/g')
30
Test User3d7ad8e2019-07-03 06:15:44 +000031TYPE=${TYPE:-minimal}
32# Only minimal cluster works in this script currently
33TYPE=minimal
34
David K. Bainbridgeb7285432019-07-02 22:05:24 -070035if [ $# -ne 1 -o $(echo ":up:down:" | grep -c ":$1:") -ne 1 ]; then
36 >&2 echo "up or down?"
37 exit 1
38fi
39
40if [ "$1" == "down" ]; then
Test User08ebbd92019-07-03 17:15:39 +000041 if [ -x ./bin/kind ]; then
42 exec ./bin/kind delete cluster --name voltha-$TYPE
43 else
44 >&2 echo "Kind doesn't seem to be installed, so nothing to do. Bye."
45 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -070046 exit
47fi
48
49LOG="install.log"
50date > $LOG
51
52spin() {
Test Userd87942b2019-07-03 07:20:24 +000053 PARTS="\
54 \xe2\xa2\x8e\xe2\xa1\xb0 \
55 \xe2\xa2\x8e\xe2\xa1\xa1 \
56 \xe2\xa2\x8e\xe2\xa1\x91 \
57 \xe2\xa2\x8e\xe2\xa0\xb1 \
58 \xe2\xa0\x8e\xe2\xa1\xb1 \
59 \xe2\xa2\x8a\xe2\xa1\xb1 \
60 \xe2\xa2\x8c\xe2\xa1\xb1 \
61 \xe2\xa2\x86\xe2\xa1\xb1 \
62 "
63 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -070064 tput civis
65 while true; do
Test Userd87942b2019-07-03 07:20:24 +000066 C=$(echo $PARTS | cut '-d ' -f $IDX)
67 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070068 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +000069 if [ $IDX -gt 8 ]; then
70 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -070071 fi
72 sleep .15
73 echo -en "\r"
74 done
75}
76
Test Userd87942b2019-07-03 07:20:24 +000077SPIN_PARTS="\
78 \xe2\xa2\x8e\xe2\xa1\xb0 \
79 \xe2\xa2\x8e\xe2\xa1\xa1 \
80 \xe2\xa2\x8e\xe2\xa1\x91 \
81 \xe2\xa2\x8e\xe2\xa0\xb1 \
82 \xe2\xa0\x8e\xe2\xa1\xb1 \
83 \xe2\xa2\x8a\xe2\xa1\xb1 \
84 \xe2\xa2\x8c\xe2\xa1\xb1 \
85 \xe2\xa2\x86\xe2\xa1\xb1 \
86 "
87IDX=1
88NOT_VERIFIED="\xe2\x9c\x97\x20"
89VERIFIED="\xe2\x9c\x93\x20"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070090bspin() {
91 tput civis
Test Userd87942b2019-07-03 07:20:24 +000092 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -070093 local INDENT=
94 if [ "$1" == "-" ]; then
95 INDENT=" "
96 shift
97 fi
Test Userd87942b2019-07-03 07:20:24 +000098 echo -en "$INDENT $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070099}
100
101sspin() {
102 local INDENT=
103 if [ "$1" == "-" ]; then
104 INDENT=" "
105 shift
106 fi
Test Userd87942b2019-07-03 07:20:24 +0000107 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
108 echo -en "\r$INDENT$C $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700109 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000110 if [ $IDX -gt 8 ]; then
111 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700112 fi
113}
114
115espin() {
116 local INDENT=
117 if [ "$1" == "-" ]; then
118 INDENT=" "
119 shift
120 fi
121 echo -e "\r$INDENT$*"
122 tput cnorm
123}
124
125count_pods() {
126 local NAMESPACE=$1; shift
127 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
128 local COUNT=0
129 local PATTERNS=$*
130 for POD in $PODS; do
131 local NAME=$(echo $POD | cut -d/ -f 1)
132 local STATE=$(echo $POD | cut -d/ -f 2)
133 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
134 if [ "$STATE" == "Running" ]; then
135 local TOTAL=$(echo $CONTAINERS | wc -w)
136 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
137 if [ $TOTAL -eq $FOUND ]; then
138 for PATTERN in $PATTERNS; do
139 if [[ $NAME =~ $PATTERN ]]; then
140 COUNT=$(expr $COUNT + 1)
141 fi
142 done
143 fi
144 fi
145 done
146 echo $COUNT
147}
148
149wait_for_pods() {
150 local INDENT=
151 if [ "$1" == "-" ]; then
152 INDENT=$1; shift
153 fi
154 local NAMESPACE=$1; shift
155 local EXPECT=$1; shift
156 local RETRY=$1; shift
157 local MESSAGE=$1; shift
158 local PATTERNS=$*
159 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
160 COUNT=$(expr 300 / 15)
161 bspin $INDENT $MESSAGE
162 sspin $INDENT
163 if [ $HAVE -ne $EXPECT ]; then
164 while [ $HAVE -ne $EXPECT ]; do
165 sspin $INDENT
166 COUNT=$(expr $COUNT - 1)
167 if [ $COUNT -eq 0 ]; then
168 HAVE=$(count_pods $NAMESPACE $PATTERNS)
169 COUNT=$(expr 300 / 15)
170 fi
171 sleep .15
172 done
173 fi
174 espin $INDENT $VERIFIED
175 if [ $HAVE -ne $EXPECT ]; then
176 return 1
177 fi
178 return 0
179}
180
181helm_install() {
182 local INDENT=
183 if [ "$1" == "-" ]; then
184 INDENT=$1; shift
185 fi
186 local NAMESPACE=$1; shift
187 local NAME=$1; shift
188 local CHART=$1; shift
189 local MESSAGE=$*
190
191 COUNT=$(expr 300 / 15)
192 bspin $INDENT $MESSAGE
193 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
194 SUCCESS=$?
195 while [ $SUCCESS -ne 0 ]; do
196 sspin $INDENT
197 COUNT=$(expr $COUNT - 1)
198 if [ $COUNT -eq 0 ]; then
199 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
200 COUNT=$(expr 300 / 15)
201 fi
202 sleep .15
203 done
204 espin $INDENT $VERIFIED
205}
206
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700207echo "INSTALL TYPE: $TYPE" >> $LOG
208
209bspin "Verify GOPATH"
210export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000211mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700212espin $VERIFIED
213
214bspin "Verify Kubernetes/Kind"
Test User3d7ad8e2019-07-03 06:15:44 +0000215if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700216 espin $VERIFIED
217else
218 espin $NOT_VERIFIED
219 bspin - "Download and build Kubernetes/Kind"
Test User08ebbd92019-07-03 17:15:39 +0000220 (set -x; curl -o $GOPATH/bin/kind -sSL https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-$(go env GOHOSTOS)-$(go env GOARCH) >>$LOG 2>&1) >>$LOG 2>&1
Test User7c2be412019-07-03 06:20:30 +0000221 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700222 espin - $VERIFIED
223fi
224
225bspin "Verify Helm"
Test User3d7ad8e2019-07-03 06:15:44 +0000226if [ -x $GOPATH/bin/helm ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700227 espin $VERIFIED
228else
229 espin $NOT_VERIFIED
230 bspin - "Download and install Helm"
Test User08ebbd92019-07-03 17:15:39 +0000231 (set -x; curl -sSL https://git.io/get_helm.sh | USE_SUDO=false HELM_INSTALL_DIR=$(go env GOPATH)/bin bash >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700232 espin - $VERIFIED
233fi
234
235bspin "Verify voltctl"
Test User3d7ad8e2019-07-03 06:15:44 +0000236if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700237 espin $VERIFIED
238else
239 espin $NOT_VERIFIED
240 bspin - "Download and build voltctl"
Test User08ebbd92019-07-03 17:15:39 +0000241 (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/ciena/voltctl/releases/download/$VOLTCTL_VERSION/voltctl-$_VOLTCTL_VERSION-$(go env GOHOSTOS)-$(go env GOARCH) >>$LOG 2>&1) >>$LOG 2>&1
242 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700243 espin - $VERIFIED
244fi
245
246bspin "Verify command PATH"
247export PATH=$(go env GOPATH)/bin:$PATH
248espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700249
250HAVE=$(kind get clusters | grep -c voltha-$TYPE)
251bspin "Verify Kubernetes/Kind Cluster"
252sspin
253if [ $HAVE -eq 0 ]; then
254 espin $NOT_VERIFIED
255 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
256else
257 espin $VERIFIED
258fi
259
260export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
261P="coredns-.* \
262 etcd-voltha-$TYPE-control-plane \
263 kindnet-.* \
264 kube-apiserver-voltha-$TYPE-control-plane \
265 kube-controller-manager-voltha-$TYPE-control-plane \
266 kube-proxy-.* \
267 kube-scheduler-voltha-$TYPE-control-plane"
268
269wait_for_pods - "kube-system" 12 -1 "Waiting for system PODs to start..." $P
270
271COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
272bspin "Verify Helm"
273if [ $(count_pods "kube-system" "tiller-deploy-.*") -ne 1 ]; then
274 espin $NOT_VERIFIED
Test Userd87942b2019-07-03 07:20:24 +0000275 echo "Configuring Helm ..."
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700276 bspin - "Initialize Helm"
277 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
278 espin - $VERIFIED
279 bspin - "Add Google Incubator repository to Helm ..."
280 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
281 espin - $VERIFIED
282
283 bspin - "Add Google Stable repository to Helm ..."
284 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
285 espin - $VERIFIED
286 bspin - "Add ONF repository to Helm ..."
287 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
288 espin - $VERIFIED
289 bspin - "Update Helm repository cache ..."
290 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
291 espin - $VERIFIED
292
293 # Create and k8s service account so that Helm can create pods
294 bspin - "Create Tiller ServiceAccount ..."
295 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
296 espin - $VERIFIED
297 bspin - "Create Tiller ClusterRoleBinding ..."
298 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
299 espin - $VERIFIED
300 bspin - "Update Tiller Manifest ..."
301 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>$LOG 2>&1) >>$LOG 2>&1
302 espin - $VERIFIED
303else
304 espin $VERIFIED
305fi
306wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start..." "tiller-deploy-.*"
307
308bspin "Verify ETCD Operator"
309if [ $(helm list etcd-operator | grep -c DEPLOYED) -ne 1 ]; then
310 espin $NOT_VERIFIED
311 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
312else
313 espin $VERIFIED
314fi
315wait_for_pods - "voltha" 1 -1 "Waiting for ETCD Operator to start..." "etcd-operator-.*"
316
317bspin "Verify ONOS installed"
318if [ $(helm list onos | grep -c DEPLOYED) -ne 1 ]; then
319 espin $NOT_VERIFIED
320 helm_install - default onos onf/onos "Install ONOS"
321else
322 espin $VERIFIED
323fi
324wait_for_pods - "default" 1 -1 "Waiting for ONOS to start..." "onos-.*"
325
326bspin - "Forward ONOS API port"
327(set -x; screen -p 0 -X -S onos-ui stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
328(set -x; screen -dmS onos-ui kubectl port-forward service/onos-ui 8181:8181 >>$LOG 2>&1) >>$LOG 2>&1
329espin - $VERIFIED
330bspin - "Forward ONOS SSH port"
331(set -x; screen -p 0 -X -S onos-ssh stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
332(set -x; screen -dmS onos-ssh kubectl port-forward service/onos-ssh 8101:8101 >>$LOG 2>&1) >>$LOG 2>&1
333espin - $VERIFIED
334bspin - "Install required ONOS applications"
335(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
336espin - $VERIFIED
337
338bspin "Verify VOLTHA installed"
339if [ $(helm list voltha | grep -c DEPLOYED) -ne 1 ]; then
340 espin $NOT_VERIFIED
Test Userd87942b2019-07-03 07:20:24 +0000341 helm_install - voltha voltha onf/voltha "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700342else
343 espin $VERIFIED
344fi
345VOLTHA="ofagent-.* \
346 ro-core.* \
347 rw-core.* \
348 voltha-api-server-.* \
349 voltha-cli-server-.* \
350 voltha-etcd-cluster-.* \
351 voltha-kafka-.* \
352 voltha-zookeeper-.*"
Test Userd87942b2019-07-03 07:20:24 +0000353wait_for_pods - "voltha" 9 -1 "Waiting for VOLTHA Core to start..." $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700354
355echo "Verify Adapters"
356bspin - "Verify Simulated Adapters installed"
357if [ $(helm list sim | grep -c DEPLOYED) -ne 1 ]; then
358 espin - $NOT_VERIFIED
359 helm_install - voltha sim onf/voltha-adapter-simulated "Install Simulated Adapters"
360else
361 espin - $VERIFIED
362fi
363
364bspin - "Verify OpenOLT Adapter installed"
365if [ $(helm list open-olt | grep -c DEPLOYED) -ne 1 ]; then
366 espin - $NOT_VERIFIED
367 helm_install - voltha open-olt onf/voltha-adapter-openolt "Install OpenOLT Adapter"
368else
369 espin - $VERIFIED
370fi
371bspin - "Verify OpenONU Adapter installed"
372if [ $(helm list open-onu | grep -c DEPLOYED) -ne 1 ]; then
373 espin - $NOT_VERIFIED
374 helm_install - voltha open-onu onf/voltha-adapter-openonu "Install OpenONU Adapter"
375else
376 espin - $VERIFIED
377fi
378
379ADAPTERS="adapter-.*"
380wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start..." $ADAPTERS
381
382echo "Restart VOLTHA API"
383API="voltha-api-server-.* ofagent-.*"
384(set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
385wait_for_pods - "voltha" 0 -1 "Wait for API to stop" $API
386(set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
387wait_for_pods - "voltha" 2 -1 "Wait for API to re-start ..." $API
388
389bspin - "Forward VOLTHA API port"
390(set -x; screen -p 0 -X -S voltha-api stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
391(set -x; screen -dmS voltha-api kubectl port-forward -n voltha service/voltha-api 55555:55555 >>$LOG 2>&1) >>$LOG 2>&1
392espin - $VERIFIED
393bspin - "Forward VOLTHA SSH port"
394(set -x; screen -p 0 -X -S voltha-ssh stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
395(set -x; screen -dmS voltha-ssh kubectl port-forward -n voltha service/voltha-cli 5022:5022 >>$LOG 2>&1) >>$LOG 2>&1
396espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000397
398bspin - "Create voltctl configuration file"
399(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
400(set -x; voltctl -a v2 -s localhost:55555 config > $HOME/.volt/config 2>>$LOG) >>$LOG 2>&1
401espin - $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +0000402
403echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
404echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
405echo "tools required by VOLTHA in your command path. " | tee -a $LOG
406echo "" | tee -a $LOG
407echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
408echo 'export PATH=$GOPATH/bin:$PATH' | tee -a $LOG
409echo "" | tee -a $LOG
410echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
411