moving certs and keys to k8s secrets
[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 -l [LOCATION]       : Location of oom project
13 -i [INSTANCE]       : ONAP deployment instance # (default: 1)
14 -a [APP]            : Specify a specific ONAP component (default: all)
15                       from the following choices:
16                       sdc, aai ,mso, message-router, robot,
17                       vid, sdnc, portal, policy, appc
18 EOF
19 }
20
21 create_namespace() {
22   kubectl create namespace $1-$2
23 }
24
25 create_registry_key() {
26   kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7
27 }
28
29 create_certs_secret() {
30   if [ -d $LOCATION/config/certs/$i/ ]; then
31     printf "\nCreating certs and keys secret **********\n"
32     _CERTS_FILES=$(find $LOCATION/config/certs/$2/ -type f | awk '$0="--from-file="$0' ORS=' ')
33     kubectl create secret generic secret-$1-$2 $_CERTS_FILES -n $1-$2
34   fi
35 }
36
37 create_onap_helm() {
38   HELM_VALUES_ADDITION=""
39   if [[ ! -z $HELM_VALUES_FILEPATH ]]; then
40     HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH"
41   fi
42   helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}
43 }
44
45
46 #MAINs
47 NS=
48 HELM_VALUES_FILEPATH=""
49 LOCATION="../"
50 INCL_SVC=true
51 APP=
52 INSTANCE=1
53 MAX_INSTANCE=5
54 DU=$ONAP_DOCKER_USER
55 DP=$ONAP_DOCKER_PASS
56
57 while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do
58   case $PARAM in
59     u)
60       usage
61       exit 1
62       ;;
63     n)
64       NS=${OPTARG}
65       ;;
66     v)
67       HELM_VALUES_FILEPATH=${OPTARG}
68       ;;
69     i)
70       INSTANCE=${OPTARG}
71       ;;
72     l)
73       LOCATION=${OPTARG}
74       ;;
75     a)
76       APP=${OPTARG}
77       if [[ -z $APP ]]; then
78         usage
79         exit 1
80       fi
81       ;;
82     du)
83       DU=${OPTARG}
84       ;;
85     dp)
86       DP=${OPTARG}
87       ;;
88     ?)
89       usage
90       exit
91       ;;
92   esac
93 done
94
95 if [[ -z $NS ]]; then
96   usage
97   exit 1
98 fi
99
100 if [[ ! -z "$APP" ]]; then
101   HELM_APPS=($APP)
102 fi
103
104
105 if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then
106   printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n"
107   printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n"
108   exit 1
109 fi
110
111 start=$((300+2*INSTANCE))
112 end=$((start+1))
113
114 printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n"
115
116
117 printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n"
118
119
120 printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n"
121
122 for i in ${HELM_APPS[@]}; do
123   printf "\nCreating namespace **********\n"
124   create_namespace $NS $i
125
126   printf "\nCreating registry secret **********\n"
127   create_registry_key $NS $i ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL
128
129   create_certs_secret $NS $i
130
131   printf "\nCreating deployments and services **********\n"
132   create_onap_helm $NS $i $start
133
134   printf "\n"
135 done
136
137 printf "\n**** Done ****\n"