bc211eeb47d72587b7cea8ea109dc002ae951800
[oom.git] / kubernetes / oneclick / createAll.bash
1 #!/bin/bash
2
3 . $(dirname "$0")/setenv.bash
4
5 usage() {
6   cat <<EOF
7 Usage: $0 [PARAMs]
8 -u                  : Display usage
9 -n [NAMESPACE]      : Kubernetes namespace (required)
10 -s false            : Exclude services (default: true)
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_service() {
28   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
30   kubectl --namespace $1-$2 create -f ../$2/all-services.yaml
31   mv ../$2/all-services.yaml-- ../$2/all-services.yaml
32 }
33
34 #MAINs
35 NS=
36 INCL_SVC=true
37 APP=
38 INSTANCE=1
39 MAX_INSTANCE=5
40 DU=$ONAP_DOCKER_USER
41 DP=$ONAP_DOCKER_PASS
42
43 while getopts ":n:u:s:i:a:du:dp:" PARAM; do
44   case $PARAM in
45     u)
46       usage
47       exit 1
48       ;;
49     n)
50       NS=${OPTARG}
51       ;;
52     s)
53       INCL_SVC=${OPTARG}
54       ;;
55     i)
56       INSTANCE=${OPTARG}
57       ;;
58     a)
59       APP=${OPTARG}
60       if [[ -z $APP ]]; then
61         usage
62         exit 1
63       fi
64       ;;
65     du)
66       DU=${OPTARG}
67       ;;
68     dp)
69       DP=${OPTARG}
70       ;;
71     ?)
72       usage
73       exit
74       ;;
75   esac
76 done
77
78 if [[ -z $NS ]]; then
79   usage
80   exit 1
81 fi
82
83 if [[ ! -z "$APP" ]]; then
84   ONAP_APPS=($APP)
85 fi
86
87 if [[ "$INCL_SVC" == true ]]; then
88
89   if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
90     printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
91     printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
92     exit 1
93   fi
94
95   start=$((300+2*INSTANCE))
96   end=$((start+1))
97   printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
98
99 fi
100
101 printf "\n********** Creating up ONAP: ${ONAP_APPS[*]}\n"
102
103 for i in ${ONAP_APPS[@]}; do
104   printf "\nCreating namespaces **********\n"
105   create_namespace $NS $i
106
107   if [[ "$INCL_SVC" == true ]]; then
108     printf "\nCreating services **********\n"
109     create_service $NS $i $start $end
110   fi
111
112   printf "\n"
113 done
114
115 printf "\n\n********** Creating deployments for  ${ONAP_APPS[*]} ********** \n"
116 for i in ${ONAP_APPS[@]}; do
117   create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
118   /bin/bash $i.sh $NS $i 'create'
119 done
120
121 printf "\n**** Done ****\n"