blob: 8d41ee45a6650a231c49d0751b64d364f0dca7c0 [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 Rozman7704d2a2017-09-26 16:04:12 -040016 sdc, aai ,mso, message-router, robot, vid, aaf
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
29
Mandeep Khindad6ea9872017-06-24 11:49:37 -040030create_namespace() {
tzvika avni213d2ef2017-09-07 17:54:15 +030031 cmd=`echo kubectl create namespace $1-$2`
32 eval ${cmd}
33 check_return_code $cmd
Mandeep Khindad6ea9872017-06-24 11:49:37 -040034}
35
Borislav Glozman5197e2e2017-07-24 10:45:28 +030036create_registry_key() {
tzvika avni213d2ef2017-09-07 17:54:15 +030037 cmd=`echo kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7`
38 eval ${cmd}
39 check_return_code $cmd
Borislav Glozman5197e2e2017-07-24 10:45:28 +030040}
41
Mandeep Khindade8d47e2017-09-21 18:22:10 +000042configure_dcaegen2() {
43 if [ ! -s "$OPENSTACK_PRIVATE_KEY_PATH" ]
44 then
45 echo "ERROR: $OPENSTACK_PRIVATE_KEY_PATH does not exist or is empty. Cannot launch dcae gen2."
46 return 1
47 fi
48
49 cmd=`echo kubectl --namespace $1-$2 create secret generic $2-openstack-ssh-private-key --from-file=key=${OPENSTACK_PRIVATE_KEY_PATH}`
50 eval ${cmd}
51 check_return_code $cmd
52
53 if [ ! -s "$DCAEGEN2_CONFIG_INPUT_FILE_PATH" ]
54 then
55 echo "ERROR: $DCAEGEN2_CONFIG_INPUT_FILE_PATH does not exist or is empty. Cannot launch dcae gen2."
56 return 1
57 fi
58
59 cmd=`echo kubectl --namespace $1-$2 create configmap $2-config-inputs --from-file=inputs.yaml=${DCAEGEN2_CONFIG_INPUT_FILE_PATH}`
60 eval ${cmd}
61 check_return_code $cmd
62}
63
kerenj74d723a2017-08-22 15:27:04 +000064create_onap_helm() {
tzvika avnie3cbfa32017-09-07 16:42:37 +030065 HELM_VALUES_ADDITION=""
tzvika avni67a81112017-09-07 19:43:57 +030066 if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
67 HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
tzvika avnie3cbfa32017-09-07 16:42:37 +030068 fi
Mandeep Khindade8d47e2017-09-21 18:22:10 +000069 # Have to put a check for dcaegen2 because it requires external files to helm
70 # which should not be part of the Chart.
71 if [ "$2" = "dcaegen2" ];
72 then
73 configure_dcaegen2 $1 $2
74 local result=$?
75 if [ $result -ne 0 ]
76 then
77 echo "ERROR: dcaegen2 failed to configure: Pre-requisites not met. Skipping deploying it and continue"
78 return
79 fi
80 fi
81
tzvika avni213d2ef2017-09-07 17:54:15 +030082 cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
83 eval ${cmd}
84 check_return_code $cmd
Mike Elliottd17accd2017-08-14 16:21:40 -040085}
86
Mandeep Khindad6ea9872017-06-24 11:49:37 -040087#MAINs
88NS=
tzvika avni67a81112017-09-07 19:43:57 +030089HELM_VALUES_FILEPATH=""
90LOCATION="../"
Mandeep Khindad6ea9872017-06-24 11:49:37 -040091INCL_SVC=true
92APP=
Munir Ahmad87b01092017-08-09 14:51:11 -040093INSTANCE=1
94MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +030095DU=$ONAP_DOCKER_USER
96DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -040097
tzvika avni67a81112017-09-07 19:43:57 +030098while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -040099 case $PARAM in
100 u)
101 usage
102 exit 1
103 ;;
104 n)
105 NS=${OPTARG}
106 ;;
tzvika avnie3cbfa32017-09-07 16:42:37 +0300107 v)
108 HELM_VALUES_FILEPATH=${OPTARG}
109 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -0400110 i)
111 INSTANCE=${OPTARG}
112 ;;
tzvika avni67a81112017-09-07 19:43:57 +0300113 l)
114 LOCATION=${OPTARG}
115 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400116 a)
117 APP=${OPTARG}
118 if [[ -z $APP ]]; then
119 usage
120 exit 1
121 fi
122 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300123 du)
124 DU=${OPTARG}
125 ;;
126 dp)
127 DP=${OPTARG}
128 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400129 ?)
130 usage
131 exit
132 ;;
133 esac
134done
135
136if [[ -z $NS ]]; then
137 usage
138 exit 1
139fi
140
141if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +0000142 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400143fi
144
Munir Ahmad87b01092017-08-09 14:51:11 -0400145
kerenj80102842017-08-24 13:54:21 +0000146if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
147 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
148 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
149 exit 1
Munir Ahmad87b01092017-08-09 14:51:11 -0400150fi
151
kerenj80102842017-08-24 13:54:21 +0000152start=$((300+2*INSTANCE))
153end=$((start+1))
154
155printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
156
157
Mike Elliottd17accd2017-08-14 16:21:40 -0400158printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400159
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400160
kerenj80102842017-08-24 13:54:21 +0000161printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400162
kerenj74d723a2017-08-22 15:27:04 +0000163for i in ${HELM_APPS[@]}; do
164 printf "\nCreating namespace **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300165 create_namespace $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000166
167 printf "\nCreating registry secret **********\n"
Mandeep Khinda0e8f8892017-08-25 03:31:17 +0000168 create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
kerenj74d723a2017-08-22 15:27:04 +0000169
170 printf "\nCreating deployments and services **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300171 create_onap_helm $NS $i $start
kerenj74d723a2017-08-22 15:27:04 +0000172
173 printf "\n"
174done
175
Munir Ahmad87b01092017-08-09 14:51:11 -0400176printf "\n**** Done ****\n"