Skip to content

Commit

Permalink
SDCICD-1358: custom task to get OLM bundle version
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jbpratt authored and MartinBasti committed Aug 9, 2024
1 parent 2425e36 commit 2680275
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
18 changes: 18 additions & 0 deletions task/opm-get-bundle-version/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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|

## Workspaces
|name|description|optional|
|---|---|---|
|workspace|The shared workspace between steps|false|
38 changes: 38 additions & 0 deletions task/opm-get-bundle-version/0.1/opm-get-bundle-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
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
workspaces:
- name: workspace
description: The shared workspace between steps
steps:
- name: opm-render-bundle
image: "registry.redhat.io/openshift4/ose-operator-registry:latest"
securityContext:
runAsUser: 0
env:
- name: BUNDLE_IMAGE
value: $(params.bundle-image)
script: |
#!/usr/bin/env bash
set -xe
opm render "${BUNDLE_IMAGE}" > "$(workspaces.workspace.path)/bundle.json"
- name: jq-get-olm-package-version
image: "quay.io/konflux-ci/appstudio-utils:ab6b0b8e40e440158e7288c73aff1cf83a2cc8a9@sha256:24179f0efd06c65d16868c2d7eb82573cce8e43533de6cea14fec3b7446e0b14"
script: |
#!/usr/bin/env bash
set -xe
jq -jr \
'.properties | .[] | select(.type == "olm.package") | .value.version' \
"$(workspaces.workspace.path)/bundle.json" \
> "$(results.bundle-version.path)"
6 changes: 6 additions & 0 deletions task/opm-get-bundle-version/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
approvers:
- jbpratt
- gurnben
reviewers:
- jbpratt
- gurnben

0 comments on commit 2680275

Please sign in to comment.