blob: 6cadf7ccd5e17aa29c401a810559575d636cb8ba [file] [log] [blame]
wriderdb365a72020-01-20 15:28:51 -05001#!/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##############################################################################
Zhe Huangfaf7b362020-03-26 17:35:19 -040019# Verifies RIC helm charts
20# Requires Linux with wget and tar.
21# This script should be executed inside the ric-plt/ric-dep bin directory only.
22set -eu
23echo "--> verify-ric-charts"
wriderdb365a72020-01-20 15:28:51 -050024
wriderdb365a72020-01-20 15:28:51 -050025
Zhe Huangfaf7b362020-03-26 17:35:19 -040026# (Optional) provide HELMVERSION as first parameter. It selects the helm client version
27# (Optional) provide OVERRIDEYAML as the second parameter. It allows us to specify an override file to replace values used to render the helm charts
28if [[ "${1:-nope}" != "nope" ]]; then
29 HELMVERSION=$1
30else
31 HELMVERSION=2.12.3
32fi
33if [[ "${2:-nope}" != "nope" ]]; then
34 OVERRIDEYAML=$2
Zhe Huangdbdd2b52020-03-26 16:50:33 -040035fi
36
Zhe Huangfaf7b362020-03-26 17:35:19 -040037ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
38HELM_COMMAND=helm
Zhe Huangdbdd2b52020-03-26 16:50:33 -040039
Zhe Huangfaf7b362020-03-26 17:35:19 -040040if ! $($HELM_COMMAND > /dev/null);then
41 echo "Download and install Helm"
42 if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then
43 wget -nv https://storage.googleapis.com/kubernetes-helm/helm-v${HELMVERSION}-linux-amd64.tar.gz
44 fi
45 tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz
46 mv linux-amd64/helm ./
47 HELM_COMMAND=./helm
48 $HELM_COMMAND init -c
49fi
50# Set up ric common template
51# Download it/dep common template charts
52git clone --single-branch --branch master "https://gerrit.o-ran-sc.org/r/it/dep" ./dep
wriderdb365a72020-01-20 15:28:51 -050053
Zhe Huangfaf7b362020-03-26 17:35:19 -040054# Start Helm local repo if there isn't one
55HELM_PID=$(pgrep "$HELM_COMMAND")
56if [ ! -z "$HELM_PID" ]; then
57 echo "Stopping existing local Helm server."
58 kill -9 "$HELM_PID"
59fi
60if [ ! -d ./charts ]; then
61 mkdir ./charts
62fi
63echo "Starting local Helm server"
64nohup $HELM_COMMAND serve --repo-path charts >& /dev/null &
65# Package ric-common and serve it using Helm local repo
66$HELM_COMMAND package --save=false -d ./charts "$ROOT_DIR/dep/ric-common/Common-Template/helm/ric-common"
67$HELM_COMMAND package --save=false -d ./charts "$ROOT_DIR/dep/ric-common/Common-Template/helm/aux-common"
68$HELM_COMMAND repo index ./charts
69# Make sure that helm local repo is added
70$HELM_COMMAND repo remove local
71$HELM_COMMAND repo add local http://127.0.0.1:8879/charts
72# Remove it/dep charts
73rm -rf ./dep
Zhe Huangdbdd2b52020-03-26 16:50:33 -040074
wriderdb365a72020-01-20 15:28:51 -050075# Create array of helm charts
Zhe Huangfaf7b362020-03-26 17:35:19 -040076echo "Finding all Helm charts"
wriderdb365a72020-01-20 15:28:51 -050077CHART_ARRAY=()
78while IFS= read -r -d $'\0'; do
79 CHART_ARRAY+=("$REPLY")
Zhe Huangfaf7b362020-03-26 17:35:19 -040080done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0')
wriderdb365a72020-01-20 15:28:51 -050081
82echo "***************************************"
wriderdb365a72020-01-20 15:28:51 -050083for dir in "${CHART_ARRAY[@]}"
84do
Zhe Huangfaf7b362020-03-26 17:35:19 -040085 echo "Running helm lint and verification on chart $dir"
86 echo "Update chart dependency"
87 $HELM_COMMAND dep up "$dir"
wriderdb365a72020-01-20 15:28:51 -050088 # Lint clearly marks errors; e.g., [ERROR]
Zhe Huangfaf7b362020-03-26 17:35:19 -040089 echo "Performing Helm lint"
90 if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
91 $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir"> /tmp/output 2>&1
wriderdb365a72020-01-20 15:28:51 -050092 else
Zhe Huangfaf7b362020-03-26 17:35:19 -040093 $HELM_COMMAND lint "$dir" > /tmp/output 2>&1
wriderdb365a72020-01-20 15:28:51 -050094 fi
95 echo "***************************************************************************************************************"
96 cat /tmp/output
wriderdb365a72020-01-20 15:28:51 -050097 egrep -q '^Error: [0-9]* chart\(s\) linted, [0-9]* chart\(s\) failed' /tmp/output && exit 1
98 echo "***************************************************************************************************************"
Zhe Huangfaf7b362020-03-26 17:35:19 -040099 echo "Rendering Helm charts locally"
100 if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
101 $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir" > /tmp/output 2>&1
wriderdb365a72020-01-20 15:28:51 -0500102 else
Zhe Huangfaf7b362020-03-26 17:35:19 -0400103 $HELM_COMMAND template "$dir" > /tmp/output 2>&1
wriderdb365a72020-01-20 15:28:51 -0500104 fi
105 echo "***************************************************************************************************************"
106 cat /tmp/output
Zhe Huangfaf7b362020-03-26 17:35:19 -0400107 grep -E -n '%!.\(.*=.*\)' /tmp/output && echo "Error: Type mismatch." && exit 1
wriderdb365a72020-01-20 15:28:51 -0500108 echo "***************************************************************************************************************"
wriderdb365a72020-01-20 15:28:51 -0500109done
Zhe Huangfaf7b362020-03-26 17:35:19 -0400110echo "--> verify-ric-charts ends"
wriderdb365a72020-01-20 15:28:51 -0500111exit 0
112