blob: 5e5f2dc76ea7739452e757282e750638b4e3e1de [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
Mandeep Khindad6ea9872017-06-24 11:49:37 -04005usage() {
6 cat <<EOF
7Usage: $0 [PARAMs]
8-u : Display usage
9-n [NAMESPACE] : Kubernetes namespace (required)
10-s false : Exclude services (default: true)
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
Mandeep Khindad6ea9872017-06-24 11:49:37 -040027create_service() {
Munir Ahmad87b01092017-08-09 14:51:11 -040028 sed -i -- 's/nodePort: [0-9]\{2\}[02468]\{1\}/nodePort: '"$3"'/g' ../$2/all-services.yaml
29 sed -i -- 's/nodePort: [0-9]\{2\}[13579]\{1\}/nodePort: '"$4"'/g' ../$2/all-services.yaml
Mandeep Khindad6ea9872017-06-24 11:49:37 -040030 kubectl --namespace $1-$2 create -f ../$2/all-services.yaml
Munir Ahmad87b01092017-08-09 14:51:11 -040031 mv ../$2/all-services.yaml-- ../$2/all-services.yaml
Mandeep Khindad6ea9872017-06-24 11:49:37 -040032}
33
Mike Elliottd17accd2017-08-14 16:21:40 -040034configure_app() {
35 # if previous configuration exists put back original template file
36 for file in ../$2/*.yaml; do
37 if [ -e "$file-template" ]; then
38 mv "$file-template" "${file%}"
39 fi
40 done
41
42 # replace the default 'onap' namespace qualification of K8s hostnames within
43 # the config files
44 # note: this will create a '-template' file within the component's directory
45 # this is not ideal and should be addressed (along with the replacement
46 # of sed commands for configuration) by the future configuration
47 # user stories (ie. OOM-51 to OOM-53)
48 find ../$2 -type f -exec sed -i -template "s/onap-/$1-/g" {} \;
49
Munir Ahmad76610be2017-08-17 11:56:15 -040050 # replace the default '/dockerdata-nfs/onapdemo' volume mount paths
51 find ../$2 -iname "*.yaml" -type f -exec sed -i -e 's/dockerdata-nfs\/[a-zA-Z0-9\\-]*\//dockerdata-nfs\/'"$1"'\//g' {} \;
Mike Elliottd17accd2017-08-14 16:21:40 -040052 rm -f ../$2/*.yaml-e
53}
54
55
Mandeep Khindad6ea9872017-06-24 11:49:37 -040056#MAINs
57NS=
58INCL_SVC=true
59APP=
Munir Ahmad87b01092017-08-09 14:51:11 -040060INSTANCE=1
61MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +030062DU=$ONAP_DOCKER_USER
63DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -040064
Munir Ahmad87b01092017-08-09 14:51:11 -040065while getopts ":n:u:s:i:a:du:dp:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -040066 case $PARAM in
67 u)
68 usage
69 exit 1
70 ;;
71 n)
72 NS=${OPTARG}
73 ;;
74 s)
75 INCL_SVC=${OPTARG}
76 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -040077 i)
78 INSTANCE=${OPTARG}
79 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040080 a)
81 APP=${OPTARG}
82 if [[ -z $APP ]]; then
83 usage
84 exit 1
85 fi
86 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +030087 du)
88 DU=${OPTARG}
89 ;;
90 dp)
91 DP=${OPTARG}
92 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040093 ?)
94 usage
95 exit
96 ;;
97 esac
98done
99
100if [[ -z $NS ]]; then
101 usage
102 exit 1
103fi
104
105if [[ ! -z "$APP" ]]; then
106 ONAP_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400107fi
108
Munir Ahmad87b01092017-08-09 14:51:11 -0400109if [[ "$INCL_SVC" == true ]]; then
110
111 if [ "$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
115 fi
116
117 start=$((300+2*INSTANCE))
118 end=$((start+1))
119 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
120
121fi
122
Mike Elliottd17accd2017-08-14 16:21:40 -0400123printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400124
125for i in ${ONAP_APPS[@]}; do
Mike Elliottd17accd2017-08-14 16:21:40 -0400126 printf "\nCreating namespace **********\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400127 create_namespace $NS $i
128
Mike Elliottd17accd2017-08-14 16:21:40 -0400129 printf "\nCreating registry secret **********\n"
130 create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
131
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400132 if [[ "$INCL_SVC" == true ]]; then
Mike Elliottd17accd2017-08-14 16:21:40 -0400133 printf "\nCreating service **********\n"
Munir Ahmad87b01092017-08-09 14:51:11 -0400134 create_service $NS $i $start $end
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400135 fi
136
137 printf "\n"
138done
139
Mike Elliottd17accd2017-08-14 16:21:40 -0400140printf "\n\n********** Creating deployments for ${ONAP_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400141for i in ${ONAP_APPS[@]}; do
Mike Elliottd17accd2017-08-14 16:21:40 -0400142 configure_app $NS $i
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400143 /bin/bash $i.sh $NS $i 'create'
144done
145
Munir Ahmad87b01092017-08-09 14:51:11 -0400146printf "\n**** Done ****\n"