blob: 7e2969760a90fe978d4d1bcd8aa9981f0dab54c0 [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)
11-s false : Exclude services (default: true)
Munir Ahmad87b01092017-08-09 14:51:11 -040012-i [INSTANCE] : ONAP deployment instance # (default: 1)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040013-a [APP] : Specify a specific ONAP component (default: all)
14 from the following choices:
15 sdc, aai ,mso, message-router, robot,
16 vid, sdnc, portal, policy, appc
17EOF
18}
19
20create_namespace() {
21 kubectl create namespace $1-$2
22}
23
Borislav Glozman5197e2e2017-07-24 10:45:28 +030024create_registry_key() {
25 kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7
26}
27
Mandeep Khindad6ea9872017-06-24 11:49:37 -040028create_service() {
Munir Ahmad0803ca62017-08-23 16:55:59 -040029 sed -i-- 's/nodePort: [0-9]\{2\}[02468]\{1\}/nodePort: '"$3"'/g' ../$2/all-services.yaml
30 sed -i-- 's/nodePort: [0-9]\{2\}[13579]\{1\}/nodePort: '"$4"'/g' ../$2/all-services.yaml
Mandeep Khindad6ea9872017-06-24 11:49:37 -040031 kubectl --namespace $1-$2 create -f ../$2/all-services.yaml
Munir Ahmad87b01092017-08-09 14:51:11 -040032 mv ../$2/all-services.yaml-- ../$2/all-services.yaml
Mandeep Khindad6ea9872017-06-24 11:49:37 -040033}
34
kerenj74d723a2017-08-22 15:27:04 +000035
36create_onap_helm() {
37 helm install ../$2/ --name $2
38}
39
Mike Elliottd17accd2017-08-14 16:21:40 -040040configure_app() {
41 # if previous configuration exists put back original template file
kerenj74d723a2017-08-22 15:27:04 +000042 for file in $3/*.yaml; do
Mike Elliottd17accd2017-08-14 16:21:40 -040043 if [ -e "$file-template" ]; then
44 mv "$file-template" "${file%}"
45 fi
46 done
kerenj74d723a2017-08-22 15:27:04 +000047
48 if [ -e "$2/Chart.yaml" ]; then
Munir Ahmad0803ca62017-08-23 16:55:59 -040049 sed -i-- 's/nodePort: [0-9]\{2\}[02468]\{1\}/nodePort: '"$4"'/g' $3/all-services.yaml
50 sed -i-- 's/nodePort: [0-9]\{2\}[13579]\{1\}/nodePort: '"$5"'/g' $3/all-services.yaml
kerenj74d723a2017-08-22 15:27:04 +000051 sed -i "s/onap-/$1-/g" ../$2/values.yaml
52 fi
53
Mike Elliottd17accd2017-08-14 16:21:40 -040054
55 # replace the default 'onap' namespace qualification of K8s hostnames within
56 # the config files
57 # note: this will create a '-template' file within the component's directory
58 # this is not ideal and should be addressed (along with the replacement
59 # of sed commands for configuration) by the future configuration
60 # user stories (ie. OOM-51 to OOM-53)
kerenj74d723a2017-08-22 15:27:04 +000061 find $3 -type f -exec sed -i -- "s/onap-/$1-/g" {} \;
Mike Elliottd17accd2017-08-14 16:21:40 -040062
Munir Ahmad76610be2017-08-17 11:56:15 -040063 # replace the default '/dockerdata-nfs/onapdemo' volume mount paths
kerenj74d723a2017-08-22 15:27:04 +000064 find $3 -iname "*.yaml" -type f -exec sed -i -e 's/dockerdata-nfs\/[a-zA-Z0-9\\-]*\//dockerdata-nfs\/'"$1"'\//g' {} \;
65 rm -f $3/*.yaml-e
Mike Elliottd17accd2017-08-14 16:21:40 -040066}
67
68
Mandeep Khindad6ea9872017-06-24 11:49:37 -040069#MAINs
70NS=
71INCL_SVC=true
72APP=
Munir Ahmad87b01092017-08-09 14:51:11 -040073INSTANCE=1
74MAX_INSTANCE=5
Borislav Glozman5197e2e2017-07-24 10:45:28 +030075DU=$ONAP_DOCKER_USER
76DP=$ONAP_DOCKER_PASS
Mandeep Khindad6ea9872017-06-24 11:49:37 -040077
Munir Ahmad87b01092017-08-09 14:51:11 -040078while getopts ":n:u:s:i:a:du:dp:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -040079 case $PARAM in
80 u)
81 usage
82 exit 1
83 ;;
84 n)
85 NS=${OPTARG}
86 ;;
87 s)
88 INCL_SVC=${OPTARG}
89 ;;
Munir Ahmad87b01092017-08-09 14:51:11 -040090 i)
91 INSTANCE=${OPTARG}
92 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040093 a)
94 APP=${OPTARG}
95 if [[ -z $APP ]]; then
96 usage
97 exit 1
98 fi
99 ;;
Borislav Glozman5197e2e2017-07-24 10:45:28 +0300100 du)
101 DU=${OPTARG}
102 ;;
103 dp)
104 DP=${OPTARG}
105 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400106 ?)
107 usage
108 exit
109 ;;
110 esac
111done
112
113if [[ -z $NS ]]; then
114 usage
115 exit 1
116fi
117
118if [[ ! -z "$APP" ]]; then
119 ONAP_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400120fi
121
Munir Ahmad87b01092017-08-09 14:51:11 -0400122if [[ "$INCL_SVC" == true ]]; then
123
124 if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
125 printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
126 printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
127 exit 1
128 fi
129
130 start=$((300+2*INSTANCE))
131 end=$((start+1))
132 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
133
134fi
135
Mike Elliottd17accd2017-08-14 16:21:40 -0400136printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400137
138for i in ${ONAP_APPS[@]}; do
Mike Elliottd17accd2017-08-14 16:21:40 -0400139 printf "\nCreating namespace **********\n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400140 create_namespace $NS $i
141
Mike Elliottd17accd2017-08-14 16:21:40 -0400142 printf "\nCreating registry secret **********\n"
143 create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
144
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400145 if [[ "$INCL_SVC" == true ]]; then
Mike Elliottd17accd2017-08-14 16:21:40 -0400146 printf "\nCreating service **********\n"
Munir Ahmad87b01092017-08-09 14:51:11 -0400147 create_service $NS $i $start $end
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400148 fi
149
150 printf "\n"
151done
152
Mike Elliottd17accd2017-08-14 16:21:40 -0400153printf "\n\n********** Creating deployments for ${ONAP_APPS[*]} ********** \n"
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400154for i in ${ONAP_APPS[@]}; do
kerenj74d723a2017-08-22 15:27:04 +0000155 _FILES_PATH=$(echo ../$i)
156 configure_app $NS $i $_FILES_PATH $start $end
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400157 /bin/bash $i.sh $NS $i 'create'
158done
159
kerenj74d723a2017-08-22 15:27:04 +0000160for i in ${HELM_APPS[@]}; do
161 printf "\nCreating namespace **********\n"
162 create_namespace $NS $i
163
164 printf "\nCreating registry secret **********\n"
165 create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
166
167 printf "\nCreating deployments and services **********\n"
168 _FILES_PATH=$(echo ../$i/templates)
169 configure_app $NS $i $_FILES_PATH $start $end
170 create_onap_helm $NS $i
171
172 printf "\n"
173done
174
Munir Ahmad87b01092017-08-09 14:51:11 -0400175printf "\n**** Done ****\n"
kerenj74d723a2017-08-22 15:27:04 +0000176