blob: 829f27a4dfef7736a21a88529db4d56d1479a706 [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)
Munir Ahmad87b01092017-08-09 14:51:11 -040011-i [INSTANCE] : ONAP deployment instance # (default: 1)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040012-a [APP] : Specify a specific ONAP component (default: all)
13 from the following choices:
14 sdc, aai ,mso, message-router, robot,
15 vid, sdnc, portal, policy, appc
16EOF
17}
18
19create_namespace() {
20 kubectl create namespace $1-$2
21}
22
Borislav Glozman5197e2e2017-07-24 10:45:28 +030023create_registry_key() {
24 kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7
25}
26
kerenj74d723a2017-08-22 15:27:04 +000027create_onap_helm() {
Mandeep Khinda0e8f8892017-08-25 03:31:17 +000028 helm install ../$2/ --name $2 --namespace $1 --set nsPrefix=$1
kerenj74d723a2017-08-22 15:27:04 +000029}
30
Mike Elliottd17accd2017-08-14 16:21:40 -040031configure_app() {
32 # if previous configuration exists put back original template file
kerenj74d723a2017-08-22 15:27:04 +000033 for file in $3/*.yaml; do
Mike Elliottd17accd2017-08-14 16:21:40 -040034 if [ -e "$file-template" ]; then
35 mv "$file-template" "${file%}"
36 fi
37 done
kerenj74d723a2017-08-22 15:27:04 +000038
39 if [ -e "$2/Chart.yaml" ]; then
Munir Ahmad0803ca62017-08-23 16:55:59 -040040 sed -i-- 's/nodePort: [0-9]\{2\}[02468]\{1\}/nodePort: '"$4"'/g' $3/all-services.yaml
41 sed -i-- 's/nodePort: [0-9]\{2\}[13579]\{1\}/nodePort: '"$5"'/g' $3/all-services.yaml
kerenj74d723a2017-08-22 15:27:04 +000042 fi
Mike Elliottd17accd2017-08-14 16:21:40 -040043}
44
45
Mandeep Khindad6ea9872017-06-24 11:49:37 -040046#MAINs
47NS=
48INCL_SVC=true
49APP=
Munir Ahmad87b01092017-08-09 14:51:11 -040050INSTANCE=1
51MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +030052DU=$ONAP_DOCKER_USER
53DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -040054
Munir Ahmad87b01092017-08-09 14:51:11 -040055while getopts ":n:u:s:i:a:du:dp:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -040056 case $PARAM in
57 u)
58 usage
59 exit 1
60 ;;
61 n)
62 NS=${OPTARG}
63 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -040064 i)
65 INSTANCE=${OPTARG}
66 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040067 a)
68 APP=${OPTARG}
69 if [[ -z $APP ]]; then
70 usage
71 exit 1
72 fi
73 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +030074 du)
75 DU=${OPTARG}
76 ;;
77 dp)
78 DP=${OPTARG}
79 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040080 ?)
81 usage
82 exit
83 ;;
84 esac
85done
86
87if [[ -z $NS ]]; then
88 usage
89 exit 1
90fi
91
92if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +000093 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040094fi
95
Munir Ahmad87b01092017-08-09 14:51:11 -040096
kerenj80102842017-08-24 13:54:21 +000097if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
98 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
99 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
100 exit 1
Munir Ahmad87b01092017-08-09 14:51:11 -0400101fi
102
kerenj80102842017-08-24 13:54:21 +0000103start=$((300+2*INSTANCE))
104end=$((start+1))
105
106printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
107
108
Mike Elliottd17accd2017-08-14 16:21:40 -0400109printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400110
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400111
kerenj80102842017-08-24 13:54:21 +0000112printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400113
kerenj74d723a2017-08-22 15:27:04 +0000114for i in ${HELM_APPS[@]}; do
115 printf "\nCreating namespace **********\n"
116 create_namespace $NS $i
117
118 printf "\nCreating registry secret **********\n"
Mandeep Khinda0e8f8892017-08-25 03:31:17 +0000119 create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
kerenj74d723a2017-08-22 15:27:04 +0000120
121 printf "\nCreating deployments and services **********\n"
122 _FILES_PATH=$(echo ../$i/templates)
123 configure_app $NS $i $_FILES_PATH $start $end
124 create_onap_helm $NS $i
125
126 printf "\n"
127done
128
Munir Ahmad87b01092017-08-09 14:51:11 -0400129printf "\n**** Done ****\n"