da9bc36227d5192b2132aecebd04128e893cc53c
[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     fi
90 done
91   
92 FOUND_STORAGECLASS=$(grep storageclass $OVERRIDEYAML)
93
94
95 if  ! $LABELFOUND && [ -z "$FOUND_STORAGECLASS" ]; then
96     echo "***********************************************************************************************"
97     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
98     echo "***********************************************************************************************"
99     echo "* Nodes label \"local-storage=enable\" is not found in any of the cluster node.               *"
100     echo "* Please pick a node and label it using the following command.                                *"
101     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> local-storage=enable                       *"
102     echo "***********************************************************************************************"
103
104     exit 1
105 fi
106
107
108 if [ -z "$FOUND_STORAGECLASS" ] && $LABELFOUND; then
109
110     DATAPATH=$(cat $DIR/../helm/dashboard/values.yaml | grep datapath | awk '{ print $2}' )
111
112
113     if [ ! -z $OVERRIDEYAML ]; then
114         DATAPATHOVERRIDE=$(cat $OVERRIDEYAML | grep datapath | awk '{ print $2}' )
115     fi
116
117     if [ ! -z "$DATAPATHOVERRIDE" ]; then
118         DATAPATH=$DATAPATHOVERRIDE
119     fi
120
121     if [ ! -d "$DATAPATH" ]; then
122         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 ; }
123     fi
124
125     echo "***********************************************************************************************"
126     echo "*                                          WARNING!!!!!!!!!!!!!                               *"
127     echo "***********************************************************************************************"
128     echo "* Dashboard will use local storage. Please make sure that directory                           *"
129     echo "* $DATAPATH                                                                                   *"
130     echo "* contains the proper files.                                                                  *"
131     echo "***********************************************************************************************"
132
133 fi
134
135
136 LABELFOUND=false
137 for f in $NODENAME; do
138     LABEL=$(kubectl describe node $f | grep "portal-storage=enable")
139     if [ ! -z "$LABEL" ]; then
140         LABELFOUND=true
141     fi
142 done
143
144 if  ! $LABELFOUND; then
145     echo "***********************************************************************************************"
146     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
147     echo "***********************************************************************************************"
148     echo "* Nodes label \"portal-storage=enable\" is not found in any of the cluster node.               *"
149     echo "* Please pick a node and label it using the following command.   i                             *"
150     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> portal-storage=enable                       *"
151     echo "***********************************************************************************************"
152
153     exit 1
154 fi
155
156
157
158 if ! kubectl get ns ${AUXNAMESPACE:-ricaux}> /dev/null 2>&1; then
159     kubectl create ns ${AUXNAMESPACE:-ricaux}
160 fi
161 if ! kubectl get ns ${INFRANAMESPACE:-ricinfra}> /dev/null 2>&1; then
162     kubectl create ns ${INFRANAMESPACE:-ricinfra}
163 fi
164 if ! kubectl get ns onap > /dev/null 2>&1; then
165     kubectl create ns onap
166 fi
167
168 HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"jobs.batch \"ricaux-portal-db-config\" is forbidden: User \"system:serviceaccount:ricaux:default\" cannot get resource \"jobs/status\" in API group \"batch\" in the namespace \"ricaux\"","reason":"Forbidden","details":{"name":"ricaux-portal-db-config","group":"batch","kind":"jobs"},"code":403}
169
170
171 HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"pods is forbidden: User \"system:serviceaccount:onap:default\" cannot list resource \"pods\" in API group \"\" in the namespace \"onap\"","reason":"Forbidden","details":{"kind":"pods"},"code":403}
172
173
174
175 echo Add cluster roles
176     cat >ricaux-role.yaml <<EOF
177 ---
178 apiVersion: rbac.authorization.k8s.io/v1
179 kind: ClusterRole
180 metadata:
181   name: ricaux-system-default
182 rules:
183   - apiGroups: [""]
184     resources: ["pods"]
185     verbs: ["list"]
186   - apiGroups: ["batch"]
187     resources: ["jobs/status"]
188     verbs: ["get"]
189 ---
190
191 apiVersion: rbac.authorization.k8s.io/v1
192 kind: ClusterRoleBinding
193 metadata:
194   name: ricaux-system-default
195 roleRef:
196   apiGroup: rbac.authorization.k8s.io
197   kind: ClusterRole
198   name: ricaux-system-default
199 subjects:
200   - kind: ServiceAccount
201     name: default
202     namespace: ${AUXNAMESPACE:-ricaux}
203 ---
204 apiVersion: rbac.authorization.k8s.io/v1
205 kind: ClusterRole
206 metadata:
207   name: onap-system-default
208 rules:
209   - apiGroups: [""]
210     resources: ["pods"]
211     verbs: ["list"]
212   - apiGroups: ["apps"]
213     resources: ["replicasets/status"]
214     verbs: ["get"]
215   - apiGroups: ["batch"]
216     resources: ["jobs/status"]
217     verbs: ["get"]
218   - apiGroups: ["apps"]
219     resources: ["deployments", "statefulsets"]
220     verbs: ["get"]
221 ---
222
223 apiVersion: rbac.authorization.k8s.io/v1
224 kind: ClusterRoleBinding
225 metadata:
226   name: onap-system-default
227 roleRef:
228   apiGroup: rbac.authorization.k8s.io
229   kind: ClusterRole
230   name: onap-system-default
231 subjects:
232   - kind: ServiceAccount
233     name: default
234     namespace: onap
235 EOF
236 kubectl apply -f ricaux-role.yaml
237 rm ricaux-role.yaml
238
239 kubectl create configmap -n ${AUXNAMESPACE:-ricaux} aux-recipe --from-file=recipe=$OVERRIDEYAML
240
241
242
243 echo "Clean up dockerdata-nfs directory"
244 rm -rf /dockerdata-nfs
245
246
247 echo "Deploying AUX components [$COMPONENTS]"
248
249
250
251 for component in $COMPONENTS; do
252     helm dep up $DIR/../helm/$component
253     case "$component" in
254             aaf)
255                 NODENAME=$(kubectl get node | awk 'NR>1{print $1}')
256                 LABELFOUND=false
257                 for f in $NODENAME; do
258                     LABEL=$(kubectl describe node $f | grep "aaf-storage=enable")
259                     if [ ! -z "$LABEL" ]; then
260                         LABELFOUND=true
261                     fi
262                 done
263                 
264                 if  ! $LABELFOUND; then
265                     echo "***********************************************************************************************"
266                     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
267                     echo "***********************************************************************************************"
268                     echo "* Nodes label \"aaf-storage=enable\" is not found in any of the cluster node.               *"
269                     echo "* Please pick a node and label it using the following command.                                *"
270                     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> aaf-storage=enable                       *"
271                     echo "***********************************************************************************************"
272                 else
273                     helm install -f $OVERRIDEYAML --namespace "onap" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
274                 fi
275             ;;
276             *)
277                 helm install -f $OVERRIDEYAML --namespace "${AUXNAMESPACE:-ricaux}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
278  
279     esac
280
281 done