wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 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 | ############################################################################## |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 19 | # 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. |
| 22 | set -eu |
| 23 | echo "--> verify-ric-charts" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 24 | |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 25 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 26 | # (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 |
| 28 | if [[ "${1:-nope}" != "nope" ]]; then |
| 29 | HELMVERSION=$1 |
| 30 | else |
vipin | e38909d | 2020-12-21 10:35:07 +0000 | [diff] [blame] | 31 | HELMVERSION=2.17.0 |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 32 | fi |
| 33 | if [[ "${2:-nope}" != "nope" ]]; then |
| 34 | OVERRIDEYAML=$2 |
Zhe Huang | dbdd2b5 | 2020-03-26 16:50:33 -0400 | [diff] [blame] | 35 | fi |
| 36 | |
Zhe Huang | 1c0c34b | 2020-04-07 16:50:52 -0400 | [diff] [blame] | 37 | ROOT_DIR="$(pwd)" |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 38 | HELM_COMMAND=helm |
Zhe Huang | dbdd2b5 | 2020-03-26 16:50:33 -0400 | [diff] [blame] | 39 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 40 | if ! $($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 |
| 49 | fi |
| 50 | # Set up ric common template |
| 51 | # Download it/dep common template charts |
| 52 | git clone --single-branch --branch master "https://gerrit.o-ran-sc.org/r/it/dep" ./dep |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 53 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 54 | # Start Helm local repo if there isn't one |
Zhe Huang | 1c0c34b | 2020-04-07 16:50:52 -0400 | [diff] [blame] | 55 | if [ ! -z $(pgrep "$HELM_COMMAND") ]; then |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 56 | echo "Stopping existing local Helm server." |
Zhe Huang | 1c0c34b | 2020-04-07 16:50:52 -0400 | [diff] [blame] | 57 | kill -9 "$(pgrep "$HELM_COMMAND")" |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 58 | fi |
| 59 | if [ ! -d ./charts ]; then |
| 60 | mkdir ./charts |
| 61 | fi |
| 62 | echo "Starting local Helm server" |
| 63 | nohup $HELM_COMMAND serve --repo-path charts >& /dev/null & |
| 64 | # Package ric-common and serve it using Helm local repo |
| 65 | $HELM_COMMAND package --save=false -d ./charts "$ROOT_DIR/dep/ric-common/Common-Template/helm/ric-common" |
| 66 | $HELM_COMMAND package --save=false -d ./charts "$ROOT_DIR/dep/ric-common/Common-Template/helm/aux-common" |
| 67 | $HELM_COMMAND repo index ./charts |
| 68 | # Make sure that helm local repo is added |
| 69 | $HELM_COMMAND repo remove local |
Zhe Huang | 59ed8ec | 2020-12-01 18:36:43 -0500 | [diff] [blame] | 70 | $HELM_COMMAND repo remove stable |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 71 | $HELM_COMMAND repo add local http://127.0.0.1:8879/charts |
| 72 | # Remove it/dep charts |
| 73 | rm -rf ./dep |
Zhe Huang | dbdd2b5 | 2020-03-26 16:50:33 -0400 | [diff] [blame] | 74 | |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 75 | # Create array of helm charts |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 76 | echo "Finding all Helm charts" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 77 | CHART_ARRAY=() |
| 78 | while IFS= read -r -d $'\0'; do |
| 79 | CHART_ARRAY+=("$REPLY") |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 80 | done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0') |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 81 | |
| 82 | echo "***************************************" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 83 | for dir in "${CHART_ARRAY[@]}" |
| 84 | do |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 85 | echo "Running helm lint and verification on chart $dir" |
| 86 | echo "Update chart dependency" |
| 87 | $HELM_COMMAND dep up "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 88 | # Lint clearly marks errors; e.g., [ERROR] |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 89 | echo "Performing Helm lint" |
| 90 | if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 91 | $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 92 | else |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 93 | $HELM_COMMAND lint "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 94 | fi |
| 95 | echo "***************************************************************************************************************" |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 96 | echo "Rendering Helm charts locally" |
| 97 | if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 98 | $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 99 | else |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 100 | $HELM_COMMAND template "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 101 | fi |
| 102 | echo "***************************************************************************************************************" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 103 | done |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 104 | echo "--> verify-ric-charts ends" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 105 | exit 0 |
| 106 | |