Skip to content

MGMT-24419: Delete DataImage after cluster is installed and remove detached annotation - #844

Open
giladravid16 wants to merge 1 commit into
openshift:mainfrom
giladravid16:MGMT-24419
Open

MGMT-24419: Delete DataImage after cluster is installed and remove detached annotation#844
giladravid16 wants to merge 1 commit into
openshift:mainfrom
giladravid16:MGMT-24419

Conversation

@giladravid16

@giladravid16 giladravid16 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Having the detached annotation prevents users from performing hardware lifecycle operations, and keeping the DataImage causes the BMO to remount it after firmware updates. So we want to remove both of them.

To avoid a race condition that can occur when restoring an ICI that isn't complete, we also annotate new ICIs with a post-cleanup annotation and make sure their DataImages were deleted after they are installed.
The race condition can occur when the main reconciler recreates the DataImage after the Monitor reconciler deletes it.

Summary by CodeRabbit

  • New Features

    • Added automatic cleanup of installation-related storage before an installation is marked complete.
    • Added automatic host reboot handling when cleanup requires it.
    • Added post-install cleanup processing for completed installations.
  • Bug Fixes

    • Installation monitoring now waits and requeues while cleanup is in progress.
    • Improved condition reporting during delayed cleanup.
    • Prevented unnecessary backup labeling of installation storage artifacts.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 24, 2026
@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 Jun 24, 2026
@openshift-ci

openshift-ci Bot commented Jun 24, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci-robot

openshift-ci-robot commented Jun 24, 2026

Copy link
Copy Markdown

@giladravid16: This pull request references MGMT-24419 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 epic to target either version "5.0." or "openshift-5.0.", but it targets "ACM 5.0" instead.

Details

In response to this:

Having the detached annotation prevents users from performing hardware lifecycle operations, and keeping the DataImage causes the BMO to remount it after firmware updates. So we want to remove both of them.

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 commented Jun 24, 2026

Copy link
Copy Markdown

Walkthrough

The change centralizes BareMetalHost and DataImage helpers, adds post-cleanup annotation handling, and gates installation completion on DataImage deletion. The monitor requeues while deletion is pending and updates installation conditions.

Changes

DataImage cleanup lifecycle

Layer / File(s) Summary
Shared BMH and DataImage lifecycle helpers
controllers/common.go, controllers/imageclusterinstall_controller.go, controllers/imageclusterinstall_monitor.go
Adds package-level helpers for resource lookup, deletion, cleanup, reboot annotations, and annotation checks. Updates controller call sites and removes duplicate reconciler methods.
Post-cleanup annotation flow
controllers/imageclusterinstall_controller.go, controllers/imageclusterinstall_controller_test.go
Active installations receive the post-cleanup annotation. Completed annotated installations delete the associated DataImage. Tests cover new, restored, annotated, and unannotated installations. DataImage backup labeling is removed.
Installation completion deletion gate
controllers/imageclusterinstall_monitor.go, controllers/imageclusterinstall_monitor_test.go
The monitor removes the associated DataImage before completion. It reports pending deletion, requeues for one minute, and marks installation complete only after removal. RBAC permissions and tests are updated.

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

Suggested reviewers: missxiaoguo, sakhoury

🚥 Pre-merge checks | ✅ 4 | ❌ 11

