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