8a27510e5c40aa657c5499eabfe5c7fdc958c24c
[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 -v [VALUES]         : HELM values filepath (usefull when deploying one component at a time)
12 -i [INSTANCE]       : ONAP deployment instance # (default: 1)
13 -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
17 EOF
18 }
19
20 create_namespace() {
21   kubectl create namespace $1-$2
22 }
23
24 create_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
28 create_onap_helm() {
29   HELM_VALUES_ADDITION=""
30   if [[ ! -z $4 ]]; then
31      HELM_VALUES_ADDITION="--values=$4"  
32   fi
33   helm install ../$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1 --set nodePortPrefix=$3 ${HELM_VALUES_ADDITION}
34 }
35
36
37 #MAINs
38 NS=
39 HELM_VALUES_FILEPATH=
40 INCL_SVC=true
41 APP=
42 INSTANCE=1
43 MAX_INSTANCE=5
44 DU=$ONAP_DOCKER_USER
45 DP=$ONAP_DOCKER_PASS
46
47 while getopts ":n:u:s:i:a:du:dp:v:" PARAM; do
48   case $PARAM in
49     u)
50       usage
51       exit 1
52       ;;
53     n)
54       NS=${OPTARG}
55       ;;
56     v)
57       HELM_VALUES_FILEPATH=${OPTARG}
58       ;;
59     i)
60       INSTANCE=${OPTARG}
61       ;;
62     a)
63       APP=${OPTARG}
64       if [[ -z $APP ]]; then
65         usage
66         exit 1
67       fi
68       ;;
69     du)
70       DU=${OPTARG}
71       ;;
72     dp)
73       DP=${OPTARG}
74       ;;
75     ?)
76       usage
77       exit
78       ;;
79   esac
80 done
81
82 if [[ -z $NS ]]; then
83   usage
84   exit 1
85 fi
86
87 if [[ ! -z "$APP" ]]; then
88   HELM_APPS=($APP)
89 fi
90
91
92 if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
93   printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
94   printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
95   exit 1
96 fi
97
98 start=$((300+2*INSTANCE))
99 end=$((start+1))
100
101 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
102
103
104 printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
105
106
107 printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
108
109 for i in ${HELM_APPS[@]}; do
110   printf "\nCreating namespace **********\n"
111   create_namespace $NS $i 
112
113   printf "\nCreating registry secret **********\n"
114   create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
115
116   printf "\nCreating deployments and services **********\n"
117   create_onap_helm $NS $i $start $HELM_VALUES_FILEPATH
118
119   printf "\n"
120 done
121
122 printf "\n**** Done ****\n"