❌ Failed checks (1 warning, 10 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Stable And Deterministic Test Names ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Test Structure And Quality ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Microshift Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Single Node Openshift (Sno) Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Topology-Aware Scheduling Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Ote Binary Stdout Contract ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Ipv6 And Disconnected Network Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Weak-Crypto ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Container-Privileges ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Sensitive-Data-In-Logs ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: deleting the DataImage after installation and removing the detached annotation.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci

openshift-ci Bot commented Jun 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giladravid16

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 Jun 24, 2026
@giladravid16

Copy link
Copy Markdown
Contributor Author

/test e2e-ibio

@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

🧹 Nitpick comments (1)
controllers/imageclusterinstall_monitor_test.go (1)

200-205: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert detached annotation removal too.

This updated assertion verifies rebooting, but the fixture BMH never has detachedAnnotation, so the test would miss a regression where the annotation remains and blocks lifecycle operations. Seed it before reconcile and assert it is absent here.

🤖 Prompt for 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.

In `@controllers/imageclusterinstall_monitor_test.go` around lines 200 - 205, The
test in imageclusterinstall_monitor_test.go only checks rebootAnnotation on the
BMH after DataImage removal, so it can miss a regression where
detachedAnnotation is still present. Update the test setup around the bmh
fixture and reconcile path to seed detachedAnnotation before the operation, then
extend the existing BMH assertions to verify that detachedAnnotation has been
removed alongside the reboot behavior. Use the same bmh object and the existing
annotation checks in this test to keep the assertion aligned with the DataImage
removal flow.
🤖 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 `@controllers/common.go`:
- Around line 60-74: In removeBMHDataImage, detached annotation cleanup is
skipped when deleteDataImage returns nil, so the BareMetalHost is never fetched
in the already-missing DataImage case. Update the flow so the BareMetalHost
lookup and detachedAnnotation removal always happen after deleteDataImage, and
only call attachAndRebootBMH when a DataImage deletion was actually initiated
and dataImage is non-nil. Use removeBMHDataImage, deleteDataImage, and
attachAndRebootBMH to locate the logic.

---

Nitpick comments:
In `@controllers/imageclusterinstall_monitor_test.go`:
- Around line 200-205: The test in imageclusterinstall_monitor_test.go only
checks rebootAnnotation on the BMH after DataImage removal, so it can miss a
regression where detachedAnnotation is still present. Update the test setup
around the bmh fixture and reconcile path to seed detachedAnnotation before the
operation, then extend the existing BMH assertions to verify that
detachedAnnotation has been removed alongside the reboot behavior. Use the same
bmh object and the existing annotation checks in this test to keep the assertion
aligned with the DataImage removal flow.
🪄 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: Enterprise

Run ID: 909251f3-c3a2-405e-aa52-143d0e250f69

📥 Commits

Reviewing files that changed from the base of the PR and between 6621941 and 7e1d6a7.

📒 Files selected for processing (4)
  • controllers/common.go
  • controllers/imageclusterinstall_controller.go
  • controllers/imageclusterinstall_monitor.go
  • controllers/imageclusterinstall_monitor_test.go

Comment thread controllers/common.go
Comment on lines +60 to +74
func removeBMHDataImage(ctx context.Context, c client.Client, log logrus.FieldLogger, bmhRef types.NamespacedName) (*bmh_v1alpha1.DataImage, error) {
dataImage, err := deleteDataImage(ctx, c, log, bmhRef)
if err != nil || dataImage == nil {
return dataImage, err
}

bmh := &bmh_v1alpha1.BareMetalHost{}
if err := c.Get(ctx, bmhRef, bmh); err != nil {
if k8sapierrors.IsNotFound(err) {
log.Warnf("Referenced BareMetalHost %s/%s does not exist, not waiting for dataImage deletion", bmhRef.Namespace, bmhRef.Name)
return nil, nil
}
return dataImage, fmt.Errorf("failed to get BareMetalHost %s/%s: %w", bmhRef.Namespace, bmhRef.Name, err)
}
return dataImage, attachAndRebootBMH(ctx, c, log, bmh)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Decouple detached-annotation cleanup from DataImage existence.

When deleteDataImage returns nil for an already-missing DataImage, Line 62 returns before fetching the BMH, so detachedAnnotation is never removed. That leaves the lifecycle-blocking annotation in exactly the already-cleaned-up/DataImage-missing case this PR should handle.

Possible fix direction
 	dataImage, err := deleteDataImage(ctx, c, log, bmhRef)
-	if err != nil || dataImage == nil {
+	if err != nil {
 		return dataImage, err
 	}
 
 	bmh := &bmh_v1alpha1.BareMetalHost{}

Then patch the BMH so detached removal always runs, while adding the reboot annotation only when a DataImage deletion was actually requested.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func removeBMHDataImage(ctx context.Context, c client.Client, log logrus.FieldLogger, bmhRef types.NamespacedName) (*bmh_v1alpha1.DataImage, error) {
dataImage, err := deleteDataImage(ctx, c, log, bmhRef)
if err != nil || dataImage == nil {
return dataImage, err
}
bmh := &bmh_v1alpha1.BareMetalHost{}
if err := c.Get(ctx, bmhRef, bmh); err != nil {
if k8sapierrors.IsNotFound(err) {
log.Warnf("Referenced BareMetalHost %s/%s does not exist, not waiting for dataImage deletion", bmhRef.Namespace, bmhRef.Name)
return nil, nil
}
return dataImage, fmt.Errorf("failed to get BareMetalHost %s/%s: %w", bmhRef.Namespace, bmhRef.Name, err)
}
return dataImage, attachAndRebootBMH(ctx, c, log, bmh)
func removeBMHDataImage(ctx context.Context, c client.Client, log logrus.FieldLogger, bmhRef types.NamespacedName) (*bmh_v1alpha1.DataImage, error) {
dataImage, err := deleteDataImage(ctx, c, log, bmhRef)
if err != nil {
return dataImage, err
}
bmh := &bmh_v1alpha1.BareMetalHost{}
if err := c.Get(ctx, bmhRef, bmh); err != nil {
if k8sapierrors.IsNotFound(err) {
log.Warnf("Referenced BareMetalHost %s/%s does not exist, not waiting for dataImage deletion", bmhRef.Namespace, bmhRef.Name)
return nil, nil
}
return dataImage, fmt.Errorf("failed to get BareMetalHost %s/%s: %w", bmhRef.Namespace, bmhRef.Name, err)
}
return dataImage, attachAndRebootBMH(ctx, c, log, bmh)
}
🤖 Prompt for 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.

In `@controllers/common.go` around lines 60 - 74, In removeBMHDataImage, detached
annotation cleanup is skipped when deleteDataImage returns nil, so the
BareMetalHost is never fetched in the already-missing DataImage case. Update the
flow so the BareMetalHost lookup and detachedAnnotation removal always happen
after deleteDataImage, and only call attachAndRebootBMH when a DataImage
deletion was actually initiated and dataImage is non-nil. Use
removeBMHDataImage, deleteDataImage, and attachAndRebootBMH to locate the logic.

@giladravid16

Copy link
Copy Markdown
Contributor Author

/testwith openshift/image-based-install-operator/main/e2e-ibio #844 openshift/release#80991

@giladravid16
giladravid16 marked this pull request as ready for review July 19, 2026 11:24
@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 Jul 19, 2026
@openshift-ci
openshift-ci Bot requested review from Missxiaoguo and sakhoury July 19, 2026 11:24
@giladravid16

Copy link
Copy Markdown
Contributor Author

The CI failure seem to be from the seed image.
In the logs for the preinstall, it shows "node_ips":["192.168.126.10"].

@carbonin

carbonin commented Jul 28, 2026

Copy link
Copy Markdown
Member

/hold

Putting a hold here until we understand how this affects backup/restore.
If that flow was tested then we can remove the hold.
I added a comment to the JIRA about this too.

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 28, 2026
…tached annotation

Having the detached annotation prevents users from performing hardware lifecycle operations, and keeping the DataImage causes the BMO to remount it after firmware updates. So we want to remove both of them.

To avoid a race condition that can occur when restoring an ICI that isn't complete, we also annotate new ICIs with a post-cleanup annotation and make sure their DataImages were deleted after they are installed.
The race condition can occur when the main reconciler recreates the DataImage after the Monitor reconciler deletes it.

@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 `@controllers/imageclusterinstall_controller_test.go`:
- Around line 2333-2348: Add meaningful failure messages to the lifecycle
assertions in controllers/imageclusterinstall_controller_test.go:2333-2348
identifying the expected post-cleanup annotation; 2350-2366 identifying
restore-path annotation exclusion; 2368-2410 identifying required DataImage
deletion; and 2412-2453 identifying required DataImage retention and annotation
absence. Update the existing assertions in these ranges without changing their
behavior.
🪄 Autofix

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: Enterprise

Run ID: 14952c02-e16f-40cc-8f93-42e361ec3c80

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1d6a7 and 13f216f.

📒 Files selected for processing (5)
  • controllers/common.go
  • controllers/imageclusterinstall_controller.go
  • controllers/imageclusterinstall_controller_test.go
  • controllers/imageclusterinstall_monitor.go
  • controllers/imageclusterinstall_monitor_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • controllers/imageclusterinstall_monitor_test.go
  • controllers/imageclusterinstall_monitor.go

Comment on lines +2333 to +2348
It("adds DataImage cleanup annotation to new ImageClusterInstalls", func() {
Expect(c.Create(ctx, clusterInstall)).To(Succeed())
Expect(c.Create(ctx, clusterDeployment)).To(Succeed())

key := types.NamespacedName{
Namespace: clusterInstallNamespace,
Name: clusterInstallName,
}
installerSuccess()
res, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: key})
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(ctrl.Result{}))

Expect(c.Get(ctx, key, clusterInstall)).To(Succeed())
Expect(clusterInstall.Annotations).To(HaveKeyWithValue(postCleanupAnnotation, postCleanupAnnotationValue))
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add failure messages to the new lifecycle assertions.

  • controllers/imageclusterinstall_controller_test.go#L2333-L2348: add messages that identify the expected post-cleanup annotation.
  • controllers/imageclusterinstall_controller_test.go#L2350-L2366: add messages that identify restore-path annotation exclusion.
  • controllers/imageclusterinstall_controller_test.go#L2368-L2410: add messages that identify required DataImage deletion.
  • controllers/imageclusterinstall_controller_test.go#L2412-L2453: add messages that identify required DataImage retention and annotation absence.

As per coding guidelines, “Assertion messages - include meaningful failure messages; flag assertions without messages.”

📍 Affects 1 file
  • controllers/imageclusterinstall_controller_test.go#L2333-L2348 (this comment)
  • controllers/imageclusterinstall_controller_test.go#L2350-L2366
  • controllers/imageclusterinstall_controller_test.go#L2368-L2410
  • controllers/imageclusterinstall_controller_test.go#L2412-L2453
🤖 Prompt for 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.

In `@controllers/imageclusterinstall_controller_test.go` around lines 2333 - 2348,
Add meaningful failure messages to the lifecycle assertions in
controllers/imageclusterinstall_controller_test.go:2333-2348 identifying the
expected post-cleanup annotation; 2350-2366 identifying restore-path annotation
exclusion; 2368-2410 identifying required DataImage deletion; and 2412-2453
identifying required DataImage retention and annotation absence. Update the
existing assertions in these ranges without changing their behavior.

Source: Coding guidelines

@openshift-ci

openshift-ci Bot commented Aug 11, 2026

Copy link
Copy Markdown

@giladravid16: 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-ibio-v4v6 13f216f link true /test e2e-ibio-v4v6
ci/prow/ibio-reinstall-v4v6 13f216f link false /test ibio-reinstall-v4v6
ci/prow/ibio-reinstall-v6v4 13f216f link false /test ibio-reinstall-v6v4

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.

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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