Skip to content

Commit

Permalink
Prevent add spec.replaces on new Openshift catalog (#1890)
Browse files Browse the repository at this point in the history
* Evaluates if a CSV have already published to the catalog, if no then we should not add the `spec.replaces` annotation.

Signed-off-by: pjuarezd <[email protected]>

* Update manifests to remove the `spec.replaces`

Signed-off-by: pjuarezd <[email protected]>

---------

Signed-off-by: pjuarezd <[email protected]>
  • Loading branch information
pjuarezd authored Jan 11, 2024
1 parent 60981d2 commit 1c4bb96
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -764,4 +764,3 @@ spec:
- image: quay.io/minio/minio@sha256:91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3
name: minio-91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3-annotation
version: 5.0.11
replaces: minio-operator.v5.0.10
Original file line number Diff line number Diff line change
Expand Up @@ -764,4 +764,3 @@ spec:
- image: quay.io/minio/minio@sha256:91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3
name: minio-91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3-annotation
version: 5.0.11
replaces: "null"
Original file line number Diff line number Diff line change
Expand Up @@ -759,11 +759,10 @@ spec:
name: MinIO Inc
url: https://min.io
relatedImages:
- image: quay.io/minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: console
- image: quay.io/minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: minio-operator
- image: quay.io/minio/minio@sha256:91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3
name: minio-91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3-annotation
- image: quay.io/minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: console
version: 5.0.11
replaces: minio-operator-rhmp.v5.0.10
Original file line number Diff line number Diff line change
Expand Up @@ -766,4 +766,3 @@ spec:
- image: quay.io/minio/minio@sha256:91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3
name: minio-91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3-annotation
version: 5.0.11
replaces: minio-operator.v5.0.10
Original file line number Diff line number Diff line change
Expand Up @@ -766,4 +766,3 @@ spec:
- image: quay.io/minio/minio@sha256:91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3
name: minio-91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3-annotation
version: 5.0.11
replaces: "null"
5 changes: 2 additions & 3 deletions manifests/minio-operator-rhmp.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,10 @@ spec:
name: MinIO Inc
url: https://min.io
relatedImages:
- image: minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: console
- image: minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: minio-operator
- image: quay.io/minio/minio@sha256:91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3
name: minio-91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3-annotation
- image: minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: console
version: 5.0.11
replaces: minio-operator-rhmp.v5.0.10
31 changes: 23 additions & 8 deletions olm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ echo "minioVersionDigest: ${minioVersionDigest}"

redhatCatalogs=("certified-operators" "redhat-marketplace" "community-operators")

# This constants are supported Openshift versions
minOpenshiftVersion=4.8
maxOpenshiftVersion=4.14

for catalog in "${redhatCatalogs[@]}"; do
echo " "
echo $catalog
Expand Down Expand Up @@ -70,13 +74,24 @@ 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

# 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 | split(".") | map(tonumber)).csv_name' -r)
echo "replaces: $PREV_VERSION"
yq -i e ".spec.replaces |= \"${PREV_VERSION}\"" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
# 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=$(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" -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
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
rm -Rf manifests
Expand All @@ -101,7 +116,7 @@ for catalog in "${redhatCatalogs[@]}"; do
# as well as the default.
{
echo " # Annotations to specify OCP versions compatibility."
echo " com.redhat.openshift.versions: v4.8-v4.14"
echo " com.redhat.openshift.versions: v${minOpenshiftVersion}-v${maxOpenshiftVersion}"
echo " # Annotation to add default bundle channel as potential is declared"
echo " operators.operatorframework.io.bundle.channel.default.v1: stable"
echo " operatorframework.io/suggested-namespace: minio-operator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,10 @@ spec:
name: MinIO Inc
url: https://min.io
relatedImages:
- image: quay.io/minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: console
- image: quay.io/minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: minio-operator
- image: quay.io/minio/minio@sha256:91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3
name: minio-91866cdaad4cc11d2f86056b234f33f3768a44adc600ea37c225708c83076bc3-annotation
- image: quay.io/minio/operator@sha256:3ab501c476f269c4e4fc84017543ff7f6c8209ed474d77de472311472ba2e2ff
name: console
version: 5.0.11
replaces: minio-operator-rhmp.v5.0.10

0 comments on commit 1c4bb96

Please sign in to comment.