Skip to content

Commit cd5c798

Browse files
authored
Make the name of the override-snapshot predictable (#3344)
1 parent e6beb76 commit cd5c798

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

hack/generate/override-snapshot.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function create_component_snapshot {
4343
apiVersion: appstudio.redhat.com/v1alpha1
4444
kind: Snapshot
4545
metadata:
46-
generateName: serverless-operator-${so_version}-override-snapshot-
46+
name: serverless-operator-${so_version}-override-snapshot
4747
labels:
4848
test.appstudio.openshift.io/type: override
4949
application: serverless-operator-${so_version}
@@ -87,6 +87,8 @@ EOF
8787
# ^ we take the images from the catalogs relatedImages section for the given SO version. We could also extract the bundle image from the catalog (jq -r '. | select(.name == "serverless-operator.v'${so_semversion}'") | .image')
8888
# and extract the CSV from there and use the CSVs relatedImages section.
8989

90+
append_hash_to_snapshot_name "${snapshot_file}"
91+
9092
rm -rf "${tmp_catalog_dir}"
9193
}
9294

@@ -105,7 +107,7 @@ function create_fbc_snapshots {
105107
apiVersion: appstudio.redhat.com/v1alpha1
106108
kind: Snapshot
107109
metadata:
108-
generateName: serverless-operator-${so_version}-fbc-${ocp_version}-override-snapshot-
110+
name: serverless-operator-${so_version}-fbc-${ocp_version}-override-snapshot
109111
labels:
110112
test.appstudio.openshift.io/type: override
111113
application: serverless-operator-${so_version}-fbc-${ocp_version}
@@ -117,9 +119,19 @@ EOF
117119
index_image_digest="$(skopeo inspect --no-tags docker://"${index_image}:latest" | jq -r .Digest)"
118120
add_component "${snapshot_file}" "serverless-index-${so_version}-fbc-${ocp_version}" "${index_image}@${index_image_digest}"
119121

122+
append_hash_to_snapshot_name "${snapshot_file}"
123+
120124
done <<< "$(yq read "${rootdir}/olm-catalog/serverless-operator/project.yaml" 'requirements.ocpVersion.list[*]')"
121125
}
122126

127+
function append_hash_to_snapshot_name {
128+
file=${1}
129+
sha_sum="$(sha256sum "$file" | head -c 8)" # get first 8 chars of sha
130+
new_name="$(yq read "$file" metadata.name)-$sha_sum"
131+
132+
yq write --inplace "$file" metadata.name "$new_name"
133+
}
134+
123135
target_dir="${1:?Provide a target directory for the override snapshots as arg[1]}"
124136
create_component_snapshot "${target_dir}"
125137
create_fbc_snapshots "${target_dir}"

0 commit comments

Comments
 (0)