Skip to content

Conversation

@camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Nov 9, 2025

Revisions are now discovered using a label-based cache instead of walking explicit Spec.Previous chains.
This makes lookups faster, safer, and ensures no orphan revisions are left behind when a ClusterExtension is deleted.
Migration automatically sets ownerReferences for existing revisions.

What Changed

Before:

  • Revisions tracked previous ones via Spec.Previous
  • Migration didn’t set ownerReferences
  • Finding related revisions required walking the chain

Now:

  • Revisions are queried by label olm.operatorframework.io/owner
  • Filtered in-memory (skip current, archived, deleting)
  • Migration sets ownerReferences

Why It's Better

  • Faster: Uses cache, no API calls
  • Simpler: One label query instead of walking chains
  • Cleaner: Deleting a ClusterExtension auto-deletes its revisions
  • No orphans left behind

Where it matters ( With Boxcutter runtime only )

  • Upgrade: Migrated revisions get ownerReferences
  • Management: Faster revision lookups, less API load
  • Cleanup: Deleting a ClusterExtension removes all its revisions — no orphans left behind

Copilot AI review requested due to automatic review settings November 9, 2025 00:17
@camilamacedo86 camilamacedo86 requested a review from a team as a code owner November 9, 2025 00:17
@netlify
Copy link

netlify bot commented Nov 9, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit ef2c006
🔍 Latest deploy log https://app.netlify.com/projects/olmv1/deploys/6910e4f593e3aa00082689d5
😎 Deploy Preview https://deploy-preview-2315--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors how previous revisions are discovered during ClusterExtensionRevision reconciliation. Instead of relying on a static Spec.Previous field, the controller now dynamically queries for previous revisions using the owner label, enabling more flexible revision management.

Key changes:

  • Introduced ListPreviousRevisions() method to dynamically discover sibling revisions
  • Updated toBoxcutterRevision() to call ListPreviousRevisions() and return errors
  • Enhanced test coverage with comprehensive test cases for the new listing logic
  • Improved test names and added scenario comments for better readability

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/operator-controller/controllers/clusterextensionrevision_controller.go Added ListPreviousRevisions() method for dynamic revision discovery, refactored toBoxcutterRevision() signature to return errors, removed unused unstructured import
internal/operator-controller/controllers/clusterextensionrevision_controller_test.go Added comprehensive tests for ListPreviousRevisions(), updated test names to be more descriptive, added scenario comments, updated mockTrackingCache to delegate Get/List to actual client, removed obsolete Spec.Previous test setup, added owner label to test revision helper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camilamacedo86 camilamacedo86 changed the title ✨ (chore): (Boxcutter): Use label selector for listing previous revisions WIP ✨ (chore): (Boxcutter): Use label selector for listing previous revisions Nov 9, 2025
@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 Nov 9, 2025
@codecov
Copy link

codecov bot commented Nov 9, 2025

Codecov Report

❌ Patch coverage is 69.11765% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.11%. Comparing base (b3f85d5) to head (ef2c006).

Files with missing lines Patch % Lines
...controllers/clusterextensionrevision_controller.go 61.53% 11 Missing and 4 partials ⚠️
internal/operator-controller/applier/boxcutter.go 78.57% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2315      +/-   ##
==========================================
+ Coverage   71.14%   74.11%   +2.96%     
==========================================
  Files          91       91              
  Lines        7046     7101      +55     
==========================================
+ Hits         5013     5263     +250     
+ Misses       1618     1417     -201     
- Partials      415      421       +6     
Flag Coverage Δ
e2e 45.51% <0.00%> (-0.43%) ⬇️
experimental-e2e 47.98% <44.11%> (?)
unit 58.59% <67.64%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@camilamacedo86 camilamacedo86 force-pushed the boxcutter-use-labels-cache branch from 3a1c266 to 9c8f9af Compare November 9, 2025 11:26
@openshift-ci
Copy link

openshift-ci bot commented Nov 9, 2025

