Merge "NONRTRIC-980: Service Manager - SMO deployment"
[it/dep.git] / ric-aux / bin / install
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
4 #   Copyright (c) 2019 Nokia.                                                  #
5 #                                                                              #
6 #   Licensed under the Apache License, Version 2.0 (the "License");            #
7 #   you may not use this file except in compliance with the License.           #
8 #   You may obtain a copy of the License at                                    #
9 #                                                                              #
10 #       http://www.apache.org/licenses/LICENSE-2.0                             #
11 #                                                                              #
12 #   Unless required by applicable law or agreed to in writing, software        #
13 #   distributed under the License is distributed on an "AS IS" BASIS,          #
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15 #   See the License for the specific language governing permissions and        #
16 #   limitations under the License.                                             #
17 ################################################################################
18
19
20 while [ -n "$1" ]; do # while loop starts
21
22     case "$1" in
23
24     -f) OVERRIDEYAML=$2
25         shift
26         ;;
27     -c) LIST_OF_COMPONENTS=$2
28         shift
29         ;;
30     *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
31
32     esac
33
34     shift
35
36 done
37
38
39 if [ -z "$OVERRIDEYAML" ];then
40     echo "****************************************************************************************************************"
41     echo "                                                     ERROR                                                      "
42     echo "****************************************************************************************************************"
43     echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
44     echo "****************************************************************************************************************"
45     exit 1
46 fi
47
48 #Check for helm3
49 IS_HELM3=$(helm version -c --short|grep -e "^v3")
50 HELM_SEARCH_FLAG=""
51 if [ $IS_HELM3 ]
52 then  
53     HELM_SEARCH_FLAG="repo"
54 fi
55
56
57 HAS_RIC_COMMON_PACKAGE=$(helm search ${HELM_SEARCH_FLAG} local/ric-common | grep ric-common)
58
59 if [ -z "$HAS_RIC_COMMON_PACKAGE" ];then
60     echo "****************************************************************************************************************"
61     echo "                                                     ERROR                                                      "
62     echo "****************************************************************************************************************"
63     echo "Can't locate the ric-common helm package in the local repo. Please make sure that it is properly installed."
64     echo "****************************************************************************************************************"
65     exit 1
66 fi
67
68 HAS_AUX_COMMON_PACKAGE=$(helm search ${HELM_SEARCH_FLAG} local/aux-common | grep aux-common)
69
70 if [ -z "$HAS_AUX_COMMON_PACKAGE" ];then
71     echo "****************************************************************************************************************"
72     echo "                                                     ERROR                                                      "
73     echo "****************************************************************************************************************"
74     echo "Can't locate the aux-common helm package in the local repo. Please make sure that it is properly installed."
75     echo "****************************************************************************************************************"
76     exit 1
77 fi
78
79
80
81 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
82
83 COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
84 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
85 AUXNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *aux:/{print $2}')
86 INFRANAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *infra:/{print $2}')
87 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
88 COMPONENTS=${LIST_OF_COMPONENTS:-"infrastructure dashboard ves message-router mrsub mc-stack portal aaf"}
89
90
91 NODENAME=$(kubectl get node | awk 'NR>1{print $1}')
92 LABELFOUND=false
93 for f in $NODENAME; do
94     LABEL=$(kubectl describe node $f | grep "local-storage=enable")
95     if [ ! -z "$LABEL" ]; then
96         LABELFOUND=true
97         echo "Found lable \"local-storage=enable\" at node $f"
98     fi
99 done
100   
101 FOUND_STORAGECLASS=$(grep -w storageclass $OVERRIDEYAML)
102
103
104 if  ! $LABELFOUND && [ -z "$FOUND_STORAGECLASS" ]; then
105     echo "***********************************************************************************************"
106     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
107     echo "***********************************************************************************************"
108     echo "* Nodes label \"local-storage=enable\" is not found in any of the cluster node.               *"
109     echo "* Please pick a node and label it using the following command.                                *"
110     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> local-storage=enable                       *"
111     echo "***********************************************************************************************"
112
113     exit 1
114 fi
115
116
117 if [ -z "$FOUND_STORAGECLASS" ] && $LABELFOUND; then
118
119     DATAPATH=$(cat $DIR/../helm/dashboard/values.yaml | grep datapath | awk '{ print $2}' )
120
121
122     if [ ! -z $OVERRIDEYAML ]; then
123         DATAPATHOVERRIDE=$(cat $OVERRIDEYAML | grep datapath | awk '{ print $2}' )
124     fi
125
126     if [ ! -z "$DATAPATHOVERRIDE" ]; then
127         DATAPATH=$DATAPATHOVERRIDE
128     fi
129
130     if [ ! -d "$DATAPATH" ]; then
131         mkdir -p $DATAPATH || { echo "Directory $DATAPATH does not exist and you don't have permission to create it. Please choose a different datapath." ; exit 1 ; }
132     fi
133
134     echo "***********************************************************************************************"
135     echo "*                                          WARNING!!!!!!!!!!!!!                               *"
136     echo "***********************************************************************************************"
137     echo "* Dashboard will use local storage. Please make sure that directory                           *"
138     echo "* $DATAPATH                                                                                   *"
139     echo "* contains the proper files.                                                                  *"
140     echo "***********************************************************************************************"
141
142 fi
143
144
145 LABELFOUND=false
146 for f in $NODENAME; do
147     LABEL=$(kubectl describe node $f | grep "portal-storage=enable")
148     if [ ! -z "$LABEL" ]; then
149         LABELFOUND=true
150         echo "Found lable \"portal-storage=enable\" at node $f"
151     fi
152 done
153
154 if  ! $LABELFOUND; then
155     echo "***********************************************************************************************"
156     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
157     echo "***********************************************************************************************"
158     echo "* Nodes label \"portal-storage=enable\" is not found in any of the cluster node.               *"
159     echo "* Please pick a node and label it using the following command.   i                             *"
160     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> portal-storage=enable                       *"
161     echo "***********************************************************************************************"
162
163     exit 1
164 fi
165
166
167
168 if ! kubectl get ns ${AUXNAMESPACE:-ricaux}> /dev/null 2>&1; then
169     kubectl create ns ${AUXNAMESPACE:-ricaux}
170 fi
171 if ! kubectl get ns ${INFRANAMESPACE:-ricinfra}> /dev/null 2>&1; then
172     kubectl create ns ${INFRANAMESPACE:-ricinfra}
173 fi
174 if ! kubectl get ns onap > /dev/null 2>&1; then
175     kubectl create ns onap
176 fi
177
178
179
180
181 echo Add cluster roles
182     cat >ricaux-role.yaml <<EOF
183 ---
184 apiVersion: rbac.authorization.k8s.io/v1
185 kind: ClusterRole
186 metadata:
187   name: ricaux-system-default
188 rules:
189   - apiGroups: [""]
190     resources: ["pods"]
191     verbs: ["list"]
192   - apiGroups: ["batch"]
193     resources: ["jobs/status"]
194     verbs: ["get"]
195 ---
196
197 apiVersion: rbac.authorization.k8s.io/v1
198 kind: ClusterRoleBinding
199 metadata:
200   name: ricaux-system-default
201 roleRef:
202   apiGroup: rbac.authorization.k8s.io
203   kind: ClusterRole
204   name: ricaux-system-default
205 subjects:
206   - kind: ServiceAccount
207     name: default
208     namespace: ${AUXNAMESPACE:-ricaux}
209 ---
210 apiVersion: rbac.authorization.k8s.io/v1
211 kind: ClusterRole
212 metadata:
213   name: onap-system-default
214 rules:
215   - apiGroups: [""]
216     resources: ["pods"]
217     verbs: ["list"]
218   - apiGroups: ["apps"]
219     resources: ["replicasets/status"]
220     verbs: ["get"]
221   - apiGroups: ["batch"]
222     resources: ["jobs/status"]
223     verbs: ["get"]
224   - apiGroups: ["apps"]
225     resources: ["deployments", "statefulsets"]
226     verbs: ["get"]
227 ---
228
229 apiVersion: rbac.authorization.k8s.io/v1
230 kind: ClusterRoleBinding
231 metadata:
232   name: onap-system-default
233 roleRef:
234   apiGroup: rbac.authorization.k8s.io
235   kind: ClusterRole
236   name: onap-system-default
237 subjects:
238   - kind: ServiceAccount
239     name: default
240     namespace: onap
241
242 ---
243 apiVersion: rbac.authorization.k8s.io/v1
244 kind: ClusterRole
245 metadata:
246   name: ricaux-system-tiller
247 rules:
248   - apiGroups: [""]
249     resources: ["deployments"]
250     verbs: ["get", "list", "create", "delete"]
251   - apiGroups: ["apiextensions.k8s.io"]
252     resources: ["customresourcedefinitions"]
253     verbs: ["get", "list", "create", "delete"]
254   - apiGroups: ["rbac.authorization.k8s.io"]
255     resources: ["clusterroles", "clusterrolebindings"]
256     verbs: ["get", "list", "create", "delete"]
257   - apiGroups: [""]
258     resources: ["events"]
259     verbs: ["create", "patch"]
260   - apiGroups: [""]
261     resources: ["nodes"]
262     verbs: ["list", "watch", "get"]
263   - apiGroups: ["configuration.konghq.com"]
264     resources: ["kongconsumers"]
265     verbs: ["get", "list", "watch"]
266   - apiGroups: ["configuration.konghq.com"]
267     resources: ["kongcredentials"]
268     verbs: ["get", "list", "watch"]
269   - apiGroups: ["configuration.konghq.com"]
270     resources: ["kongingresses"]
271     verbs: ["get", "list", "watch"]
272   - apiGroups: ["configuration.konghq.com"]
273     resources: ["kongplugins"]
274     verbs: ["get", "list", "watch"]
275   - apiGroups: ["extensions"]
276     resources: ["ingresses/status"]
277     verbs: ["update"]
278   - apiGroups: ["networking.k8s.io"]
279     resources: ["ingresses/status"]
280     verbs: ["update"]
281   - apiGroups: ["networking.k8s.io"]
282     resources: ["ingresses"]
283     verbs: ["get", "list", "create", "delete", "watch"]
284   - apiGroups: ["danm.k8s.io"]
285     resources: ["clusternetworks"]
286     verbs: ["get", "list", "create", "delete"]
287   - apiGroups: ["storage.k8s.io"]
288     resources: ["storageclasses"]
289     verbs: ["get", "list", "create", "delete"]
290   - apiGroups: [""]
291     resources: ["persistentvolumes"]
292     verbs: ["get", "list", "create", "delete"]
293
294
295 ---
296 apiVersion: rbac.authorization.k8s.io/v1
297 kind: ClusterRoleBinding
298 metadata:
299   name: ricaux-system-tiller
300 roleRef:
301   apiGroup: rbac.authorization.k8s.io
302   kind: ClusterRole
303   name: ricaux-system-tiller
304 subjects:
305   - kind: ServiceAccount
306     name: tiller
307     namespace: kube-system
308 EOF
309 kubectl apply -f ricaux-role.yaml
310 rm ricaux-role.yaml
311
312 kubectl create configmap -n ${AUXNAMESPACE:-ricaux} aux-recipe --from-file=recipe=$OVERRIDEYAML
313
314
315
316 echo "Clean up dockerdata-nfs directory"
317 rm -rf /dockerdata-nfs/*
318
319
320 echo "Deploying AUX components [$COMPONENTS]"
321
322
323
324 for component in $COMPONENTS; do
325     helm dep up $DIR/../helm/$component
326
327     # Handle helm2/helm3 arg
328     NAME_ARG=""
329     if [ -z $IS_HELM3 ]; then
330       NAME_ARG=" --name "
331     fi
332
333     case "$component" in
334             aaf)
335                 NODENAME=$(kubectl get node | awk 'NR>1{print $1}')
336                 LABELFOUND=false
337                 for f in $NODENAME; do
338                     LABEL=$(kubectl describe node $f | grep "aaf-storage=enable")
339                     if [ ! -z "$LABEL" ]; then
340                         LABELFOUND=true
341                         echo "Found lable \"aaf-storage=enable\" at node $f"
342                     fi
343                 done
344                 
345                 if  ! $LABELFOUND; then
346                     echo "***********************************************************************************************"
347                     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
348                     echo "***********************************************************************************************"
349                     echo "* Nodes label \"aaf-storage=enable\" is not found in any of the cluster node.               *"
350                     echo "* Please pick a node and label it using the following command.                                *"
351                     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> aaf-storage=enable                       *"
352                     echo "***********************************************************************************************"
353                 else
354                     helm install -f $OVERRIDEYAML --namespace "onap" ${NAME_ARG} "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
355                 fi
356             ;;
357             *)
358                 helm install -f $OVERRIDEYAML --namespace "${AUXNAMESPACE:-ricaux}" ${NAME_ARG} "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
359                 sleep 8 
360     esac
361
362 done