Skip to content

Commit c0e285b

Browse files
committed
validate_helm_chart: add support for oci repositories
Signed-off-by: André Martins <andre@cilium.io>
1 parent 19fbbf9 commit c0e285b

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

validate_helm_chart.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ shopt -s expand_aliases
88

99
DOCKER=${DOCKER:-docker}
1010

11+
HELM_CACHE_DIR=$(mktemp -d)
12+
trap 'rm -rf "$HELM_CACHE_DIR"' EXIT
13+
1114
helm() {
12-
"${DOCKER}" run --user "$(id -u):$(id -g)" --rm -v "$(pwd)":/apps alpine/helm:3.15.1 "$@"
15+
"${DOCKER}" run --user "$(id -u):$(id -g)" --rm \
16+
-v "$(pwd)":/apps \
17+
-v "$HELM_CACHE_DIR":/tmp/helm \
18+
-e XDG_CACHE_HOME=/tmp/helm \
19+
-e XDG_CONFIG_HOME=/tmp/helm \
20+
-e XDG_DATA_HOME=/tmp/helm \
21+
alpine/helm:3.15.1 "$@"
1322
}
1423

1524
yq () {
@@ -55,8 +64,25 @@ main() {
5564
exit 1
5665
fi
5766

58-
APP=$(helm show chart "$CHART" | yq e '.name' -)
59-
CHART_VERSION=$(helm show chart "$CHART" | yq e '.version' -)
67+
if [[ "$CHART" =~ ^oci:// ]]; then
68+
OCI_BASE=$(echo "$CHART" | cut -d':' -f1,2) # oci://registry/path/chart
69+
OCI_VERSION=$(echo "$CHART" | rev | cut -d':' -f1 | rev) # version
70+
71+
if [[ "$OCI_BASE" == "$CHART" ]]; then
72+
echo "ERROR: OCI chart reference must include version (e.g., oci://registry/chart:1.0.0)"
73+
usage
74+
exit 1
75+
fi
76+
77+
CHART_REF="$OCI_BASE"
78+
VERSION_FLAG="--version $OCI_VERSION"
79+
else
80+
CHART_REF="$CHART"
81+
VERSION_FLAG=""
82+
fi
83+
84+
APP=$(helm show chart $VERSION_FLAG "$CHART_REF" | yq e '.name' -)
85+
CHART_VERSION=$(helm show chart $VERSION_FLAG "$CHART_REF" | yq e '.version' -)
6086
if [ "$APP" == "cilium" ]; then
6187
IMAGE_PATHS=("${CILIUM_IMAGE_PATHS[@]}")
6288
elif [ "$APP" == "tetragon" ]; then
@@ -67,7 +93,7 @@ main() {
6793
fi
6894

6995
for path in "${IMAGE_PATHS[@]}"; do
70-
tag=$(helm show values --jsonpath "$path" "$CHART")
96+
tag=$(helm show values $VERSION_FLAG --jsonpath "$path" "$CHART_REF")
7197
if [ "$tag" == "v$CHART_VERSION" ]; then
7298
echo "SUCCESS: $APP $path=$tag matches chart version $CHART_VERSION"
7399
else

0 commit comments

Comments
 (0)