Fix for gen-cloud-init.sh warning msg
[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
49 HAS_RIC_COMMON_PACKAGE=$(helm search local/ric-common | grep ric-common)
50
51 if [ -z "$HAS_RIC_COMMON_PACKAGE" ];then
52     echo "****************************************************************************************************************"
53     echo "                                                     ERROR                                                      "
54     echo "****************************************************************************************************************"
55     echo "Can't locate the ric-common helm package in the local repo. Please make sure that it is properly installed."
56     echo "****************************************************************************************************************"
57     exit 1
58 fi
59
60 HAS_AUX_COMMON_PACKAGE=$(helm search local/aux-common | grep aux-common)
61
62 if [ -z "$HAS_AUX_COMMON_PACKAGE" ];then
63     echo "****************************************************************************************************************"
64     echo "                                                     ERROR                                                      "
65     echo "****************************************************************************************************************"
66     echo "Can't locate the aux-common helm package in the local repo. Please make sure that it is properly installed."
67     echo "****************************************************************************************************************"
68     exit 1
69 fi
70
71
72
73 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
74
75 COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
76 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
77 AUXNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *aux:/{print $2}')
78 INFRANAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *infra:/{print $2}')
79 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
80 COMPONENTS=${LIST_OF_COMPONENTS:-"infrastructure dashboard ves message-router mrsub mc-stack portal aaf"}
81
82
83 NODENAME=$(kubectl get node | awk 'NR>1{print $1}')
84 LABELFOUND=false
85 for f in $NODENAME; do
86     LABEL=$(kubectl describe node $f | grep "local-storage=enable")
87     if [ ! -z "$LABEL" ]; then
88         LABELFOUND=true
89         echo "Found lable \"local-storage=enable\" at node $f"
90     fi
91 done
92   
93 FOUND_STORAGECLASS=$(grep -w storageclass $OVERRIDEYAML)
94
95
96 if  ! $LABELFOUND && [ -z "$FOUND_STORAGECLASS" ]; then
97     echo "***********************************************************************************************"
98     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
99     echo "***********************************************************************************************"
100     echo "* Nodes label \"local-storage=enable\" is not found in any of the cluster node.               *"
101     echo "* Please pick a node and label it using the following command.                                *"
102     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> local-storage=enable                       *"
103     echo "***********************************************************************************************"
104
105     exit 1
106 fi
107
108
109 if [ -z "$FOUND_STORAGECLASS" ] && $LABELFOUND; then
110
111     DATAPATH=$(cat $DIR/../helm/dashboard/values.yaml | grep datapath | awk '{ print $2}' )
112
113
114     if [ ! -z $OVERRIDEYAML ]; then
115         DATAPATHOVERRIDE=$(cat $OVERRIDEYAML | grep datapath | awk '{ print $2}' )
116     fi
117
118     if [ ! -z "$DATAPATHOVERRIDE" ]; then
119         DATAPATH=$DATAPATHOVERRIDE
120     fi
121
122     if [ ! -d "$DATAPATH" ]; then
123         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 ; }
124     fi
125
126     echo "***********************************************************************************************"
127     echo "*                                          WARNING!!!!!!!!!!!!!                               *"
128     echo "***********************************************************************************************"
129     echo "* Dashboard will use local storage. Please make sure that directory                           *"
130     echo "* $DATAPATH                                                                                   *"
131     echo "* contains the proper files.                                                                  *"
132     echo "***********************************************************************************************"
133
134 fi
135
136
137 LABELFOUND=false
138 for f in $NODENAME; do
139     LABEL=$(kubectl describe node $f | grep "portal-storage=enable")
140     if [ ! -z "$LABEL" ]; then
141         LABELFOUND=true
142         echo "Found lable \"portal-storage=enable\" at node $f"
143     fi
144 done
145
146 if  ! $LABELFOUND; then
147     echo "***********************************************************************************************"
148     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
149     echo "***********************************************************************************************"
150     echo "* Nodes label \"portal-storage=enable\" is not found in any of the cluster node.               *"
151     echo "* Please pick a node and label it using the following command.   i                             *"
152     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> portal-storage=enable                       *"
153     echo "***********************************************************************************************"
154
155     exit 1
156 fi
157
158
159
160 if ! kubectl get ns ${AUXNAMESPACE:-ricaux}> /dev/null 2>&1; then
161     kubectl create ns ${AUXNAMESPACE:-ricaux}
162 fi
163 if ! kubectl get ns ${INFRANAMESPACE:-ricinfra}> /dev/null 2>&1; then
164     kubectl create ns ${INFRANAMESPACE:-ricinfra}
165 fi
166 if ! kubectl get ns onap > /dev/null 2>&1; then
167     kubectl create ns onap
168 fi
169
170
171
172
173 echo Add cluster roles
174     cat >ricaux-role.yaml <<EOF
175 ---
176 apiVersion: rbac.authorization.k8s.io/v1
177 kind: ClusterRole
178 metadata:
179   name: ricaux-system-default
180 rules:
181   - apiGroups: [""]
182     resources: ["pods"]
183     verbs: ["list"]
184   - apiGroups: ["batch"]
185     resources: ["jobs/status"]
186     verbs: ["get"]
187 ---
188
189 apiVersion: rbac.authorization.k8s.io/v1
190 kind: ClusterRoleBinding
191 metadata:
192   name: ricaux-system-default
193 roleRef:
194   apiGroup: rbac.authorization.k8s.io
195   kind: ClusterRole
196   name: ricaux-system-default
197 subjects:
198   - kind: ServiceAccount
199     name: default
200     namespace: ${AUXNAMESPACE:-ricaux}
201 ---
202 apiVersion: rbac.authorization.k8s.io/v1
203 kind: ClusterRole
204 metadata:
205   name: onap-system-default
206 rules:
207   - apiGroups: [""]
208     resources: ["pods"]
209     verbs: ["list"]
210   - apiGroups: ["apps"]
211     resources: ["replicasets/status"]
212     verbs: ["get"]
213   - apiGroups: ["batch"]
214     resources: ["jobs/status"]
215     verbs: ["get"]
216   - apiGroups: ["apps"]
217     resources: ["deployments", "statefulsets"]
218     verbs: ["get"]
219 ---
220
221 apiVersion: rbac.authorization.k8s.io/v1
222 kind: ClusterRoleBinding
223 metadata:
224   name: onap-system-default
225 roleRef:
226   apiGroup: rbac.authorization.k8s.io
227   kind: ClusterRole
228   name: onap-system-default
229 subjects:
230   - kind: ServiceAccount
231     name: default
232     namespace: onap
233
234 ---
235 apiVersion: rbac.authorization.k8s.io/v1
236 kind: ClusterRole
237 metadata:
238   name: ricaux-system-tiller
239 rules:
240   - apiGroups: [""]
241     resources: ["deployments"]
242     verbs: ["get", "list", "create", "delete"]
243   - apiGroups: ["apiextensions.k8s.io"]
244     resources: ["customresourcedefinitions"]
245     verbs: ["get", "list", "create", "delete"]
246   - apiGroups: ["rbac.authorization.k8s.io"]
247     resources: ["clusterroles", "clusterrolebindings"]
248     verbs: ["get", "list", "create", "delete"]
249   - apiGroups: [""]
250     resources: ["events"]
251     verbs: ["create", "patch"]
252   - apiGroups: [""]
253     resources: ["nodes"]
254     verbs: ["list", "watch", "get"]
255   - apiGroups: ["configuration.konghq.com"]
256     resources: ["kongconsumers"]
257     verbs: ["get", "list", "watch"]
258   - apiGroups: ["configuration.konghq.com"]
259     resources: ["kongcredentials"]
260     verbs: ["get", "list", "watch"]
261   - apiGroups: ["configuration.konghq.com"]
262     resources: ["kongingresses"]
263     verbs: ["get", "list", "watch"]
264   - apiGroups: ["configuration.konghq.com"]
265     resources: ["kongplugins"]
266     verbs: ["get", "list", "watch"]
267   - apiGroups: ["extensions"]
268     resources: ["ingresses/status"]
269     verbs: ["update"]
270   - apiGroups: ["networking.k8s.io"]
271     resources: ["ingresses/status"]
272     verbs: ["update"]
273   - apiGroups: ["networking.k8s.io"]
274     resources: ["ingresses"]
275     verbs: ["get", "list", "create", "delete", "watch"]
276   - apiGroups: ["danm.k8s.io"]
277     resources: ["clusternetworks"]
278     verbs: ["get", "list", "create", "delete"]
279   - apiGroups: ["storage.k8s.io"]
280     resources: ["storageclasses"]
281     verbs: ["get", "list", "create", "delete"]
282   - apiGroups: [""]
283     resources: ["persistentvolumes"]
284     verbs: ["get", "list", "create", "delete"]
285
286
287 ---
288 apiVersion: rbac.authorization.k8s.io/v1
289 kind: ClusterRoleBinding
290 metadata:
291   name: ricaux-system-tiller
292 roleRef:
293   apiGroup: rbac.authorization.k8s.io
294   kind: ClusterRole
295   name: ricaux-system-tiller
296 subjects:
297   - kind: ServiceAccount
298     name: tiller
299     namespace: kube-system
300 EOF
301 kubectl apply -f ricaux-role.yaml
302 rm ricaux-role.yaml
303
304 kubectl create configmap -n ${AUXNAMESPACE:-ricaux} aux-recipe --from-file=recipe=$OVERRIDEYAML
305
306
307
308 echo "Clean up dockerdata-nfs directory"
309 rm -rf /dockerdata-nfs/*
310
311
312 echo "Deploying AUX components [$COMPONENTS]"
313
314
315
316 for component in $COMPONENTS; do
317     helm dep up $DIR/../helm/$component
318     case "$component" in
319             aaf)
320                 NODENAME=$(kubectl get node | awk 'NR>1{print $1}')
321                 LABELFOUND=false
322                 for f in $NODENAME; do
323                     LABEL=$(kubectl describe node $f | grep "aaf-storage=enable")
324                     if [ ! -z "$LABEL" ]; then
325                         LABELFOUND=true
326                         echo "Found lable \"aaf-storage=enable\" at node $f"
327                     fi
328                 done
329                 
330                 if  ! $LABELFOUND; then
331                     echo "***********************************************************************************************"
332                     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
333                     echo "***********************************************************************************************"
334                     echo "* Nodes label \"aaf-storage=enable\" is not found in any of the cluster node.               *"
335                     echo "* Please pick a node and label it using the following command.                                *"
336                     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> aaf-storage=enable                       *"
337                     echo "***********************************************************************************************"
338                 else
339                     helm install -f $OVERRIDEYAML --namespace "onap" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
340                 fi
341             ;;
342             *)
343                 helm install -f $OVERRIDEYAML --namespace "${AUXNAMESPACE:-ricaux}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
344                 sleep 8 
345     esac
346
347 done