blob: 72d852ded61ef38054076037ae27b775ba419db7 [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
tzvika avni213d2ef2017-09-07 17:54:15 +030087 cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
88 eval ${cmd}
89 check_return_code $cmd
Mike Elliottd17accd2017-08-14 16:21:40 -040090}
91
Mandeep Khindad6ea9872017-06-24 11:49:37 -040092#MAINs
93NS=
tzvika avni67a81112017-09-07 19:43:57 +030094HELM_VALUES_FILEPATH=""
95LOCATION="../"
Mandeep Khindad6ea9872017-06-24 11:49:37 -040096INCL_SVC=true
97APP=
Munir Ahmad87b01092017-08-09 14:51:11 -040098INSTANCE=1
99MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300100DU=$ONAP_DOCKER_USER
101DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400102
tzvika avni67a81112017-09-07 19:43:57 +0300103while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400104 case $PARAM in
105 u)
106 usage
107 exit 1
108 ;;
109 n)
110 NS=${OPTARG}
111 ;;
tzvika avnie3cbfa32017-09-07 16:42:37 +0300112 v)
113 HELM_VALUES_FILEPATH=${OPTARG}
114 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -0400115 i)
116 INSTANCE=${OPTARG}
117 ;;
tzvika avni67a81112017-09-07 19:43:57 +0300118 l)
119 LOCATION=${OPTARG}
120 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400121 a)
122 APP=${OPTARG}
123 if [[ -z $APP ]]; then
124 usage
125 exit 1
126 fi
127 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300128 du)
129 DU=${OPTARG}
130 ;;
131 dp)
132 DP=${OPTARG}
133 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400134 ?)
135 usage
136 exit
137 ;;
138 esac
139done
140
141if [[ -z $NS ]]; then
142 usage
143 exit 1
144fi
145
146if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +0000147 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400148fi
149
Munir Ahmad87b01092017-08-09 14:51:11 -0400150
kerenj80102842017-08-24 13:54:21 +0000151if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
152 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
153 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
154 exit 1
Munir Ahmad87b01092017-08-09 14:51:11 -0400155fi
156
kerenj80102842017-08-24 13:54:21 +0000157start=$((300+2*INSTANCE))
158end=$((start+1))
159
160printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
161
162
Mike Elliottd17accd2017-08-14 16:21:40 -0400163printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400164
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400165
kerenj80102842017-08-24 13:54:21 +0000166printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400167
kerenj74d723a2017-08-22 15:27:04 +0000168for i in ${HELM_APPS[@]}; do
169 printf "\nCreating namespace **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300170 create_namespace $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000171
Anaël Closson40cdf492017-10-09 14:52:24 +0200172 printf "\nCreating service account **********\n"
173 create_service_account $NS $i
174
kerenj74d723a2017-08-22 15:27:04 +0000175 printf "\nCreating registry secret **********\n"
Mandeep Khinda0e8f8892017-08-25 03:31:17 +0000176 create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
kerenj74d723a2017-08-22 15:27:04 +0000177
178 printf "\nCreating deployments and services **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300179 create_onap_helm $NS $i $start
kerenj74d723a2017-08-22 15:27:04 +0000180
181 printf "\n"
182done
183
Munir Ahmad87b01092017-08-09 14:51:11 -0400184printf "\n**** Done ****\n"