[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 grokspawn, thetechnick for approval. For more information see the Code Review Process.

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

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

@camilamacedo86 camilamacedo86 force-pushed the boxcutter-use-labels-cache branch from 9c8f9af to 6026ae8 Compare November 9, 2025 11:35
@camilamacedo86 camilamacedo86 changed the title WIP ✨ (chore): (Boxcutter): Use label selector for listing previous revisions WIP ✨ (chore): (Boxcutter): se label-based cache for revision lookups instead of explicit chains; Nov 9, 2025
@camilamacedo86 camilamacedo86 changed the title WIP ✨ (chore): (Boxcutter): se label-based cache for revision lookups instead of explicit chains; ✨ (Valid for Boxcutter Runtime Only) switched to label-based revision lookups — faster, safer, and no orphans left behind. Nov 9, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 9, 2025
@camilamacedo86 camilamacedo86 changed the title ✨ (Valid for Boxcutter Runtime Only) switched to label-based revision lookups — faster, safer, and no orphans left behind. WIP ✨ (Valid for Boxcutter Runtime Only) switched to label-based revision lookups — faster, safer, and no orphans left behind. Nov 9, 2025
@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 Nov 9, 2025
@camilamacedo86 camilamacedo86 force-pushed the boxcutter-use-labels-cache branch 4 times, most recently from c067348 to 6076304 Compare November 9, 2025 12:57
Copilot AI review requested due to automatic review settings November 9, 2025 13:10
@camilamacedo86 camilamacedo86 force-pushed the boxcutter-use-labels-cache branch from 6076304 to 5a89bed Compare November 9, 2025 13:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camilamacedo86 camilamacedo86 force-pushed the boxcutter-use-labels-cache branch from 5a89bed to fbf27d6 Compare November 9, 2025 13:50
Copilot AI review requested due to automatic review settings November 9, 2025 18:24
@camilamacedo86 camilamacedo86 force-pushed the boxcutter-use-labels-cache branch from fbf27d6 to c7ea251 Compare November 9, 2025 18:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…it chains

Instead of tracking revision history through Spec.Previous fields, we now
find related revisions using labels and the controller-runtime cache. This
is more efficient and works better with controller-runtime's caching layer.

To support this change, the Helm-to-Boxcutter migration now sets
ownerReferences on migrated revisions, ensuring they work identically
to newly created revisions.

Assisted-by: Cursor
@camilamacedo86 camilamacedo86 force-pushed the boxcutter-use-labels-cache branch from c7ea251 to ef2c006 Compare November 9, 2025 19:01
// Package name must be in labels for BoxcutterRevisionStatesGetter to find it
if pkg, ok := annotations[labels.PackageNameKey]; ok {
revisionLabels[labels.PackageNameKey] = pkg
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why:

  • Main already reads Package from rev.Labels["package-name"] in BoxcutterRevisionStatesGetter
  • But main doesn't set it during migration - Package field was always empty
  • This fixes the bug by copying package name from annotations to labels

}
// Only archive revisions with lower revision numbers (actual previous revisions)
if r.Spec.Revision >= rev.Spec.Revision {
continue
Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Nov 9, 2025

Choose a reason for hiding this comment

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

We still populate Spec.Previous even though we now use labels for discovery because:

    1. API Compatibility - It's a published field in the CRD and marked immutable. Removing it would be a breaking change.
    1. Garbage Collection - setPreviousRevisions() uses it to enforce the 5 revision limit and delete older archived revisions.
    1. Audit Trail - Provides a historical record of the revision chain, useful for debugging and understanding upgrade history.

if err := bc.Client.Get(ctx, client.ObjectKey{Name: currentRevision.Name}, updated); err != nil {
return false, "", fmt.Errorf("fetching updated revision: %w", err)
}
currentRevision = updated
Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Nov 9, 2025

Choose a reason for hiding this comment

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

After in-place patch, currentRevision pointed to stale object with old annotations.
It is a bug fixes required to allow we move forward here and pass on the tests.
The scenario where it would fail is: v1.0.0 → v1.0.1 with identical bundle (only metadata changes)

// - When a revision is archived or being deleted, exclude it from results
// - When a revision has a higher or equal revision number, exclude it (not a previous revision)
// - Otherwise include active and paused revisions with matching owner
func (c *ClusterExtensionRevisionReconciler) ListPreviousRevisions(ctx context.Context, rev *ocv1.ClusterExtensionRevision) ([]client.Object, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added ListPreviousRevisions(ctx, rev) that queries revisions by owner label and filters:

  • Same ClusterExtension owner
  • Revision number < current (only actual previous revisions)
  • Active or paused (not archived)

Why the revision number filter matters:
Without it, Revision-1 completing would archive Revision-2, causing "revision is archived" errors.

@camilamacedo86 camilamacedo86 changed the title WIP ✨ (Valid for Boxcutter Runtime Only) switched to label-based revision lookups — faster, safer, and no orphans left behind. ✨ (Valid for Boxcutter Runtime Only) switched to label-based revision lookups — faster, safer, and no orphans left behind. Nov 9, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 9, 2025
// This makes the migrated revision consistent with revisions created by normal Boxcutter flow.
if err := controllerutil.SetControllerReference(ext, rev, m.Scheme); err != nil {
return fmt.Errorf("set ownerref: %w", err)
}
Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Nov 9, 2025

Choose a reason for hiding this comment

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

@tmshort That should address the JIRA you added: https://issues.redhat.com/browse/OPRUN-4038

Once this PR is merged, I plan to extend the test coverage to validate the orphan scenario, ensuring we’re not leaving any orphans behind. If we identify any, we’ll handle them properly in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant