blob: 488f920e91f02f9acb64b6cc76775fd1a6d86fc3 [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() {
BorislavG042b6852018-03-04 15:03:52 +000030 cmd=`echo kubectl create clusterrolebinding $1-admin-binding --clusterrole=cluster-admin --serviceaccount=$1:default`
Anaël Closson40cdf492017-10-09 14:52:24 +020031 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() {
BorislavG8bfc6cf2018-02-27 15:04:26 +000036 cmd=`echo kubectl create namespace $1`
tzvika avni213d2ef2017-09-07 17:54:15 +030037 eval ${cmd}
Mandeep Khindad6ea9872017-06-24 11:49:37 -040038}
39
Borislav Glozman5197e2e2017-07-24 10:45:28 +030040create_registry_key() {
BorislavG8bfc6cf2018-02-27 15:04:26 +000041cmd=`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 +030042 eval ${cmd}
43 check_return_code $cmd
Borislav Glozman5197e2e2017-07-24 10:45:28 +030044}
45
Mandeep Khindade8d47e2017-09-21 18:22:10 +000046configure_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
kerenj74d723a2017-08-22 15:27:04 +000068create_onap_helm() {
tzvika avnie3cbfa32017-09-07 16:42:37 +030069 HELM_VALUES_ADDITION=""
tzvika avni67a81112017-09-07 19:43:57 +030070 if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
71 HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
tzvika avnie3cbfa32017-09-07 16:42:37 +030072 fi
Mandeep Khindade8d47e2017-09-21 18:22:10 +000073 # 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
tzvika58a0c102018-01-11 10:41:47 +020086 # assign default auth token
87 if [[ -z $ONAP_DEFAULT_AUTH_TOKEN ]]; then
BorislavG8bfc6cf2018-02-27 15:04:26 +000088 DEFAULT_SECRET=`kubectl get secrets -n $1 | grep default-token | awk '{ print $1}'`
89 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 +020090 fi
91
92 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 +030093 eval ${cmd}
94 check_return_code $cmd
Mike Elliottd17accd2017-08-14 16:21:40 -040095}
96
Mandeep Khindad6ea9872017-06-24 11:49:37 -040097#MAINs
98NS=
tzvika avni67a81112017-09-07 19:43:57 +030099HELM_VALUES_FILEPATH=""
100LOCATION="../"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400101INCL_SVC=true
102APP=
Munir Ahmad87b01092017-08-09 14:51:11 -0400103INSTANCE=1
104MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300105DU=$ONAP_DOCKER_USER
106DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400107
BorislavG8bfc6cf2018-02-27 15:04:26 +0000108SINGLE_COMPONENT=false
109
tzvika avni67a81112017-09-07 19:43:57 +0300110while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400111 case $PARAM in
112 u)
113 usage
114 exit 1
115 ;;
116 n)
117 NS=${OPTARG}
118 ;;
tzvika avnie3cbfa32017-09-07 16:42:37 +0300119 v)
120 HELM_VALUES_FILEPATH=${OPTARG}
121 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -0400122 i)
123 INSTANCE=${OPTARG}
124 ;;
tzvika avni67a81112017-09-07 19:43:57 +0300125 l)
126 LOCATION=${OPTARG}
127 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400128 a)
BorislavG8bfc6cf2018-02-27 15:04:26 +0000129 SINGLE_COMPONENT=true
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400130 APP=${OPTARG}
131 if [[ -z $APP ]]; then
132 usage
133 exit 1
134 fi
135 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300136 du)
137 DU=${OPTARG}
138 ;;
139 dp)
140 DP=${OPTARG}
141 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400142 ?)
143 usage
144 exit
145 ;;
146 esac
147done
148
149if [[ -z $NS ]]; then
150 usage
151 exit 1
152fi
153
154if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +0000155 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400156fi
157
Munir Ahmad87b01092017-08-09 14:51:11 -0400158
kerenj80102842017-08-24 13:54:21 +0000159if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
160 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
161 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
162 exit 1
Munir Ahmad87b01092017-08-09 14:51:11 -0400163fi
164
kerenj80102842017-08-24 13:54:21 +0000165start=$((300+2*INSTANCE))
166end=$((start+1))
167
168printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
169
170
Mike Elliottd17accd2017-08-14 16:21:40 -0400171printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400172
BorislavG8bfc6cf2018-02-27 15:04:26 +0000173if [ "$SINGLE_COMPONENT" == "false" ]
174then
175 printf "\nCreating namespace **********\n"
176 create_namespace $NS
177
178 printf "\nCreating registry secret **********\n"
179 create_registry_key $NS ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
BorislavG042b6852018-03-04 15:03:52 +0000180
181 printf "\nCreating service account **********\n"
182 create_service_account $NS
BorislavG8bfc6cf2018-02-27 15:04:26 +0000183fi
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400184
kerenj80102842017-08-24 13:54:21 +0000185printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400186
kerenj74d723a2017-08-22 15:27:04 +0000187for i in ${HELM_APPS[@]}; do
kerenj74d723a2017-08-22 15:27:04 +0000188
kerenj74d723a2017-08-22 15:27:04 +0000189 printf "\nCreating deployments and services **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300190 create_onap_helm $NS $i $start
kerenj74d723a2017-08-22 15:27:04 +0000191
192 printf "\n"
193done
194
Munir Ahmad87b01092017-08-09 14:51:11 -0400195printf "\n**** Done ****\n"