Add K8S deployment above Vagrant
[sdc.git] / sdc-os-chef / scripts / k8s / deploy_k8s_sdc.sh
1 #!/bin/sh
2 set -x
3
4 check_status()
5 {
6   local rc=$1
7   shift
8   local comment="$@"
9   if [ ${rc} != 0 ]; then
10     echo "[ERR] Failure detected - ${comment}.  Aborting !"
11     exit 255
12   fi
13 }
14
15 check_pods_status()
16
17     num_of_pods=$1
18     status=0
19     while [ ${status} -ne ${num_of_pods} ]
20     do 
21       status=$(sudo kubectl get pods --namespace kube-system -o json \
22       | jq -r '
23         .items[]
24         | select(.status.phase == "Running" and 
25         ([ .status.conditions[] | select(.type == "Ready" and .status == "True") ]
26         | length ) == 1 )
27         | .metadata.namespace + "/" + .metadata.name
28         ' \
29       |  wc -l )
30       sleep 3
31     done
32 }
33
34 # Should be removed while private dockers (maven build) will be available:
35 echo "[INFO] ONAP Docker login"
36 sudo docker login -u docker -p docker nexus3.onap.org:10001
37 check_status $? "Onap docker registry login"
38
39 # Verify the kube-system pods are running:
40 # kube-addon-manager, kube-dns, kubernetes-dashboard, storage-provisioner, tiller-deploy
41 echo "[INFO] Wait for Kubernetes Service ..." 
42 cd ../../kubernetes
43
44 check_pods_status 4
45
46 # Create namespace 
47 echo "[INFO] Check Namespace existence"
48 exist_namespace=$( sudo kubectl get namespaces  | grep onap-sdc | grep Active | wc -l )
49 if [ ${exist_namespace} -eq 0 ]; then
50   sudo kubectl create namespace onap-sdc
51   check_status $? "Create namespace"
52 fi
53
54 echo "[INFO] Running helm init"
55 sudo helm init
56 check_status $? "Helm init"
57
58 check_pods_status 5
59
60 printf "[INFO] Wait for helm to get ready\n"
61 helm_health=1
62 while [ ${helm_health} -ne 0 ]
63 do 
64   sudo helm version | grep "Server" >/dev/null 2>&1
65   helm_health=$?
66   sleep 5
67 done
68
69 # Remove previous chart
70 exist_chart=$( sudo helm ls onap-sdc -q | wc -l )
71 if [ ${exist_chart} -ne 0 ];then
72   echo "[INFO] Delete the existing onap-sdc chart"
73   sudo helm del --purge onap-sdc
74   check_status $? "Delete chart"
75 fi
76
77 # Install updated chart
78 echo "[INFO] Create onap-sdc deployment"
79 sudo helm install sdc --name onap-sdc
80 check_status $? "Install chart"