cd adjust for random deploy upgrade conflict
[logging-analytics.git] / deploy / cd.sh
1 #!/bin/bash
2 #############################################################################
3 #
4 # Copyright © 2019 Amdocs.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #############################################################################
18 # v20181226
19 # https://wiki.onap.org/display/DW/ONAP+on+Kubernetes
20 # source from https://jira.onap.org/browse/OOM-320, 326, 321
21 # Michael O'Brien
22 #
23
24 usage() {
25   cat <<EOF
26 Usage: $0 [PARAMs]
27 example 
28 ./cd.sh -b amsterdam -e onap (will rerun onap in the onap namespace, no new repo, no deletion of existing repo, no sdnc workaround, no onap removal at the end
29 ./cd.sh -b master -e onap -s 500 -c true -d true -w true -r true (run as cd server, new oom, delete prev oom, run workarounds, clean onap at the end of the script
30 ./cd.sh -b master -e onap -s 600 -c true -d false -w true -r false (standard new server/dev environment - use this as the default)
31 provide a dev0.yaml/dev1.yaml override set (0=platform, 1=rest of pods) - copy from https://git.onap.org/oom/tree/kubernetes/onap/resources/environments/dev.yaml
32
33 -u                  : Display usage
34 -b [branch]         : branch = master/beijing or amsterdam (required)
35 -e [environment]    : use the default (onap)
36 -s [seconds]        : delay between base and rest of onap dual-deployments based on dev0 and dev1.yaml
37 -c [true|false]     : FLAG clone new oom repo (default: true)
38 -d [true|false]     : FLAG delete prev oom - (cd build) (default: false)
39 -w [true|false]     : FLAG apply workarounds  IE: sdnc (default: true)
40 -r [true|false]     : FLAG remove oom at end of script - for use by CD only (default: false)
41 EOF
42 }
43
44 deploy_onap() {
45   
46   echo "$(date)"
47   echo "running with: -b $BRANCH -e $ENVIRON -s $SPLIT_DEPLOY_DELAY -c $CLONE_NEW_OOM -d $DELETE_PREV_OOM -w $APPLY_WORKAROUNDS -r $REMOVE_OOM_AT_END"
48   echo "provide onap-parameters.yaml(amsterdam) or dev0.yaml+dev1.yaml (master) and aai-cloud-region-put.json"
49   echo "provide a dev0.yaml and dev1.yaml override (0=platform, 1=rest of pods) - copy from https://git.onap.org/oom/tree/kubernetes/onap/resources/environments/dev.yaml"
50   # fix virtual memory for onap-log:elasticsearch under Rancher 1.6.11 - OOM-431
51   sudo sysctl -w vm.max_map_count=262144
52   if [[ "$DELETE_PREV_OOM" != false ]]; then
53     echo "remove existing oom"
54     # master/beijing only - not amsterdam
55     if [ "$BRANCH" == "amsterdam" ]; then
56       oom/kubernetes/oneclick/deleteAll.bash -n $ENVIRON
57     else
58       # run undeploy for completeness of the deploy/undeploy cycle - note that pv/pvcs are not deleted in all cases
59       # this will fail as expected on a clean first run of the deployment - the plugin will be installed for run n+1
60       sudo helm undeploy $ENVIRON --purge
61       # workaround for secondary orchestration in dcae
62       kubectl delete namespace $ENVIRON
63       echo "sleep for 4 min to allow the delete to finish pod terminations before trying a helm delete"
64       sleep 240
65       sudo helm delete --purge $ENVIRON
66     fi
67
68     # verify
69     DELETED=$(kubectl get pods --all-namespaces -a | grep -E '0/|1/2' | wc -l)
70     echo "showing {$DELETED} undeleted pods"
71     echo "verify deletion is finished."
72     while [  $(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l) -gt 0 ]; do
73       sleep 15
74       echo "waiting for deletions to complete"
75     done
76     # wait for 0/1 before deleting
77     echo "sleeping 30 sec"
78     # delete potential hanging clustered pods
79     #kubectl delete pod $ENVIRON-aaf-sms-vault-0 -n $ENVIRON --grace-period=0 --force
80     # specific to when there is no helm release
81     kubectl delete pv --all
82     kubectl delete pvc --all
83     kubectl delete secrets --all
84     kubectl delete clusterrolebinding --all
85     # replace with watch
86     # keep jenkins 120 sec timeout happy with echos
87     sleep 30
88     echo "List of ONAP Modules - look for terminating pods"
89     LIST_ALL=$(kubectl get pods --all-namespaces --show-all -o wide )
90     echo "${LIST_ALL}"
91
92     # for use by continuous deployment only
93     echo " deleting /dockerdata-nfs/ all onap-* deployments"
94     sudo chmod -R 777 /dockerdata-nfs/*
95     rm -rf /dockerdata-nfs/*
96   fi
97   # for use by continuous deployment only
98   if [[ "$CLONE_NEW_OOM" != false ]]; then
99     rm -rf oom
100     echo "pull new oom"
101     git clone -b $BRANCH http://gerrit.onap.org/r/oom
102     # https://wiki.onap.org/display/DW/OOM+Helm+%28un%29Deploy+plugins
103     sudo cp -R ~/oom/kubernetes/helm/plugins/ ~/.helm
104   fi
105
106   if [ "$BRANCH" == "amsterdam" ]; then
107     echo "start config pod"
108     # still need to source docker variables
109     source oom/kubernetes/oneclick/setenv.bash
110     #echo "source setenv override"
111     echo "moving onap-parameters.yaml to oom/kubernetes/config"
112     cp onap-parameters.yaml oom/kubernetes/config
113     cd oom/kubernetes/config
114     ./createConfig.sh -n $ENVIRON
115     cd ../../../
116     echo "verify onap-config is 0/1 not 1/1 - as in completed - an error pod - means you are missing onap-parameters.yaml or values are not set in it."
117     while [  $(kubectl get pods -n onap -a | grep config | grep 0/1 | grep Completed | wc -l) -eq 0 ]; do
118       sleep 15
119       echo "waiting for config pod to complete"
120     done
121   else
122     echo "moving values.yaml to oom/kubernetes/"
123     #sudo cp values.yaml oom/kubernetes/onap
124   fi
125
126   # usually the prepull takes up to 25-300 min - however hourly builds will finish the docker pulls before the config pod is finished
127   #echo "pre pull docker images - 35+ min"
128   #wget https://jira.onap.org/secure/attachment/11261/prepull_docker.sh
129   #chmod 777 prepull_docker.sh
130   #./prepull_docker.sh
131   echo "start onap pods"
132   if [ "$BRANCH" == "amsterdam" ]; then
133     cd oom/kubernetes/oneclick
134     ./createAll.bash -n $ENVIRON
135     cd ../../../
136   else
137     cd oom/kubernetes/
138     sudo make clean
139     sudo make all
140     sudo make $ENVIRON
141     #sudo helm install local/onap -n onap --namespace $ENVIRON
142     # run an empty deploy first to get a round a random helm deploy failure on a release upgrade failure (deploy plugin runs as upgrade instead of install)
143     echo "deploying empty onap deployment as base 1 of 3"
144     sudo helm deploy onap local/onap --namespace $ENVIRON -f onap/resources/environments/disable-allcharts.yaml --verbose
145     # deploy platform pods first - dev0 and dev1 can be the same is required
146     echo "deploying base onap pods as base 2 of 3"
147     sudo helm deploy onap local/onap --namespace $ENVIRON -f onap/resources/environments/disable-allcharts.yaml -f ~/dev0.yaml --verbose
148     echo "sleep ${SPLIT_DEPLOY_DELAY} sec to allow base platform pods to complete - without a grep on 0/1|0/2| non-Complete jobs"
149     sleep $SPLIT_DEPLOY_DELAY
150     echo "deploying rest of onap pods as base 3 of 3"
151     sudo helm deploy onap local/onap --namespace $ENVIRON -f onap/resources/environments/disable-allcharts.yaml -f ~/dev1.yaml --verbose  
152   cd ../../
153   fi
154
155   echo "wait for all pods up for 15-80 min"
156   FAILED_PODS_LIMIT=0
157   MAX_WAIT_PERIODS=480 # 120 MIN
158   COUNTER=0
159   PENDING_PODS=0
160   while [  $(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l) -gt $FAILED_PODS_LIMIT ]; do
161     PENDING=$(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l)
162     PENDING_PODS=$PENDING
163     sleep 15
164     LIST_PENDING=$(kubectl get pods --all-namespaces -o wide | grep -E '0/|1/2' )
165     echo "${LIST_PENDING}"
166     echo "${PENDING} pending > ${FAILED_PODS_LIMIT} at the ${COUNTER}th 15 sec interval"
167     echo ""
168     COUNTER=$((COUNTER + 1 ))
169     MAX_WAIT_PERIODS=$((MAX_WAIT_PERIODS - 1))
170     if [ "$MAX_WAIT_PERIODS" -eq 0 ]; then
171       FAILED_PODS_LIMIT=800
172     fi
173   done
174
175   echo "report on non-running containers"
176   PENDING=$(kubectl get pods --all-namespaces | grep -E '0/|1/2')
177   PENDING_COUNT=$(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l)
178   PENDING_COUNT_AAI=$(kubectl get pods -n $ENVIRON | grep aai- | grep -E '0/|1/2' | wc -l)
179   if [ "$PENDING_COUNT_AAI" -gt 0 ]; then
180     echo "down-aai=${PENDING_COUNT_AAI}"
181   fi
182
183   # todo don't stop if aai is down
184   PENDING_COUNT_APPC=$(kubectl get pods -n $ENVIRON | grep appc- | grep -E '0/|1/2' | wc -l)
185   if [ "$PENDING_COUNT_APPC" -gt 0 ]; then
186     echo "down-appc=${PENDING_COUNT_APPC}"
187   fi
188   PENDING_COUNT_MR=$(kubectl get pods -n $ENVIRON | grep message-router- | grep -E '0/|1/2' | wc -l)
189   if [ "$PENDING_COUNT_MR" -gt 0 ]; then
190     echo "down-mr=${PENDING_COUNT_MR}"
191   fi
192   PENDING_COUNT_SO=$(kubectl get pods -n $ENVIRON | grep so- | grep -E '0/|1/2' | wc -l)
193   if [ "$PENDING_COUNT_SO" -gt 0 ]; then
194     echo "down-so=${PENDING_COUNT_SO}"
195   fi
196   PENDING_COUNT_POLICY=$(kubectl get pods -n $ENVIRON | grep policy- | grep -E '0/|1/2' | wc -l)
197   if [ "$PENDING_COUNT_POLICY" -gt 0 ]; then
198     echo "down-policy=${PENDING_COUNT_POLICY}"
199   fi
200   PENDING_COUNT_PORTAL=$(kubectl get pods -n $ENVIRON | grep portal- | grep -E '0/|1/2' | wc -l)
201   if [ "$PENDING_COUNT_PORTAL" -gt 0 ]; then
202     echo "down-portal=${PENDING_COUNT_PORTAL}"
203   fi
204   PENDING_COUNT_LOG=$(kubectl get pods -n $ENVIRON | grep log- | grep -E '0/|1/2' | wc -l)
205   if [ "$PENDING_COUNT_LOG" -gt 0 ]; then
206     echo "down-log=${PENDING_COUNT_LOG}"
207   fi
208   PENDING_COUNT_ROBOT=$(kubectl get pods -n $ENVIRON | grep robot- | grep -E '0/|1/2' | wc -l)
209   if [ "$PENDING_COUNT_ROBOT" -gt 0 ]; then
210     echo "down-robot=${PENDING_COUNT_ROBOT}"
211   fi
212   PENDING_COUNT_SDC=$(kubectl get pods -n $ENVIRON | grep sdc- | grep -E '0/|1/2' | wc -l)
213   if [ "$PENDING_COUNT_SDC" -gt 0 ]; then
214     echo "down-sdc=${PENDING_COUNT_SDC}"
215   fi
216   PENDING_COUNT_SDNC=$(kubectl get pods -n $ENVIRON | grep sdnc- | grep -E '0/|1/2' | wc -l)
217   if [ "$PENDING_COUNT_SDNC" -gt 0 ]; then
218     echo "down-sdnc=${PENDING_COUNT_SDNC}"
219   fi
220   PENDING_COUNT_VID=$(kubectl get pods -n $ENVIRON | grep vid- | grep -E '0/|1/2' | wc -l)
221   if [ "$PENDING_COUNT_VID" -gt 0 ]; then
222     echo "down-vid=${PENDING_COUNT_VID}"
223   fi
224
225   PENDING_COUNT_AAF=$(kubectl get pods -n $ENVIRON | grep aaf- | grep -E '0/|1/2' | wc -l)
226   if [ "$PENDING_COUNT_AAF" -gt 0 ]; then
227     echo "down-aaf=${PENDING_COUNT_AAF}"
228   fi
229   PENDING_COUNT_CONSUL=$(kubectl get pods -n $ENVIRON | grep consul- | grep -E '0/|1/2' | wc -l)
230   if [ "$PENDING_COUNT_CONSUL" -gt 0 ]; then
231     echo "down-consul=${PENDING_COUNT_CONSUL}"
232   fi
233   PENDING_COUNT_MSB=$(kubectl get pods -n $ENVIRON | grep msb- | grep -E '0/|1/2' | wc -l)
234   if [ "$PENDING_COUNT_MSB" -gt 0 ]; then
235     echo "down-msb=${PENDING_COUNT_MSB}"
236   fi
237   PENDING_COUNT_DCAE=$(kubectl get pods -n $ENVIRON | grep dcaegen2- | grep -E '0/|1/2' | wc -l)
238   if [ "$PENDING_COUNT_DCAE" -gt 0 ]; then
239     echo "down-dcae=${PENDING_COUNT_DCAE}"
240   fi
241   PENDING_COUNT_CLI=$(kubectl get pods -n $ENVIRON | grep cli- | grep -E '0/|1/2' | wc -l)
242   if [ "$PENDING_COUNT_CLI" -gt 0 ]; then
243     echo "down-cli=${PENDING_COUNT_CLI}"
244   fi
245   PENDING_COUNT_MULTICLOUD=$(kubectl get pods -n $ENVIRON | grep multicloud- | grep -E '0/|1/2' | wc -l)
246   if [ "$PENDING_COUNT_MULTICLOUD" -gt 0 ]; then
247     echo "down-multicloud=${PENDING_COUNT_MULTICLOUD}"
248   fi
249   PENDING_COUNT_CLAMP=$(kubectl get pods -n $ENVIRON | grep clamp- | grep -E '0/|1/2' | wc -l)
250   if [ "$PENDING_COUNT_CLAMP" -gt 0 ]; then
251     echo "down-clamp=${PENDING_COUNT_CLAMP}"
252   fi
253   PENDING_COUNT_VNFSDK=$(kubectl get pods -n $ENVIRON | grep vnfsdk- | grep -E '0/|1/2' | wc -l)
254   if [ "$PENDING_COUNT_VNFSDK" -gt 0 ]; then
255     echo "down-vnfsdk=${PENDING_COUNT_VNFSDK}"
256   fi
257   PENDING_COUNT_UUI=$(kubectl get pods -n $ENVIRON | grep uui- | grep -E '0/|1/2' | wc -l)
258   if [ "$PENDING_COUNT_UUI" -gt 0 ]; then
259     echo "down-uui=${PENDING_COUNT_UUI}"
260   fi
261   PENDING_COUNT_VFC=$(kubectl get pods -n $ENVIRON | grep vfc- | grep -E '0/|1/2' | wc -l)
262   if [ "$PENDING_COUNT_VFC" -gt 0 ]; then
263     echo "down-vfc=${PENDING_COUNT_VFC}"
264   fi
265   PENDING_COUNT_KUBE2MSB=$(kubectl get pods -n $ENVIRON | grep kube2msb- | grep -E '0/|1/2' | wc -l)
266   if [ "$PENDING_COUNT_KUBE2MSB" -gt 0 ]; then
267     echo "down-kube2msb=${PENDING_COUNT_KUBE2MSB}"
268   fi
269   echo "pending containers=${PENDING_COUNT}"
270   echo "${PENDING}"
271
272   echo "check filebeat 2/2 count for ELK stack logging consumption"
273   FILEBEAT=$(kubectl get pods --all-namespaces -a | grep 2/)
274   echo "${FILEBEAT}"
275   echo "sleep 5 min - to allow rest frameworks to finish"
276   sleep 300
277   echo "List of ONAP Modules"
278   LIST_ALL=$(kubectl get pods --all-namespaces -a  --show-all )
279   echo "${LIST_ALL}"
280   echo "run healthcheck 2 times to warm caches and frameworks so rest endpoints report properly - see OOM-447"
281
282   echo "curl with aai cert to cloud-region PUT"
283
284   curl -X PUT https://127.0.0.1:30233/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne --data "@aai-cloud-region-put.json" -H "authorization: Basic TW9kZWxMb2FkZXI6TW9kZWxMb2FkZXI=" -H "X-TransactionId:jimmy-postman" -H "X-FromAppId:AAI" -H "Content-Type:application/json" -H "Accept:application/json" --cacert aaiapisimpledemoopenecomporg_20171003.crt -k
285
286   echo "get the cloud region back"
287   curl -X GET https://127.0.0.1:30233/aai/v11/cloud-infrastructure/cloud-regions/ -H "authorization: Basic TW9kZWxMb2FkZXI6TW9kZWxMb2FkZXI=" -H "X-TransactionId:jimmy-postman" -H "X-FromAppId:AAI" -H "Content-Type:application/json" -H "Accept:application/json" --cacert aaiapisimpledemoopenecomporg_20171003.crt -k
288
289   # OOM-484 - robot scripts moved
290   cd oom/kubernetes/robot
291   echo "run healthcheck prep 1"
292   # OOM-722 adds namespace parameter
293   if [ "$BRANCH" == "amsterdam" ]; then
294     ./ete-k8s.sh health > ~/health1.out
295   else
296     ./ete-k8s.sh $ENVIRON health > ~/health1.out
297   fi
298   echo "sleep 5 min"
299   sleep 300
300   echo "run healthcheck prep 2"
301   if [ "$BRANCH" == "amsterdam" ]; then
302     ./ete-k8s.sh health > ~/health2.out
303   else
304     ./ete-k8s.sh $ENVIRON health > ~/health2.out
305   fi
306   echo "run healthcheck for real - wait a further 5 min"
307   sleep 300
308   if [ "$BRANCH" == "amsterdam" ]; then
309     ./ete-k8s.sh health
310   else
311     ./ete-k8s.sh $ENVIRON health
312   fi
313   echo "run partial vFW"
314 #  sudo chmod 777 /dockerdata-nfs/onap
315 #  if [ "$BRANCH" == "amsterdam" ]; then
316 #    ./demo-k8s.sh init_robot
317 #  else
318 #    ./demo-k8s.sh $ENVIRON init
319 #  fi
320 #  if [ "$BRANCH" == "amsterdam" ]; then
321 #    ./demo-k8s.sh init
322 #  else
323 #    ./demo-k8s.sh $ENVIRON init
324 #  fi
325   echo "report results"
326   cd ../../../
327   
328   echo "$(date)"
329   #set +a
330 }
331
332 BRANCH=
333 ENVIRON=onap
334 APPLY_WORKAROUNDS=true
335 DELETE_PREV_OOM=false
336 REMOVE_OOM_AT_END=false
337 CLONE_NEW_OOM=true
338 SPLIT_DEPLOY_DELAY=600
339
340 while getopts ":u:b:e:s:c:d:w:r" PARAM; do
341   case $PARAM in
342     u)
343       usage
344       exit 1
345       ;;
346     b)
347       BRANCH=${OPTARG}
348       ;;
349     e)
350       ENVIRON=${OPTARG}
351       ;;
352     s)
353       SPLIT_DEPLOY_DELAY=${OPTARG}
354       ;;
355     c)
356       CLONE_NEW_OOM=${OPTARG}
357       ;;
358     d)
359       DELETE_PREV_OOM=${OPTARG}
360       ;;
361     w)
362       APPLY_WORKAROUNDS=${OPTARG}
363       ;;
364     r)
365       REMOVE_OOM_AT_END=${OPTARG}
366       ;;
367     ?)
368       usage
369       exit
370       ;;
371   esac
372 done
373
374 if [[ -z $BRANCH ]]; then
375   usage
376   exit 1
377 fi
378
379 deploy_onap  $BRANCH $ENVIRON $SPLIT_DEPLOY_DELAY $CLONE_NEW_OOM $DELETE_PREV_OOM $APPLY_WORKAROUNDS $REMOVE_OOM_AT_END
380
381 printf "**** Done ****\n"