Extend K8S and RIC installation instructions
[it/dep.git] / ric-aux / 80-Auxiliary-Functions / 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 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
49 GLOBAL_BLOCK=$(cat $OVERRIDEYAML | awk '/^global:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
50 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
51 NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *aux:/{print $2}')
52 RELEASE_PREFIX=$(echo "$GLOBAL_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
53 COMPONENTS=${LIST_OF_COMPONENTS:-"dashboard ves message-router mrsub mc-stack portal aaf"}
54
55
56 NODENAME=$(kubectl get node | awk 'NR>1{print $1}')
57 LABELFOUND=false
58 for f in $NODENAME; do
59     LABEL=$(kubectl describe node $f | grep local-storage)
60     if [ ! -z "$LABEL" ]; then
61         LABELFOUND=true
62     fi
63 done
64   
65 FOUND_STORAGECLASS=$(grep storageclass $OVERRIDEYAML)
66
67
68 if  ! $LABELFOUND && [ -z "$FOUND_STORAGECLASS" ]; then
69     echo "***********************************************************************************************"
70     echo "*                                          ERROR!!!!!!!!!!!!!                                 *"
71     echo "***********************************************************************************************"
72     echo "* Nodes label \"local-storage=enable\" is not found in any of the cluster node.               *"
73     echo "* Please pick a node and label it using the following command.                                *"
74     echo "* kubectl label --overwrite nodes <YOUR_NODE_NAME> local-storage=enable                       *"
75     echo "***********************************************************************************************"
76
77     exit 1
78 fi
79
80
81 if [ -z "$FOUND_STORAGECLASS" ] && $LABELFOUND; then
82
83     DATAPATH=$(cat $DIR/../helm/dashboard/values.yaml | grep datapath | awk '{ print $2}' )
84
85
86     if [ ! -z $OVERRIDEYAML ]; then
87         DATAPATHOVERRIDE=$(cat $OVERRIDEYAML | grep datapath | awk '{ print $2}' )
88     fi
89
90     if [ ! -z "$DATAPATHOVERRIDE" ]; then
91         DATAPATH=$DATAPATHOVERRIDE
92     fi
93
94     if [ ! -d "$DATAPATH" ]; then
95         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 ; }
96     fi
97
98     echo "***********************************************************************************************"
99     echo "*                                          WARNING!!!!!!!!!!!!!                               *"
100     echo "***********************************************************************************************"
101     echo "* Dashboard will use local storage. Please make sure that directory                           *"
102     echo "* $DATAPATH                                                                                   *"
103     echo "* contains the proper files.                                                                  *"
104     echo "***********************************************************************************************"
105
106 fi
107
108 echo "Deploying RIC infra components [$COMPONENTS]"
109
110 COMMON_CHART_VERSION=$(cat $DIR/../../../ric-common/Common-Template/helm/ric-common/Chart.yaml | grep version | awk '{print $2}')
111 helm package -d /tmp $DIR/../../../ric-common/Common-Template/helm/ric-common
112
113
114 for component in $COMPONENTS; do
115     case "$component" in
116             dashboard | ves | message-router | mrsub | mc-stack | portal)
117                 mkdir -p $DIR/../helm/$component/charts/
118                 cp /tmp/ric-common-$COMMON_CHART_VERSION.tgz $DIR/../helm/$component/charts/
119                 helm install -f $OVERRIDEYAML --namespace "${NAMESPACE}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
120             ;;
121             aaf)
122                 mkdir -p $DIR/../helm/$component/charts/
123                 cp /tmp/ric-common-$COMMON_CHART_VERSION.tgz $DIR/../helm/$component/charts/
124                 helm install -f $OVERRIDEYAML --namespace "onap" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
125             ;;
126             *)
127                 helm install --namespace "${NAMESPACE}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
128  
129     esac
130
131 done