2 ##############################################################################
4 # Copyright (c) 2019 AT&T Intellectual Property.
5 # Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 ##############################################################################
20 # 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.
24 echo "--> verify-ric-charts"
27 # (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
29 if [[ "${1:-nope}" != "nope" ]]; then
34 if [[ "${2:-nope}" != "nope" ]]; then
40 CHARTMUSEUM_COMMAND=chartmuseum
41 CHARTMUSEUM_VERSION=0.14.0
43 if ! $($HELM_COMMAND > /dev/null);then
44 echo "Download and install Helm"
45 if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then
46 wget -nv https://get.helm.sh/helm-v${HELMVERSION}-linux-amd64.tar.gz
48 tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz
49 mv linux-amd64/helm ./
53 # Set up ric common template
54 # Download it/dep common template charts
55 git clone --single-branch --branch master "https://gerrit.o-ran-sc.org/r/it/dep" ./dep
57 # Start Helm local repo if there isn't one
58 # In Helm3, running local repo requires chartmuseum and helm-servecm plugin
59 if ! $($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
66 curl https://raw.githubusercontent.com/helm/chartmuseum/main/scripts/get-chartmuseum | bash
67 $HELM_COMMAND plugin install https://github.com/jdolitsky/helm-servecm
70 if [ ! -z $(pgrep servecm) ]; then
71 echo "Stopping existing local Helm server."
72 kill -9 "$(pgrep servecm)"
75 echo "Wait for installing servecm plugin"
77 while [ "$timeout" -gt 0 ]; do
78 if $HELM_COMMAND servecm --help | grep "ChartMuseum"; then
88 echo "Starting local Helm server"
89 $HELM_COMMAND servecm --port=8879 --storage local --storage-local-rootdir ./local-repo --context-path=/charts &
91 # Package ric-common and serve it using Helm local repo
92 $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"
95 # Make sure that helm local repo is added
96 $HELM_COMMAND repo index ./local-repo
97 $HELM_COMMAND repo add local http://127.0.0.1:8879/charts
99 # Remove it/dep charts
102 # Create array of helm charts
103 echo "Finding all Helm charts"
105 while IFS= read -r -d $'\0'; do
106 CHART_ARRAY+=("$REPLY")
107 done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0')
109 echo "***************************************"
110 for dir in "${CHART_ARRAY[@]}"
112 echo "Running helm lint and verification on chart $dir"
113 echo "Update chart dependency"
114 $HELM_COMMAND dep up "$dir"
115 # Lint clearly marks errors; e.g., [ERROR]
116 echo "Performing Helm lint"
117 if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
118 $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir"
120 $HELM_COMMAND lint "$dir"
122 echo "***************************************************************************************************************"
123 echo "Rendering Helm charts locally"
124 if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
125 $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir"
127 $HELM_COMMAND template "$dir"
129 echo "***************************************************************************************************************"
131 echo "--> verify-ric-charts ends"