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