4452a09ecc9535667ca243a52fdb39b3bdf99495
[ric-plt/ric-dep.git] / bin / verify-ric-charts
1 #!/bin/bash
2 ##############################################################################
3 #
4 #   Copyright (c) 2019 AT&T Intellectual Property.
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 # Installs well-known RIC charts then verifies specified helm chart
21 # Requires chart tgz archives in /tmp
22 HELMVER=$1
23 OVERRIDEYAML=$2
24
25 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
26
27 # Set up helm
28 HELMVERSION=${HELMVER:=2.12.3}
29 if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then
30   wget https://storage.googleapis.com/kubernetes-helm/helm-v${HELMVERSION}-linux-amd64.tar.gz
31 fi
32
33 tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz
34 mv linux-amd64/helm ./
35
36 # set up ric common template
37 ./setup-ric-common-template
38
39
40
41
42 # Create array of helm charts
43 CHART_ARRAY=()
44 while IFS= read -r -d $'\0'; do
45     CHART_ARRAY+=("$REPLY")
46 done < <(find $ROOT_DIR/../ -maxdepth 4 -name Chart.yaml -printf '%h\0')
47
48 echo "***************************************"
49
50
51 for dir in "${CHART_ARRAY[@]}"
52 do
53   
54     echo "Update chart depenedency"
55     ./helm dep up $dir 
56     # Lint clearly marks errors; e.g., [ERROR]
57     if [ -z $OVERRIDEYAML ]; then
58         ./helm lint $dir > /tmp/output 2>&1
59     else
60         ./helm lint -f $OVERRIDEYAML $dir> /tmp/output 2>&1
61     fi
62     echo "***************************************************************************************************************"
63     cat /tmp/output 
64     
65     egrep -q '^Error: [0-9]* chart\(s\) linted, [0-9]* chart\(s\) failed' /tmp/output && exit 1
66     echo "***************************************************************************************************************"
67
68     if [ -z $OVERRIDEYAML ]; then
69         ./helm template $dir > /tmp/output 2>&1
70     else
71         ./helm template -f $OVERRIDEYAML $dir > /tmp/output 2>&1
72     fi
73     echo "***************************************************************************************************************"
74     cat /tmp/output 
75    sleep 1 
76     egrep -n '%!.\(.*=.*\)' /tmp/output && echo "Error: Type mismatch." && exit 1
77     echo "***************************************************************************************************************"
78
79 done
80 #Error: 1 chart(s) linted, 1 chart(s) failed
81
82
83
84 exit 0
85