Merge "sdc K8S-Helm Parameterization"
[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
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     sed -i "s/onap-/$1-/g" ../$2/values.yaml
43   fi
44
45
46   # replace the default 'onap' namespace qualification of K8s hostnames within
47   # the config files
48   # note: this will create a '-template' file within the component's directory
49   #       this is not ideal and should be addressed (along with the replacement
50   #       of sed commands for configuration) by the future configuration
51   #       user stories (ie. OOM-51 to OOM-53)
52   find $3 -type f -exec sed -i -- "s/onap-/$1-/g" {} \;
53
54   # replace the default '/dockerdata-nfs/onapdemo' volume mount paths
55   find $3 -iname "*.yaml" -type f -exec sed -i -e 's/dockerdata-nfs\/[a-zA-Z0-9\\-]*\//dockerdata-nfs\/'"$1"'\//g' {} \;
56   rm -f $3/*.yaml-e
57 }
58
59
60 #MAINs
61 NS=
62 INCL_SVC=true
63 APP=
64 INSTANCE=1
65 MAX_INSTANCE=5
66 DU=$ONAP_DOCKER_USER
67 DP=$ONAP_DOCKER_PASS
68
69 while getopts ":n:u:s:i:a:du:dp:" PARAM; do
70   case $PARAM in
71     u)
72       usage
73       exit 1
74       ;;
75     n)
76       NS=${OPTARG}
77       ;;
78     i)
79       INSTANCE=${OPTARG}
80       ;;
81     a)
82       APP=${OPTARG}
83       if [[ -z $APP ]]; then
84         usage
85         exit 1
86       fi
87       ;;
88     du)
89       DU=${OPTARG}
90       ;;
91     dp)
92       DP=${OPTARG}
93       ;;
94     ?)
95       usage
96       exit
97       ;;
98   esac
99 done
100
101 if [[ -z $NS ]]; then
102   usage
103   exit 1
104 fi
105
106 if [[ ! -z "$APP" ]]; then
107   HELM_APPS=($APP)
108 fi
109
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
120 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
121
122
123 printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
124
125
126 printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
127
128 for i in ${HELM_APPS[@]}; do
129   printf "\nCreating namespace **********\n"
130   create_namespace $NS $i 
131
132   printf "\nCreating registry secret **********\n"
133   create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
134
135   printf "\nCreating deployments and services **********\n"
136   _FILES_PATH=$(echo ../$i/templates)
137   configure_app $NS $i $_FILES_PATH $start $end
138   create_onap_helm $NS $i
139
140   printf "\n"
141 done
142
143 printf "\n**** Done ****\n"
144