blob: 5a99b19623efb1dcc9a5ae06c557ae254f5048d6 [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() {
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}
tzvika avni213d2ef2017-09-07 17:54:15 +030034
Mandeep Khindad6ea9872017-06-24 11:49:37 -040035create_namespace() {
tzvika avni213d2ef2017-09-07 17:54:15 +030036 cmd=`echo kubectl create namespace $1-$2`
37 eval ${cmd}
38 check_return_code $cmd
Mandeep Khindad6ea9872017-06-24 11:49:37 -040039}
40
Borislav Glozman5197e2e2017-07-24 10:45:28 +030041create_registry_key() {
tzvika avni213d2ef2017-09-07 17:54:15 +030042 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
Borislav Glozman5197e2e2017-07-24 10:45:28 +030045}
46
Mandeep Khindade8d47e2017-09-21 18:22:10 +000047configure_dcaegen2() {
48 if [ ! -s "$OPENSTACK_PRIVATE_KEY_PATH" ]
49 then
50 echo "ERROR: $OPENSTACK_PRIVATE_KEY_PATH does not exist or is empty. Cannot launch dcae gen2."
51 return 1
52 fi
53
54 cmd=`echo kubectl --namespace $1-$2 create secret generic $2-openstack-ssh-private-key --from-file=key=${OPENSTACK_PRIVATE_KEY_PATH}`
55 eval ${cmd}
56 check_return_code $cmd
57
58 if [ ! -s "$DCAEGEN2_CONFIG_INPUT_FILE_PATH" ]
59 then
60 echo "ERROR: $DCAEGEN2_CONFIG_INPUT_FILE_PATH does not exist or is empty. Cannot launch dcae gen2."
61 return 1
62 fi
63
64 cmd=`echo kubectl --namespace $1-$2 create configmap $2-config-inputs --from-file=inputs.yaml=${DCAEGEN2_CONFIG_INPUT_FILE_PATH}`
65 eval ${cmd}
66 check_return_code $cmd
67}
68
kerenj74d723a2017-08-22 15:27:04 +000069create_onap_helm() {
tzvika avnie3cbfa32017-09-07 16:42:37 +030070 HELM_VALUES_ADDITION=""
tzvika avni67a81112017-09-07 19:43:57 +030071 if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
72 HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
tzvika avnie3cbfa32017-09-07 16:42:37 +030073 fi
Mandeep Khindade8d47e2017-09-21 18:22:10 +000074 # Have to put a check for dcaegen2 because it requires external files to helm
75 # which should not be part of the Chart.
76 if [ "$2" = "dcaegen2" ];
77 then
78 configure_dcaegen2 $1 $2
79 local result=$?
80 if [ $result -ne 0 ]
81 then
82 echo "ERROR: dcaegen2 failed to configure: Pre-requisites not met. Skipping deploying it and continue"
83 return
84 fi
85 fi
86
tzvika58a0c102018-01-11 10:41:47 +020087 # assign default auth token
88 if [[ -z $ONAP_DEFAULT_AUTH_TOKEN ]]; then
Nicolas Hu6ef600c2018-02-01 14:21:32 -050089 DEFAULT_SECRET=`kubectl get secrets -n $1-$2 | grep default-token | awk '{ print $1}'`
90 ONAP_DEFAULT_AUTH_TOKEN=`kubectl get secrets $DEFAULT_SECRET -n $1-$2 -o yaml | grep 'token:' | awk '{ print $2}' | base64 --decode`
tzvika58a0c102018-01-11 10:41:47 +020091 fi
92
93 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 +030094 eval ${cmd}
95 check_return_code $cmd
Mike Elliottd17accd2017-08-14 16:21:40 -040096}
97
Mandeep Khindad6ea9872017-06-24 11:49:37 -040098#MAINs
99NS=
tzvika avni67a81112017-09-07 19:43:57 +0300100HELM_VALUES_FILEPATH=""
101LOCATION="../"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400102INCL_SVC=true
103APP=
Munir Ahmad87b01092017-08-09 14:51:11 -0400104INSTANCE=1
105MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300106DU=$ONAP_DOCKER_USER
107DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400108
tzvika avni67a81112017-09-07 19:43:57 +0300109while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400110 case $PARAM in
111 u)
112 usage
113 exit 1
114 ;;
115 n)
116 NS=${OPTARG}
117 ;;
tzvika avnie3cbfa32017-09-07 16:42:37 +0300118 v)
119 HELM_VALUES_FILEPATH=${OPTARG}
120 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -0400121 i)
122 INSTANCE=${OPTARG}
123 ;;
tzvika avni67a81112017-09-07 19:43:57 +0300124 l)
125 LOCATION=${OPTARG}
126 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400127 a)
128 APP=${OPTARG}
129 if [[ -z $APP ]]; then
130 usage
131 exit 1
132 fi
133 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300134 du)
135 DU=${OPTARG}
136 ;;
137 dp)
138 DP=${OPTARG}
139 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400140 ?)
141 usage
142 exit
143 ;;
144 esac
145done
146
147if [[ -z $NS ]]; then
148 usage
149 exit 1
150fi
151
152if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +0000153 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400154fi
155
Munir Ahmad87b01092017-08-09 14:51:11 -0400156
kerenj80102842017-08-24 13:54:21 +0000157if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
158 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
159 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
160 exit 1
Munir Ahmad87b01092017-08-09 14:51:11 -0400161fi
162
kerenj80102842017-08-24 13:54:21 +0000163start=$((300+2*INSTANCE))
164end=$((start+1))
165
166printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
167
168
Mike Elliottd17accd2017-08-14 16:21:40 -0400169printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400170
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400171
kerenj80102842017-08-24 13:54:21 +0000172printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400173
kerenj74d723a2017-08-22 15:27:04 +0000174for i in ${HELM_APPS[@]}; do
175 printf "\nCreating namespace **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300176 create_namespace $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000177
Anaël Closson40cdf492017-10-09 14:52:24 +0200178 printf "\nCreating service account **********\n"
179 create_service_account $NS $i
180
kerenj74d723a2017-08-22 15:27:04 +0000181 printf "\nCreating registry secret **********\n"
Mandeep Khinda0e8f8892017-08-25 03:31:17 +0000182 create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
kerenj74d723a2017-08-22 15:27:04 +0000183
184 printf "\nCreating deployments and services **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300185 create_onap_helm $NS $i $start
kerenj74d723a2017-08-22 15:27:04 +0000186
187 printf "\n"
188done
189
Munir Ahmad87b01092017-08-09 14:51:11 -0400190printf "\n**** Done ****\n"