blob: b7d6a64ffb3bddd5c35b9fa485b92d89b1d13cd6 [file] [log] [blame]
Mandeep Khindad6ea9872017-06-24 11:49:37 -04001#!/bin/bash
2
Borislav Glozman5197e2e2017-07-24 10:45:28 +03003. $(dirname "$0")/setenv.bash
4
kerenj74d723a2017-08-22 15:27:04 +00005
Mandeep Khindad6ea9872017-06-24 11:49:37 -04006usage() {
7 cat <<EOF
8Usage: $0 [PARAMs]
9-u : Display usage
10-n [NAMESPACE] : Kubernetes namespace (required)
tzvika avnie3cbfa32017-09-07 16:42:37 +030011-v [VALUES] : HELM values filepath (usefull when deploying one component at a time)
tzvika avni67a81112017-09-07 19:43:57 +030012-l [LOCATION] : Location of oom project
Munir Ahmad87b01092017-08-09 14:51:11 -040013-i [INSTANCE] : ONAP deployment instance # (default: 1)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040014-a [APP] : Specify a specific ONAP component (default: all)
15 from the following choices:
Dusan Rozman03aa27e2017-10-11 13:04:23 -040016 sdc, aai ,mso, message-router, robot, vid, aaf, uui
Dusan Rozman75c07c42017-09-25 10:28:28 -040017 sdnc, portal, policy, appc, multicloud, clamp, consul, vnfsdk
Mandeep Khindad6ea9872017-06-24 11:49:37 -040018EOF
19}
20
tzvika avni213d2ef2017-09-07 17:54:15 +030021check_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
Anaël Closson40cdf492017-10-09 14:52:24 +020029create_service_account() {
BorislavG8bfc6cf2018-02-27 15:04:26 +000030# cmd=`echo kubectl create clusterrolebinding $1-$2-admin-binding --clusterrole=cluster-admin --serviceaccount=$1-$2:default`
31 cmd=`echo kubectl create clusterrolebinding $1-$2-admin-binding --clusterrole=cluster-admin --serviceaccount=$1:default`
Anaël Closson40cdf492017-10-09 14:52:24 +020032 eval ${cmd}
33 check_return_code $cmd
34}
tzvika avni213d2ef2017-09-07 17:54:15 +030035
Mandeep Khindad6ea9872017-06-24 11:49:37 -040036create_namespace() {
BorislavG8bfc6cf2018-02-27 15:04:26 +000037 cmd=`echo kubectl create namespace $1`
tzvika avni213d2ef2017-09-07 17:54:15 +030038 eval ${cmd}
Mandeep Khindad6ea9872017-06-24 11:49:37 -040039}
40
Borislav Glozman5197e2e2017-07-24 10:45:28 +030041create_registry_key() {
BorislavG8bfc6cf2018-02-27 15:04:26 +000042# cmd=`echo kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7`
43cmd=`echo kubectl --namespace $1 create secret docker-registry $2 --docker-server=$3 --docker-username=$4 --docker-password=$5 --docker-email=$6`
tzvika avni213d2ef2017-09-07 17:54:15 +030044 eval ${cmd}
45 check_return_code $cmd
Borislav Glozman5197e2e2017-07-24 10:45:28 +030046}
47
Mandeep Khindade8d47e2017-09-21 18:22:10 +000048configure_dcaegen2() {
49 if [ ! -s "$OPENSTACK_PRIVATE_KEY_PATH" ]
50 then
51 echo "ERROR: $OPENSTACK_PRIVATE_KEY_PATH does not exist or is empty. Cannot launch dcae gen2."
52 return 1
53 fi
54
55 cmd=`echo kubectl --namespace $1-$2 create secret generic $2-openstack-ssh-private-key --from-file=key=${OPENSTACK_PRIVATE_KEY_PATH}`
56 eval ${cmd}
57 check_return_code $cmd
58
59 if [ ! -s "$DCAEGEN2_CONFIG_INPUT_FILE_PATH" ]
60 then
61 echo "ERROR: $DCAEGEN2_CONFIG_INPUT_FILE_PATH does not exist or is empty. Cannot launch dcae gen2."
62 return 1
63 fi
64
65 cmd=`echo kubectl --namespace $1-$2 create configmap $2-config-inputs --from-file=inputs.yaml=${DCAEGEN2_CONFIG_INPUT_FILE_PATH}`
66 eval ${cmd}
67 check_return_code $cmd
68}
69
kerenj74d723a2017-08-22 15:27:04 +000070create_onap_helm() {
tzvika avnie3cbfa32017-09-07 16:42:37 +030071 HELM_VALUES_ADDITION=""
tzvika avni67a81112017-09-07 19:43:57 +030072 if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
73 HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
tzvika avnie3cbfa32017-09-07 16:42:37 +030074 fi
Mandeep Khindade8d47e2017-09-21 18:22:10 +000075 # Have to put a check for dcaegen2 because it requires external files to helm
76 # which should not be part of the Chart.
77 if [ "$2" = "dcaegen2" ];
78 then
79 configure_dcaegen2 $1 $2
80 local result=$?
81 if [ $result -ne 0 ]
82 then
83 echo "ERROR: dcaegen2 failed to configure: Pre-requisites not met. Skipping deploying it and continue"
84 return
85 fi
86 fi
87
tzvika58a0c102018-01-11 10:41:47 +020088 # assign default auth token
89 if [[ -z $ONAP_DEFAULT_AUTH_TOKEN ]]; then
BorislavG8bfc6cf2018-02-27 15:04:26 +000090 DEFAULT_SECRET=`kubectl get secrets -n $1 | grep default-token | awk '{ print $1}'`
91 ONAP_DEFAULT_AUTH_TOKEN=`kubectl get secrets $DEFAULT_SECRET -n $1 -o yaml | grep 'token:' | awk '{ print $2}' | base64 --decode`
tzvika58a0c102018-01-11 10:41:47 +020092 fi
93
94 cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3,kubeMasterAuthToken=$ONAP_DEFAULT_AUTH_TOKEN ${HELM_VALUES_ADDITION}`
tzvika avni213d2ef2017-09-07 17:54:15 +030095 eval ${cmd}
96 check_return_code $cmd
Mike Elliottd17accd2017-08-14 16:21:40 -040097}
98
Mandeep Khindad6ea9872017-06-24 11:49:37 -040099#MAINs
100NS=
tzvika avni67a81112017-09-07 19:43:57 +0300101HELM_VALUES_FILEPATH=""
102LOCATION="../"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400103INCL_SVC=true
104APP=
Munir Ahmad87b01092017-08-09 14:51:11 -0400105INSTANCE=1
106MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300107DU=$ONAP_DOCKER_USER
108DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400109
BorislavG8bfc6cf2018-02-27 15:04:26 +0000110SINGLE_COMPONENT=false
111
tzvika avni67a81112017-09-07 19:43:57 +0300112while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400113 case $PARAM in
114 u)
115 usage
116 exit 1
117 ;;
118 n)
119 NS=${OPTARG}
120 ;;
tzvika avnie3cbfa32017-09-07 16:42:37 +0300121 v)
122 HELM_VALUES_FILEPATH=${OPTARG}
123 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -0400124 i)
125 INSTANCE=${OPTARG}
126 ;;
tzvika avni67a81112017-09-07 19:43:57 +0300127 l)
128 LOCATION=${OPTARG}
129 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400130 a)
BorislavG8bfc6cf2018-02-27 15:04:26 +0000131 SINGLE_COMPONENT=true
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400132 APP=${OPTARG}
133 if [[ -z $APP ]]; then
134 usage
135 exit 1
136 fi
137 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300138 du)
139 DU=${OPTARG}
140 ;;
141 dp)
142 DP=${OPTARG}
143 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400144 ?)
145 usage
146 exit
147 ;;
148 esac
149done
150
151if [[ -z $NS ]]; then
152 usage
153 exit 1
154fi
155
156if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +0000157 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400158fi
159
Munir Ahmad87b01092017-08-09 14:51:11 -0400160
kerenj80102842017-08-24 13:54:21 +0000161if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
162 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
163 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
164 exit 1
Munir Ahmad87b01092017-08-09 14:51:11 -0400165fi
166
kerenj80102842017-08-24 13:54:21 +0000167start=$((300+2*INSTANCE))
168end=$((start+1))
169
170printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
171
172
Mike Elliottd17accd2017-08-14 16:21:40 -0400173printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400174
BorislavG8bfc6cf2018-02-27 15:04:26 +0000175if [ "$SINGLE_COMPONENT" == "false" ]
176then
177 printf "\nCreating namespace **********\n"
178 create_namespace $NS
179
180 printf "\nCreating registry secret **********\n"
181 create_registry_key $NS ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
182fi
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400183
kerenj80102842017-08-24 13:54:21 +0000184printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400185
kerenj74d723a2017-08-22 15:27:04 +0000186for i in ${HELM_APPS[@]}; do
kerenj74d723a2017-08-22 15:27:04 +0000187
Anaël Closson40cdf492017-10-09 14:52:24 +0200188 printf "\nCreating service account **********\n"
189 create_service_account $NS $i
190
kerenj74d723a2017-08-22 15:27:04 +0000191 printf "\nCreating deployments and services **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300192 create_onap_helm $NS $i $start
kerenj74d723a2017-08-22 15:27:04 +0000193
194 printf "\n"
195done
196
Munir Ahmad87b01092017-08-09 14:51:11 -0400197printf "\n**** Done ****\n"