From 328bc5e4d4a350b155d4c7803576efeaae5d9d2d Mon Sep 17 00:00:00 2001 From: Brady Pratt Date: Tue, 6 Aug 2024 08:34:09 -0500 Subject: [PATCH] SDCICD-1358: custom task to get OLM bundle version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this is needed to string together the dynamic bundle generation task to the catalog generation task. The bundle ref is stored as a param in the catalog pipeline (nudged), we need to fetch the version that was put in the bundle to add an entry into the catalog with it. ``` ❯ opm render ${BUNDLE_IMAGE} { "schema": "olm.bundle", "name": "osd-example-operator.v4.16.0-28f1940", "package": "osd-example-operator", "image": "quay.io/redhat-user-workloads/oeo-cicada-tenant/osd-example-operator/bundle@sha256:5485652c17ab8ac5cf44452f67e15ed06dc9d2d7d67a7f079e76248878d5370e", "properties": [ { "type": "olm.gvk", "value": { "group": "managed.openshift.io", "kind": "Example", "version": "v1alpha1" } }, { "type": "olm.package", "value": { "packageName": "osd-example-operator", "version": "4.16.0-28f1940" } }, ... ❯ opm render ${BUNDLE_IMAGE} \ | sed -n '/"type": "olm.package"/,/}/p' \ | sed -n 's/.*"version": "\(.*\)".*/\1/p' | tr -d '\n' 4.16.0-28f1940 ``` https://github.com/openshift/osd-example-operator/blob/971083313e7eb4c7383c04a2067ac80ae535946c/.tekton/catalog-push.yaml#L176-L211 https://issues.redhat.com/browse/SDCICD-1358 Signed-off-by: Brady Pratt --- task/opm-get-bundle-version/0.1/README.md | 14 ++++++++++ .../0.1/opm-get-bundle-version.yaml | 27 +++++++++++++++++++ task/opm-get-bundle-version/OWNERS | 6 +++++ 3 files changed, 47 insertions(+) create mode 100644 task/opm-get-bundle-version/0.1/README.md create mode 100644 task/opm-get-bundle-version/0.1/opm-get-bundle-version.yaml create mode 100644 task/opm-get-bundle-version/OWNERS diff --git a/task/opm-get-bundle-version/0.1/README.md b/task/opm-get-bundle-version/0.1/README.md new file mode 100644 index 0000000000..9484a3b6d2 --- /dev/null +++ b/task/opm-get-bundle-version/0.1/README.md @@ -0,0 +1,14 @@ +# opm-get-bundle-version task + +Fetch the current version of the provided OLM bundle image + +## Parameters +|name|description|default value|required| +|---|---|---|---| +|bundle-image|OLM bundle image to query||true| + +## Results +|name|description| +|---|---| +|bundle-version|olm.package version| + diff --git a/task/opm-get-bundle-version/0.1/opm-get-bundle-version.yaml b/task/opm-get-bundle-version/0.1/opm-get-bundle-version.yaml new file mode 100644 index 0000000000..b55e3f5c02 --- /dev/null +++ b/task/opm-get-bundle-version/0.1/opm-get-bundle-version.yaml @@ -0,0 +1,27 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: opm-get-bundle-version +spec: + description: Fetch the current version of the provided OLM bundle image + params: + - name: bundle-image + description: OLM bundle image to query + results: + - name: bundle-version + description: olm.package version + steps: + - name: opm-get-bundle-version + image: "registry.redhat.io/openshift4/ose-operator-registry:latest" + env: + - name: BUNDLE_IMAGE + value: $(params.bundle-image) + script: | + #!/usr/bin/env bash + set -xeo pipefail + opm render ${BUNDLE_IMAGE} \ + | sed -n '/"type": "olm.package"/,/}/p' \ + | sed -n 's/.*"version": "\(.*\)".*/\1/p' \ + | tr -d '\n' \ + > "$(results.bundle-version.path)" diff --git a/task/opm-get-bundle-version/OWNERS b/task/opm-get-bundle-version/OWNERS new file mode 100644 index 0000000000..54bf30ad65 --- /dev/null +++ b/task/opm-get-bundle-version/OWNERS @@ -0,0 +1,6 @@ +approvers: +- jbpratt +- gurnben +reviewers: +- jbpratt +- gurnben