blob: ded7c392ed1866e5c3efd9d1d12c99f48e359a94 [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
Frank A. Zdarsky8407a7a2018-03-20 11:07:13 +010086 cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
tzvika avni213d2ef2017-09-07 17:54:15 +030087 eval ${cmd}
88 check_return_code $cmd
Mike Elliottd17accd2017-08-14 16:21:40 -040089}
90
Mandeep Khindad6ea9872017-06-24 11:49:37 -040091#MAINs
92NS=
tzvika avni67a81112017-09-07 19:43:57 +030093HELM_VALUES_FILEPATH=""
94LOCATION="../"
Mandeep Khindad6ea9872017-06-24 11:49:37 -040095INCL_SVC=true
96APP=
Munir Ahmad87b01092017-08-09 14:51:11 -040097INSTANCE=1
98MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +030099DU=$ONAP_DOCKER_USER
100DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400101
BorislavG8bfc6cf2018-02-27 15:04:26 +0000102SINGLE_COMPONENT=false
103
tzvika avni67a81112017-09-07 19:43:57 +0300104while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400105 case $PARAM in
106 u)
107 usage
108 exit 1
109 ;;
110 n)
111 NS=${OPTARG}
112 ;;
tzvika avnie3cbfa32017-09-07 16:42:37 +0300113 v)
114 HELM_VALUES_FILEPATH=${OPTARG}
115 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -0400116 i)
117 INSTANCE=${OPTARG}
118 ;;
tzvika avni67a81112017-09-07 19:43:57 +0300119 l)
120 LOCATION=${OPTARG}
121 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400122 a)
BorislavG8bfc6cf2018-02-27 15:04:26 +0000123 SINGLE_COMPONENT=true
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400124 APP=${OPTARG}
125 if [[ -z $APP ]]; then
126 usage
127 exit 1
128 fi
129 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300130 du)
131 DU=${OPTARG}
132 ;;
133 dp)
134 DP=${OPTARG}
135 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400136 ?)
137 usage
138 exit
139 ;;
140 esac
141done
142
143if [[ -z $NS ]]; then
144 usage
145 exit 1
146fi
147
148if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +0000149 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400150fi
151
Munir Ahmad87b01092017-08-09 14:51:11 -0400152
kerenj80102842017-08-24 13:54:21 +0000153if [ "$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
Munir Ahmad87b01092017-08-09 14:51:11 -0400157fi
158
kerenj80102842017-08-24 13:54:21 +0000159start=$((300+2*INSTANCE))
160end=$((start+1))
161
162printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
163
164
Mike Elliottd17accd2017-08-14 16:21:40 -0400165printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400166
BorislavG8bfc6cf2018-02-27 15:04:26 +0000167if [ "$SINGLE_COMPONENT" == "false" ]
168then
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
BorislavG042b6852018-03-04 15:03:52 +0000174
175 printf "\nCreating service account **********\n"
176 create_service_account $NS
BorislavG8bfc6cf2018-02-27 15:04:26 +0000177fi
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400178
kerenj80102842017-08-24 13:54:21 +0000179printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400180
kerenj74d723a2017-08-22 15:27:04 +0000181for i in ${HELM_APPS[@]}; do
kerenj74d723a2017-08-22 15:27:04 +0000182
kerenj74d723a2017-08-22 15:27:04 +0000183 printf "\nCreating deployments and services **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300184 create_onap_helm $NS $i $start
kerenj74d723a2017-08-22 15:27:04 +0000185
186 printf "\n"
187done
188
Munir Ahmad87b01092017-08-09 14:51:11 -0400189printf "\n**** Done ****\n"