remove passing auth token via env var
[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-admin-binding --clusterrole=cluster-admin --serviceaccount=$1:default`
31   eval ${cmd}
32   check_return_code $cmd
33 }
34
35 create_namespace() {
36   cmd=`echo kubectl create namespace $1`
37   eval ${cmd}
38 }
39
40 create_registry_key() {
41 cmd=`echo kubectl --namespace $1 create secret docker-registry $2 --docker-server=$3 --docker-username=$4 --docker-password=$5 --docker-email=$6`
42   eval ${cmd}
43   check_return_code $cmd
44 }
45
46 configure_dcaegen2() {
47   if [ ! -s "$OPENSTACK_PRIVATE_KEY_PATH" ]
48   then
49     echo "ERROR: $OPENSTACK_PRIVATE_KEY_PATH does not exist or is empty.  Cannot launch dcae gen2."
50     return 1
51   fi
52
53   cmd=`echo kubectl --namespace $1-$2 create secret generic $2-openstack-ssh-private-key --from-file=key=${OPENSTACK_PRIVATE_KEY_PATH}`
54   eval ${cmd}
55   check_return_code $cmd
56
57   if [ ! -s "$DCAEGEN2_CONFIG_INPUT_FILE_PATH" ]
58   then
59     echo "ERROR: $DCAEGEN2_CONFIG_INPUT_FILE_PATH does not exist or is empty.  Cannot launch dcae gen2."
60     return 1
61   fi
62
63   cmd=`echo kubectl --namespace $1-$2 create configmap $2-config-inputs --from-file=inputs.yaml=${DCAEGEN2_CONFIG_INPUT_FILE_PATH}`
64   eval ${cmd}
65   check_return_code $cmd
66 }
67
68 create_onap_helm() {
69   HELM_VALUES_ADDITION=""
70   if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
71     HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
72   fi
73   # Have to put a check for dcaegen2 because it requires external files to helm
74   # which should not be part of the Chart.
75   if [ "$2" = "dcaegen2" ];
76   then
77     configure_dcaegen2 $1 $2
78     local result=$?
79     if [ $result -ne 0 ]
80     then
81       echo "ERROR: dcaegen2 failed to configure: Pre-requisites not met.  Skipping deploying it and continue"
82       return
83     fi
84   fi
85
86   cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
87   eval ${cmd}
88   check_return_code $cmd
89 }
90
91 #MAINs
92 NS=
93 HELM_VALUES_FILEPATH=""
94 LOCATION="../"
95 INCL_SVC=true
96 APP=
97 INSTANCE=1
98 MAX_INSTANCE=5
99 DU=$ONAP_DOCKER_USER
100 DP=$ONAP_DOCKER_PASS
101
102 SINGLE_COMPONENT=false
103
104 while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
105   case $PARAM in
106     u)
107       usage
108       exit 1
109       ;;
110     n)
111       NS=${OPTARG}
112       ;;
113     v)
114       HELM_VALUES_FILEPATH=${OPTARG}
115       ;;
116     i)
117       INSTANCE=${OPTARG}
118       ;;
119     l)
120       LOCATION=${OPTARG}
121       ;;
122     a)
123       SINGLE_COMPONENT=true
124       APP=${OPTARG}
125       if [[ -z $APP ]]; then
126         usage
127         exit 1
128       fi
129       ;;
130     du)
131       DU=${OPTARG}
132       ;;
133     dp)
134       DP=${OPTARG}
135       ;;
136     ?)
137       usage
138       exit
139       ;;
140   esac
141 done
142
143 if [[ -z $NS ]]; then
144   usage
145   exit 1
146 fi
147
148 if [[ ! -z "$APP" ]]; then
149   HELM_APPS=($APP)
150 fi
151
152
153 if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
154   printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
155   printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
156   exit 1
157 fi
158
159 start=$((300+2*INSTANCE))
160 end=$((start+1))
161
162 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
163
164
165 printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
166
167 if [ "$SINGLE_COMPONENT" == "false" ]
168 then
169     printf "\nCreating namespace **********\n"
170     create_namespace $NS
171
172     printf "\nCreating registry secret **********\n"
173     create_registry_key $NS ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
174
175     printf "\nCreating service account **********\n"
176     create_service_account $NS
177 fi
178
179 printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
180
181 for i in ${HELM_APPS[@]}; do
182
183   printf "\nCreating deployments and services **********\n"
184   create_onap_helm $NS $i $start
185
186   printf "\n"
187 done
188
189 printf "\n**** Done ****\n"