Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDCICD-1358: custom task to get OLM bundle version #1255

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
MartinBasti marked this conversation as resolved.
Show resolved Hide resolved
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)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems rather fragile, e.g. it wouldn't work if the JSON was printed compactly or if the order of the keys was different

        {
            "value": {
                "packageName": "osd-example-operator",
                "version": "4.16.0-28f1940"
            },
            "type": "olm.package"
        }

Is there reason to believe that opm would always format the output in a way that will work with this sed command?

Copy link
Contributor Author

@jbpratt jbpratt Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We control the way opm is ran (with json output), and we aren't receiving arbitrarily formatted JSON, I would assume this to be pretty stable. I don't think there is a way to print the json compactly through opm render, the only other output option being YAML through the --output=yaml flag. I would have preferred to use JQ but I can't find an image with both opm and jq in it. Your suggestion below for using JQ is a great improvement I can follow up with.

The order of the keys shouldn't matter, we search for the olm.package object, then the value inside of that.

This also shouldn't really be used outside of our specific use case which is stringing together the custom tasks/pipelines so far which we control the inputs to.

Copy link
Contributor

@chmeliik chmeliik Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the keys shouldn't matter

Would only matter if value came before type as in my example. That does seem unlikely though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use your two step recommendation! PTAL when you have a minute, thank you!!

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
Loading