blob: 5de767c923998565c07140cd1ca39ef58449654e [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 User3d7ad8e2019-07-03 06:15:44 +000027TYPE=${TYPE:-minimal}
28# Only minimal cluster works in this script currently
29TYPE=minimal
30
David K. Bainbridgeb7285432019-07-02 22:05:24 -070031if [ $# -ne 1 -o $(echo ":up:down:" | grep -c ":$1:") -ne 1 ]; then
32 >&2 echo "up or down?"
33 exit 1
34fi
35
36if [ "$1" == "down" ]; then
37 exec kind delete cluster --name voltha-$TYPE
38 exit
39fi
40
41LOG="install.log"
42date > $LOG
43
44spin() {
45 START=14852225
46 END=14852287
47 IDX=$START
48 tput civis
49 while true; do
50 printf '%02x' $IDX | xxd -r -p
51 echo -en " $IDX"
52 IDX=$(expr $IDX + 1)
53 if [ $IDX -gt $END ]; then
54 IDX=$START
55 fi
56 sleep .15
57 echo -en "\r"
58 done
59}
60
61IDX=14852225
62NOT_VERIFIED="\xe2\x9c\x97"
63VERIFIED="\xe2\x9c\x93"
64bspin() {
65 tput civis
66 IDX=14852225
67 local INDENT=
68 if [ "$1" == "-" ]; then
69 INDENT=" "
70 shift
71 fi
72 echo -en "$INDENT $*"
73}
74
75sspin() {
76 local INDENT=
77 if [ "$1" == "-" ]; then
78 INDENT=" "
79 shift
80 fi
81 echo -en "\r$INDENT"
82 printf " %02x" $IDX | xxd -r -p
83 echo -en " $*"
84 IDX=$(expr $IDX + 1)
85 if [ $IDX -gt 14852287 ]; then
86 IDX=14852225
87 fi
88}
89
90espin() {
91 local INDENT=
92 if [ "$1" == "-" ]; then
93 INDENT=" "
94 shift
95 fi
96 echo -e "\r$INDENT$*"
97 tput cnorm
98}
99
100count_pods() {
101 local NAMESPACE=$1; shift
102 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
103 local COUNT=0
104 local PATTERNS=$*
105 for POD in $PODS; do
106 local NAME=$(echo $POD | cut -d/ -f 1)
107 local STATE=$(echo $POD | cut -d/ -f 2)
108 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
109 if [ "$STATE" == "Running" ]; then
110 local TOTAL=$(echo $CONTAINERS | wc -w)
111 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
112 if [ $TOTAL -eq $FOUND ]; then
113 for PATTERN in $PATTERNS; do
114 if [[ $NAME =~ $PATTERN ]]; then
115 COUNT=$(expr $COUNT + 1)
116 fi
117 done
118 fi
119 fi
120 done
121 echo $COUNT
122}
123
124wait_for_pods() {
125 local INDENT=
126 if [ "$1" == "-" ]; then
127 INDENT=$1; shift
128 fi
129 local NAMESPACE=$1; shift
130 local EXPECT=$1; shift
131 local RETRY=$1; shift
132 local MESSAGE=$1; shift
133 local PATTERNS=$*
134 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
135 COUNT=$(expr 300 / 15)
136 bspin $INDENT $MESSAGE
137 sspin $INDENT
138 if [ $HAVE -ne $EXPECT ]; then
139 while [ $HAVE -ne $EXPECT ]; do
140 sspin $INDENT
141 COUNT=$(expr $COUNT - 1)
142 if [ $COUNT -eq 0 ]; then
143 HAVE=$(count_pods $NAMESPACE $PATTERNS)
144 COUNT=$(expr 300 / 15)
145 fi
146 sleep .15
147 done
148 fi
149 espin $INDENT $VERIFIED
150 if [ $HAVE -ne $EXPECT ]; then
151 return 1
152 fi
153 return 0
154}
155
156helm_install() {
157 local INDENT=
158 if [ "$1" == "-" ]; then
159 INDENT=$1; shift
160 fi
161 local NAMESPACE=$1; shift
162 local NAME=$1; shift
163 local CHART=$1; shift
164 local MESSAGE=$*
165
166 COUNT=$(expr 300 / 15)
167 bspin $INDENT $MESSAGE
168 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
169 SUCCESS=$?
170 while [ $SUCCESS -ne 0 ]; do
171 sspin $INDENT
172 COUNT=$(expr $COUNT - 1)
173 if [ $COUNT -eq 0 ]; then
174 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
175 COUNT=$(expr 300 / 15)
176 fi
177 sleep .15
178 done
179 espin $INDENT $VERIFIED
180}
181
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700182echo "INSTALL TYPE: $TYPE" >> $LOG
183
184bspin "Verify GOPATH"
185export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000186mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700187espin $VERIFIED
188
189bspin "Verify Kubernetes/Kind"
Test User3d7ad8e2019-07-03 06:15:44 +0000190if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700191 espin $VERIFIED
192else
193 espin $NOT_VERIFIED
194 bspin - "Download and build Kubernetes/Kind"
195 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
Test User3d7ad8e2019-07-03 06:15:44 +0000196 (set -x; curl -o $GOPATH/bin/kind -sSL https://github.com/kubernetes-sigs/kind/releases/download/v0.4.0/kind-$(go env GOHOSTOS)-$(go env GOARCH) >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700197 espin - $VERIFIED
198fi
199
200bspin "Verify Helm"
Test User3d7ad8e2019-07-03 06:15:44 +0000201if [ -x $GOPATH/bin/helm ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700202 espin $VERIFIED
203else
204 espin $NOT_VERIFIED
205 bspin - "Download and install Helm"
206 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
207 (set -x; curl -L https://git.io/get_helm.sh | HELM_INSTALL_DIR=$(go env GOPATH)/bin bash >>$LOG 2>&1) >>$LOG 2>&1
208 espin - $VERIFIED
209fi
210
211bspin "Verify voltctl"
Test User3d7ad8e2019-07-03 06:15:44 +0000212if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700213 espin $VERIFIED
214else
215 espin $NOT_VERIFIED
216 bspin - "Download and build voltctl"
217 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
218 (set -x; go get github.com/ciena/voltctl/cmd/voltctl >>$LOG 2>&1) >>$LOG 2>&1
219 espin - $VERIFIED
220fi
221
222bspin "Verify command PATH"
223export PATH=$(go env GOPATH)/bin:$PATH
224espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700225
226HAVE=$(kind get clusters | grep -c voltha-$TYPE)
227bspin "Verify Kubernetes/Kind Cluster"
228sspin
229if [ $HAVE -eq 0 ]; then
230 espin $NOT_VERIFIED
231 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
232else
233 espin $VERIFIED
234fi
235
236export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
237P="coredns-.* \
238 etcd-voltha-$TYPE-control-plane \
239 kindnet-.* \
240 kube-apiserver-voltha-$TYPE-control-plane \
241 kube-controller-manager-voltha-$TYPE-control-plane \
242 kube-proxy-.* \
243 kube-scheduler-voltha-$TYPE-control-plane"
244
245wait_for_pods - "kube-system" 12 -1 "Waiting for system PODs to start..." $P
246
247COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
248bspin "Verify Helm"
249if [ $(count_pods "kube-system" "tiller-deploy-.*") -ne 1 ]; then
250 espin $NOT_VERIFIED
251 echo Configuring" Helm ..."
252 bspin - "Initialize Helm"
253 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
254 espin - $VERIFIED
255 bspin - "Add Google Incubator repository to Helm ..."
256 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
257 espin - $VERIFIED
258
259 bspin - "Add Google Stable repository to Helm ..."
260 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
261 espin - $VERIFIED
262 bspin - "Add ONF repository to Helm ..."
263 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
264 espin - $VERIFIED
265 bspin - "Update Helm repository cache ..."
266 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
267 espin - $VERIFIED
268
269 # Create and k8s service account so that Helm can create pods
270 bspin - "Create Tiller ServiceAccount ..."
271 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
272 espin - $VERIFIED
273 bspin - "Create Tiller ClusterRoleBinding ..."
274 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
275 espin - $VERIFIED
276 bspin - "Update Tiller Manifest ..."
277 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>$LOG 2>&1) >>$LOG 2>&1
278 espin - $VERIFIED
279else
280 espin $VERIFIED
281fi
282wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start..." "tiller-deploy-.*"
283
284bspin "Verify ETCD Operator"
285if [ $(helm list etcd-operator | grep -c DEPLOYED) -ne 1 ]; then
286 espin $NOT_VERIFIED
287 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
288else
289 espin $VERIFIED
290fi
291wait_for_pods - "voltha" 1 -1 "Waiting for ETCD Operator to start..." "etcd-operator-.*"
292
293bspin "Verify ONOS installed"
294if [ $(helm list onos | grep -c DEPLOYED) -ne 1 ]; then
295 espin $NOT_VERIFIED
296 helm_install - default onos onf/onos "Install ONOS"
297else
298 espin $VERIFIED
299fi
300wait_for_pods - "default" 1 -1 "Waiting for ONOS to start..." "onos-.*"
301
302bspin - "Forward ONOS API port"
303(set -x; screen -p 0 -X -S onos-ui stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
304(set -x; screen -dmS onos-ui kubectl port-forward service/onos-ui 8181:8181 >>$LOG 2>&1) >>$LOG 2>&1
305espin - $VERIFIED
306bspin - "Forward ONOS SSH port"
307(set -x; screen -p 0 -X -S onos-ssh stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
308(set -x; screen -dmS onos-ssh kubectl port-forward service/onos-ssh 8101:8101 >>$LOG 2>&1) >>$LOG 2>&1
309espin - $VERIFIED
310bspin - "Install required ONOS applications"
311(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
312espin - $VERIFIED
313
314bspin "Verify VOLTHA installed"
315if [ $(helm list voltha | grep -c DEPLOYED) -ne 1 ]; then
316 espin $NOT_VERIFIED
317 helm_install - voltha voltha onf/voltha "Install VOLTHA"
318else
319 espin $VERIFIED
320fi
321VOLTHA="ofagent-.* \
322 ro-core.* \
323 rw-core.* \
324 voltha-api-server-.* \
325 voltha-cli-server-.* \
326 voltha-etcd-cluster-.* \
327 voltha-kafka-.* \
328 voltha-zookeeper-.*"
329wait_for_pods - "voltha" 9 -1 "Waiting for VOLTHA CORE top start..." $VOLTHA
330
331echo "Verify Adapters"
332bspin - "Verify Simulated Adapters installed"
333if [ $(helm list sim | grep -c DEPLOYED) -ne 1 ]; then
334 espin - $NOT_VERIFIED
335 helm_install - voltha sim onf/voltha-adapter-simulated "Install Simulated Adapters"
336else
337 espin - $VERIFIED
338fi
339
340bspin - "Verify OpenOLT Adapter installed"
341if [ $(helm list open-olt | grep -c DEPLOYED) -ne 1 ]; then
342 espin - $NOT_VERIFIED
343 helm_install - voltha open-olt onf/voltha-adapter-openolt "Install OpenOLT Adapter"
344else
345 espin - $VERIFIED
346fi
347bspin - "Verify OpenONU Adapter installed"
348if [ $(helm list open-onu | grep -c DEPLOYED) -ne 1 ]; then
349 espin - $NOT_VERIFIED
350 helm_install - voltha open-onu onf/voltha-adapter-openonu "Install OpenONU Adapter"
351else
352 espin - $VERIFIED
353fi
354
355ADAPTERS="adapter-.*"
356wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start..." $ADAPTERS
357
358echo "Restart VOLTHA API"
359API="voltha-api-server-.* ofagent-.*"
360(set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
361wait_for_pods - "voltha" 0 -1 "Wait for API to stop" $API
362(set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
363wait_for_pods - "voltha" 2 -1 "Wait for API to re-start ..." $API
364
365bspin - "Forward VOLTHA API port"
366(set -x; screen -p 0 -X -S voltha-api stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
367(set -x; screen -dmS voltha-api kubectl port-forward -n voltha service/voltha-api 55555:55555 >>$LOG 2>&1) >>$LOG 2>&1
368espin - $VERIFIED
369bspin - "Forward VOLTHA SSH port"
370(set -x; screen -p 0 -X -S voltha-ssh stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
371(set -x; screen -dmS voltha-ssh kubectl port-forward -n voltha service/voltha-cli 5022:5022 >>$LOG 2>&1) >>$LOG 2>&1
372espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000373
374bspin - "Create voltctl configuration file"
375(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
376(set -x; voltctl -a v2 -s localhost:55555 config > $HOME/.volt/config 2>>$LOG) >>$LOG 2>&1
377espin - $VERIFIED