Skip to content

OCPBUGS-59197: Fix MOSB image deletion race during MOSC removal - #6348

Open
umohnani8 wants to merge 1 commit into
openshift:mainfrom
umohnani8:OCPBUGS-59197-fix-mosb-image-deletion-race
Open

OCPBUGS-59197: Fix MOSB image deletion race during MOSC removal#6348
umohnani8 wants to merge 1 commit into
openshift:mainfrom
umohnani8:OCPBUGS-59197-fix-mosb-image-deletion-race

Conversation

@umohnani8

@umohnani8 umohnani8 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes https://redhat.atlassian.net/browse/OCPBUGS-59197

- What I did
When a MachineOSConfig is deleted while nodes are actively rebasing, the node annotation safety check in deleteMOSBImage was gated on moscExists. Since the MOSC is already gone in this code path, moscExists is always false and the check is skipped entirely, allowing the image to be deleted from the registry while nodes are still using it.

Remove the moscExists gate and look up the pool directly from the MOSB's labels. If the pool exists, check node annotations before deleting. If the pool is also gone, proceed with deletion since no nodes could be using the image.

- How to verify it

Follow the steps in https://redhat.atlassian.net/browse/OCPBUGS-59197 and the race should no longer happen

- Description for the changelog
Fix MOSB image deletion race during MOSC removal

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup safeguards for build registry images.
    • Images are no longer deleted when they are currently applied to or desired by a node.
    • Added clearer handling when the associated machine pool cannot be retrieved, including validation of required labeling and better error reporting.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Jul 29, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@umohnani8: This pull request references Jira Issue OCPBUGS-59197, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @sergiordlr

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Closes https://redhat.atlassian.net/browse/OCPBUGS-59197

- What I did
When a MachineOSConfig is deleted while nodes are actively rebasing, the node annotation safety check in deleteMOSBImage was gated on moscExists. Since the MOSC is already gone in this code path, moscExists is always false and the check is skipped entirely, allowing the image to be deleted from the registry while nodes are still using it.

Remove the moscExists gate and look up the pool directly from the MOSB's labels. If the pool exists, check node annotations before deleting. If the pool is also gone, proceed with deletion since no nodes could be using the image.

- How to verify it

Follow the steps in https://redhat.atlassian.net/browse/OCPBUGS-59197 and the race should no longer happen

- Description for the changelog
Fix MOSB image deletion race during MOSC removal

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 requested review from proietfb and sergiordlr July 29, 2026 19:05
@openshift-ci

openshift-ci Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: umohnani8

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Walkthrough

deleteMOSBImage now derives the target MachineConfigPool from the MachineOSBuild label, handles pool lookup errors explicitly, and checks node image annotations before deletion.

Changes

MachineOSBuild image deletion

Layer / File(s) Summary
Pool lookup and node image guards
pkg/controller/build/reconciler.go
deleteMOSBImage validates the target pool label, retrieves the pool before scanning node image annotations, and reports unexpected pool lookup errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: proietfb, sergiordlr, eric200428

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Stable And Deterministic Test Names ✅ Passed Only pkg/controller/build/reconciler.go changed, and it contains no Ginkgo test declarations; no test names were added or modified.
Test Structure And Quality ✅ Passed PR only changes pkg/controller/build/reconciler.go; no Ginkgo tests were added or modified, so the test-structure checklist is not applicable.
Microshift Test Compatibility ✅ Passed Only pkg/controller/build/reconciler.go changed; no new Ginkgo e2e tests were added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed Only pkg/controller/build/reconciler.go changed; no _test.go or Ginkgo e2e specs were added or modified, so SNO test compatibility is unaffected.
Topology-Aware Scheduling Compatibility ✅ Passed Change is limited to controller image-deletion logic and label lookup; no manifests, replicas, affinities, nodeSelectors, or topology-aware scheduling constraints were added.
Ote Binary Stdout Contract ✅ Passed Touched code is controller logic only; no main/init/TestMain/suite setup stdout writes were added, and deleteMOSBImage logs via klog.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo/e2e tests were added or changed; only controller logic in reconciler.go was modified.
No-Weak-Crypto ✅ Passed The PR only changes deleteMOSBImage image-deletion logic; there are no weak ciphers, custom crypto, or secret/token comparisons in the touched code.
Container-Privileges ✅ Passed PR only changes Go reconciler logic; no Kubernetes manifests or securityContext settings were added or modified.
No-Sensitive-Data-In-Logs ✅ Passed The PR only changes deleteMOSBImage logic; no new or modified logging statements were introduced.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing a MOSB image deletion race during MachineOSConfig removal.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@umohnani8

