blob: 7be2e6a7de17fa29c104b2088bf715fbcd951f3f [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:
16 sdc, aai ,mso, message-router, robot,
17 vid, sdnc, portal, policy, appc
18EOF
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
kerenj74d723a2017-08-22 15:27:04 +000042create_onap_helm() {
tzvika avnie3cbfa32017-09-07 16:42:37 +030043 HELM_VALUES_ADDITION=""
tzvika avni67a81112017-09-07 19:43:57 +030044 if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
45 HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
tzvika avnie3cbfa32017-09-07 16:42:37 +030046 fi
tzvika avni213d2ef2017-09-07 17:54:15 +030047 cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
48 eval ${cmd}
49 check_return_code $cmd
Mike Elliottd17accd2017-08-14 16:21:40 -040050}
51
Mandeep Khindad6ea9872017-06-24 11:49:37 -040052#MAINs
53NS=
tzvika avni67a81112017-09-07 19:43:57 +030054HELM_VALUES_FILEPATH=""
55LOCATION="../"
Mandeep Khindad6ea9872017-06-24 11:49:37 -040056INCL_SVC=true
57APP=
Munir Ahmad87b01092017-08-09 14:51:11 -040058INSTANCE=1
59MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +030060DU=$ONAP_DOCKER_USER
61DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -040062
tzvika avni67a81112017-09-07 19:43:57 +030063while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -040064 case $PARAM in
65 u)
66 usage
67 exit 1
68 ;;
69 n)
70 NS=${OPTARG}
71 ;;
tzvika avnie3cbfa32017-09-07 16:42:37 +030072 v)
73 HELM_VALUES_FILEPATH=${OPTARG}
74 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -040075 i)
76 INSTANCE=${OPTARG}
77 ;;
tzvika avni67a81112017-09-07 19:43:57 +030078 l)
79 LOCATION=${OPTARG}
80 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040081 a)
82 APP=${OPTARG}
83 if [[ -z $APP ]]; then
84 usage
85 exit 1
86 fi
87 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +030088 du)
89 DU=${OPTARG}
90 ;;
91 dp)
92 DP=${OPTARG}
93 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040094 ?)
95 usage
96 exit
97 ;;
98 esac
99done
100
101if [[ -z $NS ]]; then
102 usage
103 exit 1
104fi
105
106if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +0000107 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400108fi
109
Munir Ahmad87b01092017-08-09 14:51:11 -0400110
kerenj80102842017-08-24 13:54:21 +0000111if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
112 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
113 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
114 exit 1
Munir Ahmad87b01092017-08-09 14:51:11 -0400115fi
116
kerenj80102842017-08-24 13:54:21 +0000117start=$((300+2*INSTANCE))
118end=$((start+1))
119
120printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
121
122
Mike Elliottd17accd2017-08-14 16:21:40 -0400123printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400124
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400125
kerenj80102842017-08-24 13:54:21 +0000126printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400127
kerenj74d723a2017-08-22 15:27:04 +0000128for i in ${HELM_APPS[@]}; do
129 printf "\nCreating namespace **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300130 create_namespace $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000131
132 printf "\nCreating registry secret **********\n"
Mandeep Khinda0e8f8892017-08-25 03:31:17 +0000133 create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
kerenj74d723a2017-08-22 15:27:04 +0000134
135 printf "\nCreating deployments and services **********\n"
tzvika avni67a81112017-09-07 19:43:57 +0300136 create_onap_helm $NS $i $start
kerenj74d723a2017-08-22 15:27:04 +0000137
138 printf "\n"
139done
140
Munir Ahmad87b01092017-08-09 14:51:11 -0400141printf "\n**** Done ****\n"