4a6ab0065cd722be3621bc086587e56f9613a334
[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, vid, aaf, uui
17                       sdnc, portal, policy, appc, multicloud, clamp, consul, vnfsdk
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 create_service_account() {
30   cmd=`echo kubectl create clusterrolebinding $1-$2-admin-binding --clusterrole=cluster-admin --serviceaccount=$1-$2:default`
31   eval ${cmd}
32   check_return_code $cmd
33 }
34
35 create_namespace() {
36   cmd=`echo kubectl create namespace $1-$2`
37   eval ${cmd}
38   check_return_code $cmd
39 }
40
41 create_registry_key() {
42   cmd=`echo kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7`
43   eval ${cmd}
44   check_return_code $cmd
45 }
46
47 create_onap_helm() {
48   HELM_VALUES_ADDITION=""
49   if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
50     HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
51   fi
52
53   cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
54   eval ${cmd}
55   check_return_code $cmd
56 }
57
58 #MAINs
59 NS=
60 HELM_VALUES_FILEPATH=""
61 LOCATION="../"
62 INCL_SVC=true
63 APP=
64 INSTANCE=1
65 MAX_INSTANCE=5
66 DU=$ONAP_DOCKER_USER
67 DP=$ONAP_DOCKER_PASS
68
69 while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
70   case $PARAM in
71     u)
72       usage
73       exit 1
74       ;;
75     n)
76       NS=${OPTARG}
77       ;;
78     v)
79       HELM_VALUES_FILEPATH=${OPTARG}
80       ;;
81     i)
82       INSTANCE=${OPTARG}
83       ;;
84     l)
85       LOCATION=${OPTARG}
86       ;;
87     a)
88       APP=${OPTARG}
89       if [[ -z $APP ]]; then
90         usage
91         exit 1
92       fi
93       ;;
94     du)
95       DU=${OPTARG}
96       ;;
97     dp)
98       DP=${OPTARG}
99       ;;
100     ?)
101       usage
102       exit
103       ;;
104   esac
105 done
106
107 if [[ -z $NS ]]; then
108   usage
109   exit 1
110 fi
111
112 if [[ ! -z "$APP" ]]; then
113   HELM_APPS=($APP)
114 fi
115
116
117 if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
118   printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
119   printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
120   exit 1
121 fi
122
123 start=$((300+2*INSTANCE))
124 end=$((start+1))
125
126 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
127
128
129 printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
130
131
132 printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
133
134 for i in ${HELM_APPS[@]}; do
135   printf "\nCreating namespace **********\n"
136   create_namespace $NS $i
137
138   printf "\nCreating service account **********\n"
139   create_service_account $NS $i
140
141   printf "\nCreating registry secret **********\n"
142   create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
143
144   printf "\nCreating deployments and services **********\n"
145   create_onap_helm $NS $i $start
146
147   printf "\n"
148 done
149
150 printf "\n**** Done ****\n"