Skip to content

[wip]OPRUN-4727: Add labels to relatedImages in olm.bundle - #2089

Open
hongkailiu wants to merge 2 commits into
operator-framework:masterfrom
hongkailiu:OPRUN-4727
Open

hongkailiu wants to merge 2 commits into
operator-framework:masterfrom
hongkailiu:OPRUN-4727

Conversation

@hongkailiu

@hongkailiu hongkailiu commented Sep 16, 2026

Copy link
Copy Markdown

Add the optional labels field to declcfg.RelatedImage so operator authors can classify related images by product feature. The labels are carried through the model, the declcfg<->model conversions, and the gRPC serving path, so they survive opm render, opm serve, and a render/validate round-trip.

opm validate checks the label keys and values against the Kubernetes label syntax. The check lives in Bundle.Validate rather than RelatedImage.Validate: the latter is still not called during bundle validation because production catalogs contain related images with an empty image reference, and enabling it wholesale would start rejecting them.

The field is optional and additive: bundles without labels serialize and validate exactly as before, and an older opm ignores the field.

For dev's purpose before operator-framework/api#524 (OPRUN-4764) gets in, github.com/operator-framework/api is replaced with that pull's branch. The replace directive should be dropped once the pull merges and a release carries RelatedImage.Labels.

Description of the change:

Motivation for the change:

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

Summary by CodeRabbit

  • New Features

    • Related images now support optional Kubernetes labels in bundle and CSV metadata.
    • Labels are preserved when related-image data is converted, rendered, or serialized.
  • Validation

    • Related-image labels are validated against Kubernetes label syntax.
    • Invalid label keys or values produce errors identifying the affected related image.

Add the optional `labels` field to declcfg.RelatedImage so operator
authors can classify related images by product feature. The labels are
carried through the model, the declcfg<->model conversions, and the
gRPC serving path, so they survive `opm render`, `opm serve`, and a
render/validate round-trip.

`opm validate` checks the label keys and values against the Kubernetes
label syntax. The check lives in Bundle.Validate rather than
RelatedImage.Validate: the latter is still not called during bundle
validation because production catalogs contain related images with an
empty image reference, and enabling it wholesale would start rejecting
them.

The field is optional and additive: bundles without labels serialize
and validate exactly as before, and an older opm ignores the field.

For dev's purpose before operator-framework/api#524 (OPRUN-4764) gets
in, github.com/operator-framework/api is replaced with that pull's
branch. The replace directive should be dropped once the pull merges
and a release carries RelatedImage.Labels.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Hongkai Liu <hongkailiu@users.noreply.github.com>
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Sep 16, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@hongkailiu: This pull request references OPRUN-4727 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.1.0" version, but no target version was set.

Details

In response to this:

Add the optional labels field to declcfg.RelatedImage so operator authors can classify related images by product feature. The labels are carried through the model, the declcfg<->model conversions, and the gRPC serving path, so they survive opm render, opm serve, and a render/validate round-trip.

opm validate checks the label keys and values against the Kubernetes label syntax. The check lives in Bundle.Validate rather than RelatedImage.Validate: the latter is still not called during bundle validation because production catalogs contain related images with an empty image reference, and enabling it wholesale would start rejecting them.

The field is optional and additive: bundles without labels serialize and validate exactly as before, and an older opm ignores the field.

For dev's purpose before operator-framework/api#524 (OPRUN-4764) gets in, github.com/operator-framework/api is replaced with that pull's branch. The replace directive should be dropped once the pull merges and a release carries RelatedImage.Labels.

Description of the change:

Motivation for the change:

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 16, 2026
@openshift-ci
openshift-ci Bot requested review from joelanford and pedjak September 16, 2026 14:03
@openshift-ci

openshift-ci Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 31f1ad21-ebc4-4c68-920e-33e376f167e2

📥 Commits

Reviewing files that changed from the base of the PR and between 35aa11c and 6c58e94.

📒 Files selected for processing (3)
  • test/e2e/opm_render_test.go
  • test/e2e/testdata/bundles/related-image-labels.0.1.0/manifests/related-image-labels.v0.1.0.clusterserviceversion.yaml
  • test/e2e/testdata/bundles/related-image-labels.0.1.0/metadata/annotations.yaml

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The change adds optional labels to related images, preserves them across CSV, model, and declarative configuration conversions, validates Kubernetes label syntax, and verifies opm render output.

Changes

Related image labels

Layer / File(s) Summary
Label contract and validation
alpha/declcfg/declcfg.go, alpha/model/model.go, alpha/model/relatedimage_labels_test.go, go.mod
Related image types support optional labels. Validation checks Kubernetes label keys and values and reports invalid relatedImages[i] entries.
Declarative configuration round trip
alpha/declcfg/declcfg_to_model.go, alpha/declcfg/model_to_declcfg.go, alpha/declcfg/relatedimages_test.go
Declarative configuration conversions preserve labels. JSON and YAML tests verify labeled and unlabeled related images.
CSV parsing and render propagation
pkg/api/..., alpha/action/relatedimage_labels_test.go, test/e2e/...
CSV parsing and conversion preserve labels. Unit and end-to-end tests verify labeled, unlabeled, and appended bundle-image entries.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CSV
  participant getRelatedImages
  participant ModelRelatedImage
  participant DeclcfgRelatedImage
  participant OpmRender
  CSV->>getRelatedImages: Parse relatedImages labels
  getRelatedImages->>ModelRelatedImage: Preserve label maps
  ModelRelatedImage->>DeclcfgRelatedImage: Copy labels
  OpmRender->>DeclcfgRelatedImage: Render bundle related images
  DeclcfgRelatedImage-->>OpmRender: Return labeled and unlabeled entries
