829f27a4dfef7736a21a88529db4d56d1479a706
[oom.git] / kubernetes / oneclick / createAll.bash
1 #!/bin/bash
2
3 . $(dirname "$0")/setenv.bash
4
5
6 usage() {
7   cat <<EOF
8 Usage: $0 [PARAMs]
9 -u                  : Display usage
10 -n [NAMESPACE]      : Kubernetes namespace (required)
11 -i [INSTANCE]       : ONAP deployment instance # (default: 1)
12 -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
16 EOF
17 }
18
19 create_namespace() {
20   kubectl create namespace $1-$2
21 }
22
23 create_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
27 create_onap_helm() {
28   helm install ../$2/ --name $2 --namespace $1 --set nsPrefix=$1
29 }
30
31 configure_app() {
32   # if previous configuration exists put back original template file
33   for file in $3/*.yaml; do
34     if [ -e "$file-template" ]; then
35       mv "$file-template" "${file%}"
36     fi
37   done
38   
39   if [ -e "$2/Chart.yaml" ]; then
40     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
42   fi
43 }
44
45
46 #MAINs
47 NS=
48 INCL_SVC=true
49 APP=
50 INSTANCE=1
51 MAX_INSTANCE=5
52 DU=$ONAP_DOCKER_USER
53 DP=$ONAP_DOCKER_PASS
54
55 while getopts ":n:u:s:i:a:du:dp:" PARAM; do
56   case $PARAM in
57     u)
58       usage
59       exit 1
60       ;;
61     n)
62       NS=${OPTARG}
63       ;;
64     i)
65       INSTANCE=${OPTARG}
66       ;;
67     a)
68       APP=${OPTARG}
69       if [[ -z $APP ]]; then
70         usage
71         exit 1
72       fi
73       ;;
74     du)
75       DU=${OPTARG}
76       ;;
77     dp)
78       DP=${OPTARG}
79       ;;
80     ?)
81       usage
82       exit
83       ;;
84   esac
85 done
86
87 if [[ -z $NS ]]; then
88   usage
89   exit 1
90 fi
91
92 if [[ ! -z "$APP" ]]; then
93   HELM_APPS=($APP)
94 fi
95
96
97 if [ "$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
101 fi
102
103 start=$((300+2*INSTANCE))
104 end=$((start+1))
105
106 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
107
108
109 printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
110
111
112 printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
113
114 for i in ${HELM_APPS[@]}; do
115   printf "\nCreating namespace **********\n"
116   create_namespace $NS $i 
117
118   printf "\nCreating registry secret **********\n"
119   create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
120
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"
127 done
128
129 printf "\n**** Done ****\n"