Copy link
Copy Markdown
Contributor Author

/pipeline required

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aws-ovn
/test e2e-aws-ovn-upgrade
/test e2e-gcp-op-ocl-part1
/test e2e-gcp-op-ocl-part2
/test e2e-gcp-op-part1
/test e2e-gcp-op-part2
/test e2e-gcp-op-single-node
/test e2e-hypershift

@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@umohnani8: This pull request references Jira Issue OCPBUGS-59197, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @sergiordlr

Details

In response to this:

Closes https://redhat.atlassian.net/browse/OCPBUGS-59197

- What I did
When a MachineOSConfig is deleted while nodes are actively rebasing, the node annotation safety check in deleteMOSBImage was gated on moscExists. Since the MOSC is already gone in this code path, moscExists is always false and the check is skipped entirely, allowing the image to be deleted from the registry while nodes are still using it.

Remove the moscExists gate and look up the pool directly from the MOSB's labels. If the pool exists, check node annotations before deleting. If the pool is also gone, proceed with deletion since no nodes could be using the image.

- How to verify it

Follow the steps in https://redhat.atlassian.net/browse/OCPBUGS-59197 and the race should no longer happen

- Description for the changelog
Fix MOSB image deletion race during MOSC removal

Summary by CodeRabbit

  • Bug Fixes
  • Improved cleanup safeguards for build registry images.
  • Images are no longer deleted when they are currently applied to or desired by a node.
  • Added clearer handling when the associated machine pool cannot be retrieved.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/controller/build/reconciler.go`:
- Around line 949-950: Update deleteMOSBImage to validate mosb.ObjectMeta.Labels
and TargetMachineConfigPoolLabelKey before calling machineConfigPoolLister.Get;
when the label is nil, missing, or empty, fail closed and do not enter the
deleted-pool handling or delete the image. Preserve that behavior only for a
non-empty pool name whose lookup returns NotFound.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 63dd120b-8c74-4506-8562-cc61bdb1af21

📥 Commits

Reviewing files that changed from the base of the PR and between dcc57bd and a5b4d12.

📒 Files selected for processing (1)
  • pkg/controller/build/reconciler.go

Comment thread pkg/controller/build/reconciler.go Outdated
@isabella-janssen

Copy link
Copy Markdown
Member

/test tls-pqc-readiness

Ignore this test, I'm just trying to show it's stable across PRs before making it required.

@umohnani8
umohnani8 force-pushed the OCPBUGS-59197-fix-mosb-image-deletion-race branch from a5b4d12 to eaa8a7c Compare July 30, 2026 13:16
When a MachineOSConfig is deleted while nodes are actively rebasing,
the node annotation safety check in deleteMOSBImage was gated on
moscExists. Since the MOSC is already gone in this code path,
moscExists is always false and the check is skipped entirely,
allowing the image to be deleted from the registry while nodes are
still using it.

Remove the moscExists gate and look up the pool directly from the
MOSB's labels. If the pool exists, check node annotations before
deleting. If the pool is also gone, proceed with deletion since no
nodes could be using the image.

Signed-off-by: Urvashi <umohnani@redhat.com>
@umohnani8
umohnani8 force-pushed the OCPBUGS-59197-fix-mosb-image-deletion-race branch from eaa8a7c to b5f69a5 Compare July 30, 2026 13:17
@openshift-ci

openshift-ci Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@umohnani8: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-ovn-upgrade a5b4d12 link true /test e2e-aws-ovn-upgrade
ci/prow/e2e-hypershift a5b4d12 link true /test e2e-hypershift

Full PR test history. Your PR dashboard.

Details

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

@umohnani8

Copy link
Copy Markdown
Contributor Author

/pipeline required

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aws-ovn
/test e2e-aws-ovn-upgrade
/test e2e-gcp-op-ocl-part1
/test e2e-gcp-op-ocl-part2
/test e2e-gcp-op-part1
/test e2e-gcp-op-part2
/test e2e-gcp-op-single-node
/test e2e-hypershift
/test tls-pqc-readiness

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. 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.

3 participants