Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
Signed-off-by: pjuarezd <[email protected]>
  • Loading branch information
pjuarezd committed Nov 27, 2023
1 parent 7e7bea2 commit adc724f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions olm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,23 @@ for catalog in "${redhatCatalogs[@]}"; do
yq -i ".spec.install.spec.deployments[0].spec.template.spec.containers[0].image |= (\"${operatorImageDigest}\")" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
yq -i ".spec.install.spec.deployments[1].spec.template.spec.containers[0].image |= (\"${operatorImageDigest}\")" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml

# Will query if a previous version of the CSV was published to the catalog of the latest suported Openshift version.
# Will query if a previous version of the CSV was published to the catalog of the latest supported Openshift version.
# It will help to prevent add the `spec.replaces` annotation when there is no preexisting CSV in the catalog to replace.
# See support case https://connect.redhat.com/support/technology-partner/#/case/03671253
PREV_VERSION_IN_CATALOG=$( curl -s "curl -s "https://catalog.redhat.com/api/containers/v1/operators/bundles?channel_name=stable&package=${package}&organization=${catalog}&ocp_version=${maxOpenshiftVersion}&include=data.version,data.csv_name,data.ocp_version" | jq '.data | length'' -r)
prev=$(curl -s "https://catalog.redhat.com/api/containers/v1/operators/bundles?channel_name=stable&package=${package}&organization=${catalog}&ocp_version=${maxOpenshiftVersion}&include=data.version,data.csv_name,data.ocp_version" | jq '.data | length' -r)

# only add `spec.replaces` if at least one version have been published to the catalog
if [ "$PREV_VERSION_IN_CATALOG" -gt 0 ]; then
if [ "$prev" -gt 0 ]; then
# To provide channel for upgrade where we tell what versions can be replaced by the new version we offer
# You can read the documentation at link below:
# https://access.redhat.com/documentation/en-us/openshift_container_platform/4.2/html/operators/understanding-the-operator-lifecycle-manager-olm#olm-upgrades_olm-understanding-olm
echo "To provide replacement for upgrading Operator..."
PREV_VERSION=$(curl -s "https://catalog.redhat.com/api/containers/v1/operators/bundles?channel_name=stable&package=${package}&organization=${catalog}&include=data.version,data.csv_name,data.ocp_version" | jq '.data | max_by(.version).csv_name' -r)
echo "replaces: $PREV_VERSION"
yq -i e ".spec.replaces |= \"${PREV_VERSION}\"" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml`
yq -i e ".spec.replaces |= \"${PREV_VERSION}\"" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
else
echo "no previous published in catalog ${maxOpenshiftVersion}, removing spec.replaces"
yq -i "del(.spec.replaces) " bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
fi

# Now promote the latest release to the root of the repository
Expand Down

0 comments on commit adc724f

Please sign in to comment.