Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.3] Add addon version check with the repo #754

Open
wants to merge 1 commit into
base: v1.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions scripts/build-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,82 @@ tar zxvf ${CHARTS_DIR}/nvidia-driver-runtime-${NVIDIA_DRIVER_RUNTIME_CHART_VERSI
# Create Helm repo index after charts are ready
helm repo index ${CHARTS_DIR}

# Check the matching of addon chart version and repo chart version
check_addon_chart_version_matching() {
echo "charts packed in Harvester repo"
ls -alht ${CHARTS_DIR}

echo "addon template files"
ls -alht ${TOP_DIR}/pkg/config/templates/rancherd-22-addons.yaml

for filename in ${TOP_DIR}/pkg/config/templates/rancherd-22-addons.yaml; do
local tmpfile=/tmp/$(basename ${filename})
grep -v "{{" ${filename} > ${tmpfile}
local cnt=$(yq '.resources | length' ${tmpfile})

local i=0
while [[ $i -lt $cnt ]] ; do
local chart=$(idx=$i yq '.resources[env(idx)].spec.chart' ${tmpfile})
local version=$(idx=$i yq '.resources[env(idx)].spec.version' ${tmpfile})
echo addon: "$chart" version: $version

local EXIT_CODE=0
local repover=$(chart=$chart yq '.entries[strenv(chart)][0].version' < ${CHARTS_DIR}/index.yaml) || EXIT_CODE=$?
if [ $EXIT_CODE != 0 ]; then
echo WARNING: addon $chart is defined, but the chart is not packed into repo / repo struct is changed
continue
Comment on lines +160 to +161
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the indention is 1 space instead of 2spaces.

fi

# some charts are not packed into arm64 ISO, the above yq will return `null`
if [[ $repover == "null" ]] && [[ ${ARCH} == "arm64" ]]; then
echo WARNING: addon "$chart" is defined with version "$version" but the chart is not packed into repo in ${ARCH}
elif [[ $repover != $version ]]; then
echo addon "$chart" has version mis-matching: in repo is "$repover" but in addon is "$version"
Comment on lines +166 to +168
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

return 1
fi
(( i += 1 ))
done
done
echo "all addons have matched version with the repo"
}

check_addon_chart_version_matching

check_upgrade_addon_chart_version_matching() {
echo "upgrade addon files"
ls -alht ${harvester_path}/package/upgrade/addons

for filename in ${harvester_path}/package/upgrade/addons/*.yaml; do
local tmpfile=/tmp/$(basename ${filename})
grep -v "{{" ${filename} > ${tmpfile}

local chart=$(yq '.spec.chart' ${tmpfile})
local version=$(yq '.spec.version' ${tmpfile})
echo upgrade addon: "$chart" version: $version

local EXIT_CODE=0
local repover=$(chart=$chart yq '.entries[strenv(chart)][0].version' < ${CHARTS_DIR}/index.yaml) || EXIT_CODE=$?
if [ $EXIT_CODE != 0 ]; then
echo WARNING: upgrade addon $chart is defined, but the chart is not packed into repo / repo struct is changed
continue
Comment on lines +194 to +195
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

fi

# some charts are not packed into arm64 ISO, the above yq will return `null`
if [[ $repover == "null" ]] && [[ ${ARCH} == "arm64" ]]; then
echo WARNING: upgrade addon "$chart" is defined with version "$version" but the chart is not packed into repo in ${ARCH}
elif [[ $repover != $version ]]; then
# the upgrade addon is stored in GH harvester; but the chart repo is stored in GH harvester-installer
# a new version bumping generally means two PRs
# directly return 1 will cause failure in build
echo WARNING upgrade addon "$chart" has version mis-matching: in repo is "$repover" but in addon is "$version"
Comment on lines +200 to +205
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

fi
done

echo "all upgrade addons have matched version with the repo"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're not failing the build on mismatches per #750 (comment), this line will always be printed. Better to either print a count of mismatches, or maybe just not print this line at all, e.g.:

@@ -180,6 +180,7 @@ check_upgrade_addon_chart_version_matching() {
   echo "upgrade addon files"
   ls -alht ${harvester_path}/package/upgrade/addons
 
+  local mismatches=0
   for filename in ${harvester_path}/package/upgrade/addons/*.yaml; do
     local tmpfile=/tmp/$(basename ${filename})
     grep -v "{{" ${filename} > ${tmpfile}
@@ -203,10 +204,13 @@ check_upgrade_addon_chart_version_matching() {
      # a new version bumping generally means two PRs
      # directly return 1 will cause failure in build
      echo  WARNING upgrade addon "$chart" has version mis-matching: in repo is "$repover" but in addon is "$version"
+     (( mismatches +=1 ))
     fi
   done
 
-  echo "all upgrade addons have matched version with the repo"
+  if [[ $mismatches -eq 0 ]]; then
+    echo "all upgrade addons have matched version with the repo"
+  fi
 }
 
 check_upgrade_addon_chart_version_matching

}

check_upgrade_addon_chart_version_matching

# Use offline bundle cache
if [ -n "$HARVESTER_INSTALLER_OFFLINE_BUILD" -a -e /bundle ]; then
cp -rf /bundle/* ${BUNDLE_DIR}/
Expand Down
Loading