blob: 5931548d6578878939c7dd467195334911b68d20 [file] [log] [blame]
wriderdb365a72020-01-20 15:28:51 -05001#!/bin/bash
2##############################################################################
3#
4# Copyright (c) 2019 AT&T Intellectual Property.
Youhwan Seol5b917602022-09-08 10:52:57 +09005# Copyright (c) 2022 Samsung Electronics Co., Ltd.
wriderdb365a72020-01-20 15:28:51 -05006#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19##############################################################################
Zhe Huangfaf7b362020-03-26 17:35:19 -040020# Verifies RIC helm charts
21# Requires Linux with wget and tar.
22# This script should be executed inside the ric-plt/ric-dep bin directory only.
23set -eu
24echo "--> verify-ric-charts"
wriderdb365a72020-01-20 15:28:51 -050025
wriderdb365a72020-01-20 15:28:51 -050026
Zhe Huangfaf7b362020-03-26 17:35:19 -040027# (Optional) provide HELMVERSION as first parameter. It selects the helm client version
28# (Optional) provide OVERRIDEYAML as the second parameter. It allows us to specify an override file to replace values used to render the helm charts
29if [[ "${1:-nope}" != "nope" ]]; then
30 HELMVERSION=$1
31else
Youhwan Seol5b917602022-09-08 10:52:57 +090032 HELMVERSION=3.9.0
Zhe Huangfaf7b362020-03-26 17:35:19 -040033fi
34if [[ "${2:-nope}" != "nope" ]]; then
35 OVERRIDEYAML=$2
Zhe Huangdbdd2b52020-03-26 16:50:33 -040036fi
37
Zhe Huang1c0c34b2020-04-07 16:50:52 -040038ROOT_DIR="$(pwd)"
Zhe Huangfaf7b362020-03-26 17:35:19 -040039HELM_COMMAND=helm
Youhwan Seol5b917602022-09-08 10:52:57 +090040CHARTMUSEUM_COMMAND=chartmuseum
41CHARTMUSEUM_VERSION=0.14.0
Zhe Huangdbdd2b52020-03-26 16:50:33 -040042
Zhe Huangfaf7b362020-03-26 17:35:19 -040043if ! $($HELM_COMMAND > /dev/null);then
44 echo "Download and install Helm"
45 if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then
subhash kumar singhec2b8b62021-09-07 22:02:32 +053046 wget -nv https://get.helm.sh/helm-v${HELMVERSION}-linux-amd64.tar.gz
Zhe Huangfaf7b362020-03-26 17:35:19 -040047 fi
48 tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz
49 mv linux-amd64/helm ./
50 HELM_COMMAND=./helm
Zhe Huangfaf7b362020-03-26 17:35:19 -040051fi
Youhwan Seol5b917602022-09-08 10:52:57 +090052
Zhe Huangfaf7b362020-03-26 17:35:19 -040053# Set up ric common template
54# Download it/dep common template charts
55git clone --single-branch --branch master "https://gerrit.o-ran-sc.org/r/it/dep" ./dep
wriderdb365a72020-01-20 15:28:51 -050056
Zhe Huangfaf7b362020-03-26 17:35:19 -040057# Start Helm local repo if there isn't one
Youhwan Seol5b917602022-09-08 10:52:57 +090058# In Helm3, running local repo requires chartmuseum and helm-servecm plugin
59if ! $($CHARTMUSEUM_COMMAND > /dev/null);then
60 echo "Download and install chartmuseum"
61 wget -nv https://get.helm.sh/chartmuseum-v${CHARTMUSEUM_VERSION}-linux-amd64.tar.gz
62 tar -xvf ./chartmuseum-v${CHARTMUSEUM_VERSION}-linux-amd64.tar.gz
63 mv linux-amd64/chartmuseum ./
64 CHARTMUSEUM_COMMAND=./chartmuseum
65
66 curl https://raw.githubusercontent.com/helm/chartmuseum/main/scripts/get-chartmuseum | bash
67 $HELM_COMMAND plugin install https://github.com/jdolitsky/helm-servecm
68fi
69
70if [ ! -z $(pgrep servecm) ]; then
Zhe Huangfaf7b362020-03-26 17:35:19 -040071 echo "Stopping existing local Helm server."
Youhwan Seol5b917602022-09-08 10:52:57 +090072 kill -9 "$(pgrep servecm)"
Zhe Huangfaf7b362020-03-26 17:35:19 -040073fi
Youhwan Seol5b917602022-09-08 10:52:57 +090074
75echo "Wait for installing servecm plugin"
76timeout=10
77while [ "$timeout" -gt 0 ]; do
78 if $HELM_COMMAND servecm --help | grep "ChartMuseum"; then
79 break
80 fi
81 sleep 1s
82 ((timeout--))
83done
84
85rm -rf ./local-repo
86mkdir ./local-repo
87
Zhe Huangfaf7b362020-03-26 17:35:19 -040088echo "Starting local Helm server"
Youhwan Seol5b917602022-09-08 10:52:57 +090089$HELM_COMMAND servecm --port=8879 --storage local --storage-local-rootdir ./local-repo --context-path=/charts &
90
Zhe Huangfaf7b362020-03-26 17:35:19 -040091# Package ric-common and serve it using Helm local repo
Youhwan Seol5b917602022-09-08 10:52:57 +090092$HELM_COMMAND package --destination ./local-repo "$ROOT_DIR/dep/ric-common/Common-Template/helm/ric-common"
93$HELM_COMMAND package --destination ./local-repo "$ROOT_DIR/dep/ric-common/Common-Template/helm/aux-common"
94
Zhe Huangfaf7b362020-03-26 17:35:19 -040095# Make sure that helm local repo is added
Youhwan Seol5b917602022-09-08 10:52:57 +090096$HELM_COMMAND repo index ./local-repo
Zhe Huangfaf7b362020-03-26 17:35:19 -040097$HELM_COMMAND repo add local http://127.0.0.1:8879/charts
Youhwan Seol5b917602022-09-08 10:52:57 +090098
Zhe Huangfaf7b362020-03-26 17:35:19 -040099# Remove it/dep charts
100rm -rf ./dep
Zhe Huangdbdd2b52020-03-26 16:50:33 -0400101
wriderdb365a72020-01-20 15:28:51 -0500102# Create array of helm charts
Zhe Huangfaf7b362020-03-26 17:35:19 -0400103echo "Finding all Helm charts"
wriderdb365a72020-01-20 15:28:51 -0500104CHART_ARRAY=()
105while IFS= read -r -d $'\0'; do
106 CHART_ARRAY+=("$REPLY")
Zhe Huangfaf7b362020-03-26 17:35:19 -0400107done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0')
wriderdb365a72020-01-20 15:28:51 -0500108
109echo "***************************************"
wriderdb365a72020-01-20 15:28:51 -0500110for dir in "${CHART_ARRAY[@]}"
111do
Zhe Huangfaf7b362020-03-26 17:35:19 -0400112 echo "Running helm lint and verification on chart $dir"
113 echo "Update chart dependency"
114 $HELM_COMMAND dep up "$dir"
wriderdb365a72020-01-20 15:28:51 -0500115 # Lint clearly marks errors; e.g., [ERROR]
Zhe Huangfaf7b362020-03-26 17:35:19 -0400116 echo "Performing Helm lint"
117 if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
Zhe Huang2a9da682020-04-07 17:33:19 -0400118 $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir"
wriderdb365a72020-01-20 15:28:51 -0500119 else
Zhe Huang2a9da682020-04-07 17:33:19 -0400120 $HELM_COMMAND lint "$dir"
wriderdb365a72020-01-20 15:28:51 -0500121 fi
122 echo "***************************************************************************************************************"
Zhe Huangfaf7b362020-03-26 17:35:19 -0400123 echo "Rendering Helm charts locally"
124 if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
Zhe Huang2a9da682020-04-07 17:33:19 -0400125 $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir"
wriderdb365a72020-01-20 15:28:51 -0500126 else
Zhe Huang2a9da682020-04-07 17:33:19 -0400127 $HELM_COMMAND template "$dir"
wriderdb365a72020-01-20 15:28:51 -0500128 fi
129 echo "***************************************************************************************************************"
wriderdb365a72020-01-20 15:28:51 -0500130done
Zhe Huangfaf7b362020-03-26 17:35:19 -0400131echo "--> verify-ric-charts ends"
wriderdb365a72020-01-20 15:28:51 -0500132exit 0
133