Loading

Merge Risk: ⚪ Minimal · up to 6c58e

The render test’s expected related-image list matches this invocation path; no actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 11 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding labels to relatedImages in the olm.bundle output. The Jira identifier is relevant, and the [wip] marker does not obscure the change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 11 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

hongkailiu added a commit to hongkailiu/oc-mirror that referenced this pull request Sep 16, 2026
Operator authors can label the related images of a bundle, typically to say
which product feature each image belongs to. Add a `selectors` field to each
operator package of the ImageSetConfiguration so that disconnected users can
leave the images of the features they do not use behind.

A related image is mirrored when it carries no label at all, or when at least
one selector of its package matches its labels. The requirements within a
selector are ANDed and the selectors of a package are ORed, following the
Kubernetes label selector semantics. A package with no selector mirrors only
the images without labels, so catalogs that carry no label are mirrored exactly
as before.

The selection happens in handleRelatedImages, where the labels of the image and
the package of its bundle are both at hand, which also keeps the images left out
from reaching the copy image schema map. Every image left out is logged for
supportability. All three workflows go through collectOperator, so m2m, m2d and
d2m behave alike. Malformed selectors are rejected when the configuration is
loaded rather than halfway through a mirror.

The labels are read from declcfg.RelatedImage.Labels, which is not released yet,
hence the replace directives pointing at the branches of
operator-framework/operator-registry#2089 and operator-framework/api#524. The
former requires go 1.26.5, which bumps the go directive of this module.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@hongkailiu

hongkailiu commented Sep 16, 2026

Copy link
Copy Markdown
Author
$ git remote -v
origin  https://github.com/operator-framework/operator-sdk.git (fetch)
origin  https://github.com/operator-framework/operator-sdk.git (push)

$ git --no-pager log --pretty=oneline -1   
299157a814e674f8f40d1b91ee77d64a90e850de (HEAD -> local-test, origin/master, origin/HEAD) Bump actions/setup-go from 6 to 7 (#7115)
$ git --no-pager diff 
diff --git a/testdata/go/v4/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml b/testdata/go/v4/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml
index e11f4c61..e8e79f0f 100644
--- a/testdata/go/v4/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml
+++ b/testdata/go/v4/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml
@@ -25,6 +25,13 @@ metadata:
   name: memcached-operator.v0.0.1
   namespace: placeholder
 spec:
+  relatedImages:
+  - name: quay.io/redhat-cop/kube-rbac-proxy
+    image: quay.io/redhat-cop/kube-rbac-proxy@sha256:c68135620167c41e3d9f6c1d2ca1eb8fa24312b86186d09b8010656b9d25fb47
+    labels:
+      aaa: "true"
+  - name: quay.io/redhat-cop/namespace-configuration-operator
+    image: quay.io/redhat-cop/namespace-configuration-operator@sha256:49ed7d6155342adaa2b12fd80c6761c3081d8e6149d187cb7ff91a247cdf2e7a
   apiservicedefinitions: {}
   customresourcedefinitions:
     owned:

and

$ git --no-pager log --pretty=oneline -1
35aa11c2c1f1bb050d5fc96dfb6f07c2475eca41 (HEAD -> OPRUN-4727, hongkailiu/OPRUN-4727) OPRUN-4727: Add labels to relatedImages in olm.bundle
$ make bin/opm

$ ./bin/opm render /Users/hongkliu/repo/operator-framework/operator-sdk/testdata/go/v4/memcached-operator/bundle | jq .relatedImages
[
  {
    "name": "",
    "image": "quay.io/example/memcached-operator:v0.0.1"
  },
  {
    "name": "quay.io/redhat-cop/kube-rbac-proxy",
    "image": "quay.io/redhat-cop/kube-rbac-proxy@sha256:c68135620167c41e3d9f6c1d2ca1eb8fa24312b86186d09b8010656b9d25fb47",
    "labels": {
      "aaa": "true"
    }
  },
  {
    "name": "quay.io/redhat-cop/namespace-configuration-operator",
    "image": "quay.io/redhat-cop/namespace-configuration-operator@sha256:49ed7d6155342adaa2b12fd80c6761c3081d8e6149d187cb7ff91a247cdf2e7a"
  }
]

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.75%. Comparing base (84a861b) to head (35aa11c).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2089      +/-   ##
==========================================
+ Coverage   59.53%   59.75%   +0.22%     
==========================================
  Files          99       99              
  Lines        8157     8177      +20     
==========================================
+ Hits         4856     4886      +30     
+ Misses       2726     2715      -11     
- Partials      575      576       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Mechanize the manual check from the pull request: render a bundle
directory whose ClusterServiceVersion labels its relatedImages, and
assert the labels survive into the olm.bundle blob.

The spec execs the opm built by `make build` rather than driving the
suite's in-process cobra command, because `opm render` writes to
os.Stdout directly and calls log.Fatal on error, so opm.SetOut() would
neither capture the output nor survive a failure.

The fixture is a minimal registry+v1 bundle with one labeled and one
unlabeled related image, so the test also covers that an absent labels
field stays absent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Hongkai Liu <hongkailiu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants