upgrade rancher/k8s to 1.6.25
[logging-analytics.git] / deploy / cd.sh
1 #!/bin/bash
2 #############################################################################
3 #
4 # Copyright © 2018 Amdocs, Bell.
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 # v20181207
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 -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 -c true -d false -w true -r false (standard new server/dev environment - use this as the default)
31 provide a dev.yaml override - 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 -c [true|false]     : FLAG clone new oom repo (default: true)
37 -d [true|false]     : FLAG delete prev oom - (cd build) (default: false)
38 -w [true|false]     : FLAG apply workarounds  IE: sdnc (default: true)
39 -r [true|false]     : FLAG remove oom at end of script - for use by CD only (default: false)
40 EOF
41 }
42
43 deploy_onap() {
44   
45   echo "$(date)"
46   echo "running with: -b $BRANCH -e $ENVIRON -c $CLONE_NEW_OOM -d $DELETE_PREV_OOM -w $APPLY_WORKAROUNDS -r $REMOVE_OOM_AT_END"
47   echo "provide onap-parameters.yaml(amsterdam) or values.yaml(master) and aai-cloud-region-put.json"
48   echo "provide a dev.yaml override - copy from https://git.onap.org/oom/tree/kubernetes/onap/resources/environments/dev.yaml"
49   #exit 0
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       # workaround for secondary orchestration in dcae
59       kubectl delete namespace $ENVIRON
60       echo "sleep for 4 min to allow the delete to finish pod terminations before trying a helm delete"
61       sleep 240
62       sudo helm delete --purge $ENVIRON
63     fi
64
65     sleep 1
66     # verify
67     DELETED=$(kubectl get pods --all-namespaces -a | -E '0/|1/2' | wc -l)
68     echo "verify deletion is finished."
69     while [  $(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l) -gt 0 ]; do
70       sleep 15
71       echo "waiting for deletions to complete"
72     done
73     # wait for 0/1 before deleting
74     echo "sleeping 30 sec"
75     # delete potential hanging clustered pods
76     #kubectl delete pod $ENVIRON-aaf-sms-vault-0 -n $ENVIRON --grace-period=0 --force
77     # specific to when there is no helm release
78     # see https://wiki.onap.org/display/DW/Cloud+Native+Deployment#CloudNativeDeployment-RemoveaDeployment
79     kubectl delete pv --all
80     kubectl delete pvc --all
81     kubectl delete secrets --all
82     kubectl delete clusterrolebinding --all
83     # replace with watch
84     # keep jenkins 120 sec timeout happy with echos
85     sleep 30
86     echo "List of ONAP Modules - look for terminating pods"
87     LIST_ALL=$(kubectl get pods --all-namespaces --show-all -o wide )
88     echo "${LIST_ALL}"
89
90     # for use by continuous deployment only
91     echo " deleting /dockerdata-nfs"
92     sudo chmod -R 777 /dockerdata-nfs/onap
93     sudo chmod -R 777 /dockerdata-nfs/dev
94     rm -rf /dockerdata-nfs/onap
95     rm -rf /dockerdata-nfs/dev
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     sudo helm deploy onap local/onap --namespace $ENVIRON -f ../../dev.yaml
143     cd ../../
144   fi
145
146   echo "wait for all pods up for 15-80 min"
147   FAILED_PODS_LIMIT=0
148   MAX_WAIT_PERIODS=480 # 120 MIN
149   COUNTER=0
150   PENDING_PODS=0
151   while [  $(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l) -gt $FAILED_PODS_LIMIT ]; do
152     PENDING=$(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l)
153     PENDING_PODS=$PENDING
154     sleep 15
155     LIST_PENDING=$(kubectl get pods --all-namespaces -o wide | grep -E '0/|1/2' )
156     echo "${LIST_PENDING}"
157     echo "${PENDING} pending > ${FAILED_PODS_LIMIT} at the ${COUNTER}th 15 sec interval"
158     echo ""
159     COUNTER=$((COUNTER + 1 ))
160     MAX_WAIT_PERIODS=$((MAX_WAIT_PERIODS - 1))
161     if [ "$MAX_WAIT_PERIODS" -eq 0 ]; then
162       FAILED_PODS_LIMIT=800
163     fi
164   done
165
166   echo "report on non-running containers"
167   PENDING=$(kubectl get pods --all-namespaces | grep -E '0/|1/2')
168   PENDING_COUNT=$(kubectl get pods --all-namespaces | grep -E '0/|1/2' | wc -l)
169   PENDING_COUNT_AAI=$(kubectl get pods -n $ENVIRON | grep aai- | grep -E '0/|1/2' | wc -l)
170   if [ "$PENDING_COUNT_AAI" -gt 0 ]; then
171     echo "down-aai=${PENDING_COUNT_AAI}"
172   fi
173
174   # todo don't stop if aai is down
175   PENDING_COUNT_APPC=$(kubectl get pods -n $ENVIRON | grep appc- | grep -E '0/|1/2' | wc -l)
176   if [ "$PENDING_COUNT_APPC" -gt 0 ]; then
177     echo "down-appc=${PENDING_COUNT_APPC}"
178   fi
179   PENDING_COUNT_MR=$(kubectl get pods -n $ENVIRON | grep message-router- | grep -E '0/|1/2' | wc -l)
180   if [ "$PENDING_COUNT_MR" -gt 0 ]; then
181     echo "down-mr=${PENDING_COUNT_MR}"
182   fi
183   PENDING_COUNT_SO=$(kubectl get pods -n $ENVIRON | grep so- | grep -E '0/|1/2' | wc -l)
184   if [ "$PENDING_COUNT_SO" -gt 0 ]; then
185     echo "down-so=${PENDING_COUNT_SO}"
186   fi
187   PENDING_COUNT_POLICY=$(kubectl get pods -n $ENVIRON | grep policy- | grep -E '0/|1/2' | wc -l)
188   if [ "$PENDING_COUNT_POLICY" -gt 0 ]; then
189     echo "down-policy=${PENDING_COUNT_POLICY}"
190   fi
191   PENDING_COUNT_PORTAL=$(kubectl get pods -n $ENVIRON | grep portal- | grep -E '0/|1/2' | wc -l)
192   if [ "$PENDING_COUNT_PORTAL" -gt 0 ]; then
193     echo "down-portal=${PENDING_COUNT_PORTAL}"
194   fi
195   PENDING_COUNT_LOG=$(kubectl get pods -n $ENVIRON | grep log- | grep -E '0/|1/2' | wc -l)
196   if [ "$PENDING_COUNT_LOG" -gt 0 ]; then
197     echo "down-log=${PENDING_COUNT_LOG}"
198   fi
199   PENDING_COUNT_ROBOT=$(kubectl get pods -n $ENVIRON | grep robot- | grep -E '0/|1/2' | wc -l)
200   if [ "$PENDING_COUNT_ROBOT" -gt 0 ]; then
201     echo "down-robot=${PENDING_COUNT_ROBOT}"
202   fi
203   PENDING_COUNT_SDC=$(kubectl get pods -n $ENVIRON | grep sdc- | grep -E '0/|1/2' | wc -l)
204   if [ "$PENDING_COUNT_SDC" -gt 0 ]; then
205     echo "down-sdc=${PENDING_COUNT_SDC}"
206   fi
207   PENDING_COUNT_SDNC=$(kubectl get pods -n $ENVIRON | grep sdnc- | grep -E '0/|1/2' | wc -l)
208   if [ "$PENDING_COUNT_SDNC" -gt 0 ]; then
209     echo "down-sdnc=${PENDING_COUNT_SDNC}"
210   fi
211   PENDING_COUNT_VID=$(kubectl get pods -n $ENVIRON | grep vid- | grep -E '0/|1/2' | wc -l)
212   if [ "$PENDING_COUNT_VID" -gt 0 ]; then
213     echo "down-vid=${PENDING_COUNT_VID}"
214   fi
215
216   PENDING_COUNT_AAF=$(kubectl get pods -n $ENVIRON | grep aaf- | grep -E '0/|1/2' | wc -l)
217   if [ "$PENDING_COUNT_AAF" -gt 0 ]; then
218     echo "down-aaf=${PENDING_COUNT_AAF}"
219   fi
220   PENDING_COUNT_CONSUL=$(kubectl get pods -n $ENVIRON | grep consul- | grep -E '0/|1/2' | wc -l)
221   if [ "$PENDING_COUNT_CONSUL" -gt 0 ]; then
222     echo "down-consul=${PENDING_COUNT_CONSUL}"
223   fi
224   PENDING_COUNT_MSB=$(kubectl get pods -n $ENVIRON | grep msb- | grep -E '0/|1/2' | wc -l)
225   if [ "$PENDING_COUNT_MSB" -gt 0 ]; then
226     echo "down-msb=${PENDING_COUNT_MSB}"
227   fi
228   PENDING_COUNT_DCAE=$(kubectl get pods -n $ENVIRON | grep dcaegen2- | grep -E '0/|1/2' | wc -l)
229   if [ "$PENDING_COUNT_DCAE" -gt 0 ]; then
230     echo "down-dcae=${PENDING_COUNT_DCAE}"
231   fi
232   PENDING_COUNT_CLI=$(kubectl get pods -n $ENVIRON | grep cli- | grep -E '0/|1/2' | wc -l)
233   if [ "$PENDING_COUNT_CLI" -gt 0 ]; then
234     echo "down-cli=${PENDING_COUNT_CLI}"
235   fi
236   PENDING_COUNT_MULTICLOUD=$(kubectl get pods -n $ENVIRON | grep multicloud- | grep -E '0/|1/2' | wc -l)
237   if [ "$PENDING_COUNT_MULTICLOUD" -gt 0 ]; then
238     echo "down-multicloud=${PENDING_COUNT_MULTICLOUD}"
239   fi
240   PENDING_COUNT_CLAMP=$(kubectl get pods -n $ENVIRON | grep clamp- | grep -E '0/|1/2' | wc -l)
241   if [ "$PENDING_COUNT_CLAMP" -gt 0 ]; then
242     echo "down-clamp=${PENDING_COUNT_CLAMP}"
243   fi
244   PENDING_COUNT_VNFSDK=$(kubectl get pods -n $ENVIRON | grep vnfsdk- | grep -E '0/|1/2' | wc -l)
245   if [ "$PENDING_COUNT_VNFSDK" -gt 0 ]; then
246     echo "down-vnfsdk=${PENDING_COUNT_VNFSDK}"
247   fi
248   PENDING_COUNT_UUI=$(kubectl get pods -n $ENVIRON | grep uui- | grep -E '0/|1/2' | wc -l)
249   if [ "$PENDING_COUNT_UUI" -gt 0 ]; then
250     echo "down-uui=${PENDING_COUNT_UUI}"
251   fi
252   PENDING_COUNT_VFC=$(kubectl get pods -n $ENVIRON | grep vfc- | grep -E '0/|1/2' | wc -l)
253   if [ "$PENDING_COUNT_VFC" -gt 0 ]; then
254     echo "down-vfc=${PENDING_COUNT_VFC}"
255   fi
256   PENDING_COUNT_KUBE2MSB=$(kubectl get pods -n $ENVIRON | grep kube2msb- | grep -E '0/|1/2' | wc -l)
257   if [ "$PENDING_COUNT_KUBE2MSB" -gt 0 ]; then
258     echo "down-kube2msb=${PENDING_COUNT_KUBE2MSB}"
259   fi
260   echo "pending containers=${PENDING_COUNT}"
261   echo "${PENDING}"
262
263   echo "check filebeat 2/2 count for ELK stack logging consumption"
264   FILEBEAT=$(kubectl get pods --all-namespaces -a | grep 2/)
265   echo "${FILEBEAT}"
266   echo "sleep 5 min - to allow rest frameworks to finish"
267   sleep 300
268   echo "List of ONAP Modules"
269   LIST_ALL=$(kubectl get pods --all-namespaces -a  --show-all )
270   echo "${LIST_ALL}"
271   echo "run healthcheck 2 times to warm caches and frameworks so rest endpoints report properly - see OOM-447"
272
273   echo "curl with aai cert to cloud-region PUT"
274
275   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
276
277   echo "get the cloud region back"
278   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
279
280   # OOM-484 - robot scripts moved
281   cd oom/kubernetes/robot
282   echo "run healthcheck prep 1"
283   # OOM-722 adds namespace parameter
284   if [ "$BRANCH" == "amsterdam" ]; then
285     ./ete-k8s.sh health > ~/health1.out
286   else
287     ./ete-k8s.sh $ENVIRON health > ~/health1.out
288   fi
289   echo "sleep 5 min"
290   sleep 300
291   echo "run healthcheck prep 2"
292   if [ "$BRANCH" == "amsterdam" ]; then
293     ./ete-k8s.sh health > ~/health2.out
294   else
295     ./ete-k8s.sh $ENVIRON health > ~/health2.out
296   fi
297   echo "run healthcheck for real - wait a further 5 min"
298   sleep 300
299   if [ "$BRANCH" == "amsterdam" ]; then
300     ./ete-k8s.sh health
301   else
302     ./ete-k8s.sh $ENVIRON health
303   fi
304   echo "run partial vFW"
305 #  sudo chmod 777 /dockerdata-nfs/onap
306 #  if [ "$BRANCH" == "amsterdam" ]; then
307 #    ./demo-k8s.sh init_robot
308 #  else
309 #    ./demo-k8s.sh $ENVIRON init
310 #  fi
311 #  if [ "$BRANCH" == "amsterdam" ]; then
312 #    ./demo-k8s.sh init
313 #  else
314 #    ./demo-k8s.sh $ENVIRON init
315 #  fi
316   echo "report results"
317   cd ../../../
318   
319   echo "$(date)"
320   #set +a
321 }
322
323 BRANCH=
324 ENVIRON=onap
325 APPLY_WORKAROUNDS=true
326 DELETE_PREV_OOM=false
327 REMOVE_OOM_AT_END=false
328 CLONE_NEW_OOM=true
329
330 while getopts ":u:b:e:c:d:w:r" PARAM; do
331   case $PARAM in
332     u)
333       usage
334       exit 1
335       ;;
336     b)
337       BRANCH=${OPTARG}
338       ;;
339     e)
340       ENVIRON=${OPTARG}
341       ;;
342     c)
343       CLONE_NEW_OOM=${OPTARG}
344       ;;
345     d)
346       DELETE_PREV_OOM=${OPTARG}
347       ;;
348     w)
349       APPLY_WORKAROUNDS=${OPTARG}
350       ;;
351     r)
352       REMOVE_OOM_AT_END=${OPTARG}
353       ;;
354     ?)
355       usage
356       exit
357       ;;
358   esac
359 done
360
361 if [[ -z $BRANCH ]]; then
362   usage
363   exit 1
364 fi
365
366 deploy_onap  $BRANCH $ENVIRON $CLONE_NEW_OOM $DELETE_PREV_OOM $APPLY_WORKAROUNDS $REMOVE_OOM_AT_END
367
368 printf "**** Done ****\n"