Skip to content

Commit e6beb76

Browse files
authored
Add revision alignment check for images in CSV (#3338)
1 parent 809d133 commit e6beb76

File tree

3 files changed

+109
-18
lines changed

3 files changed

+109
-18
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ generated-files-release-next: release-files
379379
(cd olm-catalog/serverless-operator && USE_RELEASE_NEXT=true ./hack/update-manifests.sh)
380380
./hack/update-deps.sh
381381

382+
verify-csv-revisions: install-tools
383+
./hack/verify-csv-revisions.sh
384+
382385
# Runs the lints Github Actions do too.
383386
lint:
384387
woke

hack/lib/images.bash

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -303,24 +303,8 @@ function latest_registry_redhat_io_image_sha() {
303303
exit 1
304304
fi
305305

306-
digest="${image##*@}" # Get only sha
307-
308-
image_name=${image_without_tag##*/} # Get image name after last slash
309-
310-
# Add rhel suffix
311-
if [ "${image_name}" == "serverless-openshift-kn-operator" ]; then
312-
# serverless-openshift-kn-operator is special, as it has rhel in the middle of the name
313-
# see https://redhat-internal.slack.com/archives/CKR568L8G/p1729684088850349
314-
image_name="serverless-openshift-kn-rhel$(get_serverless_operator_rhel_version)-operator"
315-
elif [ "${image_name}" == "serverless-bundle" ]; then
316-
# serverless-bundle is special, as it has no rhelXYZ in the name
317-
image_name="serverless-bundle"
318-
else
319-
# for other images simply add it as a suffix
320-
image_name="${image_name}-rhel$(get_serverless_operator_rhel_version)"
321-
fi
322-
323-
echo "${registry_redhat_io}/${image_name}@${digest}"
306+
rh_registry_image="$(get_rh_registry_image_ref "$image")"
307+
echo "$rh_registry_image"
324308
}
325309

326310
function latest_konflux_image_sha() {
@@ -363,3 +347,62 @@ function get_app_version_from_tag() {
363347
app_version=${app_version/./} # -> 134
364348
echo "${app_version}"
365349
}
350+
351+
# returns the quay image for a given rh registry image ref
352+
function get_quay_image_ref() {
353+
local rh_registry_image_ref
354+
rh_registry_image_ref="${1}"
355+
356+
if [[ $rh_registry_image_ref =~ $registry_redhat_io ]]; then
357+
image=${rh_registry_image_ref##*/} # Get image name after last slash
358+
image_sha=${image##*@} # Get SHA of image
359+
image_name=${image%@*} # Remove sha
360+
361+
if [[ "${image_name}" =~ ^serverless-openshift-kn-rhel[0-9]+-operator$ ]]; then
362+
# serverless-openshift-kn-operator is special, as it has rhel in the middle of the name
363+
# see https://redhat-internal.slack.com/archives/CKR568L8G/p1729684088850349
364+
component="serverless-openshift-kn-operator"
365+
elif [[ "${image_name}" == "serverless-operator-bundle" ]]; then
366+
# serverless-operator-bundle is special, as it is named only serverless-bundle in quay
367+
component="serverless-bundle"
368+
else
369+
# for other images simply remove the -rhelXYZ suffix
370+
component=${image_name%-rhel*}
371+
fi
372+
373+
echo "${registry_quay}/${component}@${image_sha}"
374+
else
375+
echo "Image must be from ${registry_redhat_io}, got ${rh_registry_image_ref}"
376+
return 1
377+
fi
378+
}
379+
380+
# returns the RH registry image for a given quay image ref
381+
function get_rh_registry_image_ref() {
382+
local quay_registry_image_ref
383+
quay_registry_image_ref="${1}"
384+
385+
if [[ $quay_registry_image_ref =~ $registry_quay ]]; then
386+
image=${quay_registry_image_ref##*/} # Get image name after last slash
387+
image_sha=${image##*@} # Get SHA of image
388+
image_name=${image%@*} # Remove sha
389+
390+
# Add rhel suffix
391+
if [ "${image_name}" == "serverless-openshift-kn-operator" ]; then
392+
# serverless-openshift-kn-operator is special, as it has rhel in the middle of the name
393+
# see https://redhat-internal.slack.com/archives/CKR568L8G/p1729684088850349
394+
image_name="serverless-openshift-kn-rhel$(get_serverless_operator_rhel_version)-operator"
395+
elif [ "${image_name}" == "serverless-bundle" ]; then
396+
# serverless-bundle is special, as it has no rhelXYZ in the name
397+
image_name="serverless-bundle"
398+
else
399+
# for other images simply add it as a suffix
400+
image_name="${image_name}-rhel$(get_serverless_operator_rhel_version)"
401+
fi
402+
403+
echo "${registry_redhat_io}/${image_name}@${image_sha}"
404+
else
405+
echo "Image must be from ${registry_quay}, got ${quay_registry_image_ref}"
406+
return 1
407+
fi
408+
}

hack/verify-csv-revisions.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
source "$(dirname "${BASH_SOURCE[0]}")/lib/__sources__.bash"
4+
5+
# verify that the revisions (git commit) for components from the same repo match
6+
function verify_image_revisions {
7+
local root_dir csv_file repo_revision rc
8+
root_dir="$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")"
9+
csv_file="${root_dir}/olm-catalog/serverless-operator/manifests/serverless-operator.clusterserviceversion.yaml"
10+
declare -A repo_revision=()
11+
rc=0
12+
13+
while IFS= read -r image_ref; do
14+
15+
if [[ $image_ref =~ $registry_redhat_io ]]; then
16+
quay_image_ref="$(get_quay_image_ref "$image_ref")"
17+
parameters="$(cosign download attestation "${quay_image_ref}" | jq -r '.payload' | base64 -d | jq -c '.predicate.invocation.parameters')"
18+
repo="$(echo "${parameters}" | jq -r '."git-url"')"
19+
revision="$(echo "${parameters}" | jq -r ".revision")"
20+
repo=${repo%".git"} # remove optional .git suffix from repo name
21+
22+
if [[ ! -v repo_revision[$repo] ]]; then
23+
# no revision for repo so far --> add it to map
24+
repo_revision[$repo]=$revision
25+
else
26+
if [[ "${repo_revision[$repo]}" != "$revision" ]]; then
27+
# revisions don't match
28+
image=${image_ref##*/} # Get image name after last slash
29+
30+
echo "Revision for ${image} didn't match. Expected revision ${repo_revision[$repo]} for repo ${repo}, but got ${revision}"
31+
rc=1
32+
fi
33+
fi
34+
fi
35+
36+
done <<< "$(yq read "${csv_file}" 'spec.relatedImages[*].image' | sort | uniq)"
37+
38+
if [[ "$rc" == "0" ]]; then
39+
echo "All revisions matched correctly"
40+
fi
41+
42+
return $rc
43+
}
44+
45+
verify_image_revisions

0 commit comments

Comments
 (0)