blob: 09ff441fdff549b93e0974893124c4046aa51ae7 [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
Test User7c2be412019-07-03 06:20:30 +0000197 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700198 espin - $VERIFIED
199fi
200
201bspin "Verify Helm"
Test User3d7ad8e2019-07-03 06:15:44 +0000202if [ -x $GOPATH/bin/helm ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700203 espin $VERIFIED
204else
205 espin $NOT_VERIFIED
206 bspin - "Download and install Helm"
207 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
208 (set -x; curl -L https://git.io/get_helm.sh | HELM_INSTALL_DIR=$(go env GOPATH)/bin bash >>$LOG 2>&1) >>$LOG 2>&1
209 espin - $VERIFIED
210fi
211
212bspin "Verify voltctl"
Test User3d7ad8e2019-07-03 06:15:44 +0000213if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700214 espin $VERIFIED
215else
216 espin $NOT_VERIFIED
217 bspin - "Download and build voltctl"
218 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
219 (set -x; go get github.com/ciena/voltctl/cmd/voltctl >>$LOG 2>&1) >>$LOG 2>&1
220 espin - $VERIFIED
221fi
222
223bspin "Verify command PATH"
224export PATH=$(go env GOPATH)/bin:$PATH
225espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700226
227HAVE=$(kind get clusters | grep -c voltha-$TYPE)
228bspin "Verify Kubernetes/Kind Cluster"
229sspin
230if [ $HAVE -eq 0 ]; then
231 espin $NOT_VERIFIED
232 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
233else
234 espin $VERIFIED
235fi
236
237export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
238P="coredns-.* \
239 etcd-voltha-$TYPE-control-plane \
240 kindnet-.* \
241 kube-apiserver-voltha-$TYPE-control-plane \
242 kube-controller-manager-voltha-$TYPE-control-plane \
243 kube-proxy-.* \
244 kube-scheduler-voltha-$TYPE-control-plane"
245
246wait_for_pods - "kube-system" 12 -1 "Waiting for system PODs to start..." $P
247
248COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
249bspin "Verify Helm"
250if [ $(count_pods "kube-system" "tiller-deploy-.*") -ne 1 ]; then
251 espin $NOT_VERIFIED
252 echo Configuring" Helm ..."
253 bspin - "Initialize Helm"
254 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
255 espin - $VERIFIED
256 bspin - "Add Google Incubator repository to Helm ..."
257 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
258 espin - $VERIFIED
259
260 bspin - "Add Google Stable repository to Helm ..."
261 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
262 espin - $VERIFIED
263 bspin - "Add ONF repository to Helm ..."
264 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
265 espin - $VERIFIED
266 bspin - "Update Helm repository cache ..."
267 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
268 espin - $VERIFIED
269
270 # Create and k8s service account so that Helm can create pods
271 bspin - "Create Tiller ServiceAccount ..."
272 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
273 espin - $VERIFIED
274 bspin - "Create Tiller ClusterRoleBinding ..."
275 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
276 espin - $VERIFIED
277 bspin - "Update Tiller Manifest ..."
278 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>$LOG 2>&1) >>$LOG 2>&1
279 espin - $VERIFIED
280else
281 espin $VERIFIED
282fi
283wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start..." "tiller-deploy-.*"
284
285bspin "Verify ETCD Operator"
286if [ $(helm list etcd-operator | grep -c DEPLOYED) -ne 1 ]; then
287 espin $NOT_VERIFIED
288 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
289else
290 espin $VERIFIED
291fi
292wait_for_pods - "voltha" 1 -1 "Waiting for ETCD Operator to start..." "etcd-operator-.*"
293
294bspin "Verify ONOS installed"
295if [ $(helm list onos | grep -c DEPLOYED) -ne 1 ]; then
296 espin $NOT_VERIFIED
297 helm_install - default onos onf/onos "Install ONOS"
298else
299 espin $VERIFIED
300fi
301wait_for_pods - "default" 1 -1 "Waiting for ONOS to start..." "onos-.*"
302
303bspin - "Forward ONOS API port"
304(set -x; screen -p 0 -X -S onos-ui stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
305(set -x; screen -dmS onos-ui kubectl port-forward service/onos-ui 8181:8181 >>$LOG 2>&1) >>$LOG 2>&1
306espin - $VERIFIED
307bspin - "Forward ONOS SSH port"
308(set -x; screen -p 0 -X -S onos-ssh stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
309(set -x; screen -dmS onos-ssh kubectl port-forward service/onos-ssh 8101:8101 >>$LOG 2>&1) >>$LOG 2>&1
310espin - $VERIFIED
311bspin - "Install required ONOS applications"
312(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
313espin - $VERIFIED
314
315bspin "Verify VOLTHA installed"
316if [ $(helm list voltha | grep -c DEPLOYED) -ne 1 ]; then
317 espin $NOT_VERIFIED
318 helm_install - voltha voltha onf/voltha "Install VOLTHA"
319else
320 espin $VERIFIED
321fi
322VOLTHA="ofagent-.* \
323 ro-core.* \
324 rw-core.* \
325 voltha-api-server-.* \
326 voltha-cli-server-.* \
327 voltha-etcd-cluster-.* \
328 voltha-kafka-.* \
329 voltha-zookeeper-.*"
330wait_for_pods - "voltha" 9 -1 "Waiting for VOLTHA CORE top start..." $VOLTHA
331
332echo "Verify Adapters"
333bspin - "Verify Simulated Adapters installed"
334if [ $(helm list sim | grep -c DEPLOYED) -ne 1 ]; then
335 espin - $NOT_VERIFIED
336 helm_install - voltha sim onf/voltha-adapter-simulated "Install Simulated Adapters"
337else
338 espin - $VERIFIED
339fi
340
341bspin - "Verify OpenOLT Adapter installed"
342if [ $(helm list open-olt | grep -c DEPLOYED) -ne 1 ]; then
343 espin - $NOT_VERIFIED
344 helm_install - voltha open-olt onf/voltha-adapter-openolt "Install OpenOLT Adapter"
345else
346 espin - $VERIFIED
347fi
348bspin - "Verify OpenONU Adapter installed"
349if [ $(helm list open-onu | grep -c DEPLOYED) -ne 1 ]; then
350 espin - $NOT_VERIFIED
351 helm_install - voltha open-onu onf/voltha-adapter-openonu "Install OpenONU Adapter"
352else
353 espin - $VERIFIED
354fi
355
356ADAPTERS="adapter-.*"
357wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start..." $ADAPTERS
358
359echo "Restart VOLTHA API"
360API="voltha-api-server-.* ofagent-.*"
361(set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
362wait_for_pods - "voltha" 0 -1 "Wait for API to stop" $API
363(set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
364wait_for_pods - "voltha" 2 -1 "Wait for API to re-start ..." $API
365
366bspin - "Forward VOLTHA API port"
367(set -x; screen -p 0 -X -S voltha-api stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
368(set -x; screen -dmS voltha-api kubectl port-forward -n voltha service/voltha-api 55555:55555 >>$LOG 2>&1) >>$LOG 2>&1
369espin - $VERIFIED
370bspin - "Forward VOLTHA SSH port"
371(set -x; screen -p 0 -X -S voltha-ssh stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
372(set -x; screen -dmS voltha-ssh kubectl port-forward -n voltha service/voltha-cli 5022:5022 >>$LOG 2>&1) >>$LOG 2>&1
373espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000374
375bspin - "Create voltctl configuration file"
376(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
377(set -x; voltctl -a v2 -s localhost:55555 config > $HOME/.volt/config 2>>$LOG) >>$LOG 2>&1
378espin - $VERIFIED