Skip to content

Commit

Permalink
add k8s version check against versions supported by charts
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasferrandiz committed Oct 23, 2023
1 parent a1712df commit 84a441d
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions scripts/validate-charts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ info() {
echo '[INFO] ' "$@"
}

warn() {
echo '[WARN] ' "$@" >&2
}

error() {
echo '[ERROR] ' "$@" >&2
}
Expand Down Expand Up @@ -57,6 +61,48 @@ check_system_registry() {
' $yaml_tmp
}

is_supported() {
kube_version="$1"
lower_bound="$2"
upper_bound="$3"

kube_version="${kube_version#[vV]}"
kube_version_major="${kube_version%%\.*}"
kube_version_minor="${kube_version#*.}"
kube_version_minor="${kube_version_minor%.*}"
kube_version_patch="${kube_version##*.}"
kube_version_dash="${kube_version_patch##*-}"
kube_version_patch="${kube_version_patch%-*}"

lower_bound="${lower_bound#[vV]}"
lower_bound_major="${lower_bound%%\.*}"
lower_bound_minor="${lower_bound#*.}"
lower_bound_minor="${lower_bound_minor%.*}"
lower_bound_patch="${lower_bound##*.}"
lower_bound_dash="${lower_bound_patch##*-}"
lower_bound_patch="${lower_bound_patch%-*}"


upper_bound="${upper_bound#[vV]}"
upper_bound_major="${upper_bound%%\.*}"
upper_bound_minor="${upper_bound#*.}"
upper_bound_minor="${upper_bound_minor%.*}"
upper_bound_patch="${upper_bound##*.}"
upper_bound_dash="${upper_bound_patch##*-}"
upper_bound_patch="${upper_bound_patch%-*}"

if [ "$lower_bound_major" -le "$kube_version_major" ] && \
[ "$kube_version_major" -le "$upper_bound_major" ] && \
[ "$lower_bound_minor" -le "$kube_version_minor" ] && \
[ "$kube_version_minor" -le "$upper_bound_minor" ] && \
[ "$lower_bound_patch" -le "$kube_version_patch" ] && \
[ "$kube_version_patch" -le "$upper_bound_patch" ]; then
echo 0
else
echo 1
fi
}

check_airgap() {
chart_version=$1
chart_name=$2
Expand All @@ -66,6 +112,23 @@ check_airgap() {
values="vCenter.clusterId=test-id"
helm template test-chart --kube-version ${KUBERNETES_VERSION} --set $values $chart_tmp > $yaml_tmp;

chart_folder=$(mktemp -d)
tar xfz $chart_tmp -C $chart_folder

version_annotation=`awk '$1 ~ /catalog.cattle.io\/kube-version:/ {
print $3 " " $5
}
' $chart_folder/$chart_name/Chart.yaml `
if ! [ -z ${version_annotation} ]; then
version_annotation=${version_annotation:0:-1}
read lower_bound upper_bound <<< $version_annotation

supported=$(is_supported ${KUBERNETES_VERSION} $lower_bound $upper_bound)
if [ $supported = 1 ] ; then
warn "Chart $chart_name:$chart_version does not support k8s ${KUBERNETES_VERSION}. Skipping airgap check"
return
fi
fi
awk '$1 ~ /^image:/ {
gsub(/"/, "", $2)
gsub(/^docker.io/, "", $2)
Expand Down

0 comments on commit 84a441d

Please sign in to comment.