Merge "Added CLAMP containers to ONAP Kubernetes"
[oom.git] / kubernetes / oneclick / createAll.bash
1 #!/bin/bash
2
3 . $(dirname "$0")/setenv.bash
4
5
6 usage() {
7   cat <<EOF
8 Usage: $0 [PARAMs]
9 -u                  : Display usage
10 -n [NAMESPACE]      : Kubernetes namespace (required)
11 -v [VALUES]         : HELM values filepath (usefull when deploying one component at a time)
12 -l [LOCATION]       : Location of oom project
13 -i [INSTANCE]       : ONAP deployment instance # (default: 1)
14 -a [APP]            : Specify a specific ONAP component (default: all)
15                       from the following choices:
16                       sdc, aai ,mso, message-router, robot,
17                       vid, sdnc, portal, policy, appc, multicloud, clamp
18 EOF
19 }
20
21 check_return_code(){
22   ret=$?
23   if [ $ret -ne 0 ]; then
24     printf "The command $1 returned with error code $ret \n" 1>&2
25     exit $ret
26   fi
27 }
28
29
30 create_namespace() {
31   cmd=`echo kubectl create namespace $1-$2`
32   eval ${cmd}
33   check_return_code $cmd
34 }
35
36 create_registry_key() {
37   cmd=`echo kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7`
38   eval ${cmd}
39   check_return_code $cmd
40 }
41
42 create_onap_helm() {
43   HELM_VALUES_ADDITION=""
44   if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
45     HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
46   fi
47   cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
48   eval ${cmd}
49   check_return_code $cmd
50 }
51
52 #MAINs
53 NS=
54 HELM_VALUES_FILEPATH=""
55 LOCATION="../"
56 INCL_SVC=true
57 APP=
58 INSTANCE=1
59 MAX_INSTANCE=5
60 DU=$ONAP_DOCKER_USER
61 DP=$ONAP_DOCKER_PASS
62
63 while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
64   case $PARAM in
65     u)
66       usage
67       exit 1
68       ;;
69     n)
70       NS=${OPTARG}
71       ;;
72     v)
73       HELM_VALUES_FILEPATH=${OPTARG}
74       ;;
75     i)
76       INSTANCE=${OPTARG}
77       ;;
78     l)
79       LOCATION=${OPTARG}
80       ;;
81     a)
82       APP=${OPTARG}
83       if [[ -z $APP ]]; then
84         usage
85         exit 1
86       fi
87       ;;
88     du)
89       DU=${OPTARG}
90       ;;
91     dp)
92       DP=${OPTARG}
93       ;;
94     ?)
95       usage
96       exit
97       ;;
98   esac
99 done
100
101 if [[ -z $NS ]]; then
102   usage
103   exit 1
104 fi
105
106 if [[ ! -z "$APP" ]]; then
107   HELM_APPS=($APP)
108 fi
109
110
111 if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
112   printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
113   printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
114   exit 1
115 fi
116
117 start=$((300+2*INSTANCE))
118 end=$((start+1))
119
120 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
121
122
123 printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
124
125
126 printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
127
128 for i in ${HELM_APPS[@]}; do
129   printf "\nCreating namespace **********\n"
130   create_namespace $NS $i
131
132   printf "\nCreating registry secret **********\n"
133   create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
134
135   printf "\nCreating deployments and services **********\n"
136   create_onap_helm $NS $i $start
137
138   printf "\n"
139 done
140
141 printf "\n**** Done ****\n"