Skip to content

Fix ServerMaintenance removal when Server is gone#373

Closed
stefanhipfel wants to merge 6 commits into
mainfrom
fix_issue_367
Closed

Fix ServerMaintenance removal when Server is gone#373
stefanhipfel wants to merge 6 commits into
mainfrom
fix_issue_367

Conversation

@stefanhipfel

@stefanhipfel stefanhipfel commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

Proposed changes

when bmc/server gets deleted which has a maintenance reference, the maintenance CRD will be automatically deleted now.

Fixes #367

@stefanhipfel
stefanhipfel requested a review from afritzler June 18, 2025 11:22
@github-actions github-actions Bot added size/M bug Something isn't working labels Jun 18, 2025
@stefanhipfel stefanhipfel linked an issue Jun 18, 2025 that may be closed by this pull request
@afritzler afritzler changed the title Fixes issue 367: maintenance will no longer kept around when server is deleted Fix ServerMaintenance removal when Server is gone Jun 20, 2025

@afritzler afritzler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @stefanhipfel! Some cosmetics.

Comment thread internal/controller/servermaintenance_controller_test.go Outdated
@stefanhipfel
stefanhipfel requested a review from afritzler June 26, 2025 11:18

// SetupWithManager sets up the controller with the Manager.
func (r *ServerMaintenanceReconciler) SetupWithManager(mgr ctrl.Manager) error {
if err := mgr.GetFieldIndexer().IndexField(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we move the field indexer setup to main.go of the manger - that way we can use a proper context handling.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why not leave it here and just pass the context:
func (r *ServerMaintenanceReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am with @afritzler here, I would expect to indices in the main.go. Technically, indices could used by multiple different reconcilers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would rather not put it in main.go. This file gets too cluttered otherwise. Maybe we can put it into the controller package and call it for example index.go, for all indexes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fine with me, I have no issue with larger source files, though.

@Nuckal777

Nuckal777 commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

Is this PR superseded by #387, which forbids deletion of Servers in the maintenance state?

@stefanhipfel

Copy link
Copy Markdown
Contributor Author

Is this PR superseded by #387, which forbids deletion of Servers in the maintenance state?

the pr also includes the use of FieldIndexer to find maintenances. So it is still valid

@stefanhipfel
stefanhipfel requested a review from afritzler July 15, 2025 11:12
Comment thread internal/controller/servermaintenance_controller.go Outdated

// SetupWithManager sets up the controller with the Manager.
func (r *ServerMaintenanceReconciler) SetupWithManager(mgr ctrl.Manager) error {
if err := mgr.GetFieldIndexer().IndexField(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am with @afritzler here, I would expect to indices in the main.go. Technically, indices could used by multiple different reconcilers.

@stefanhipfel
stefanhipfel requested a review from Nuckal777 July 16, 2025 08:30
if apierrors.IsNotFound(err) {
// Server not found, delete the ServerMaintenance CR
log.Info("Server no longer found, deleting ServerMaintenance", "ServerMaintenance", serverMaintenance.Name)
if err := r.Delete(ctx, serverMaintenance); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is deleting self a good idea?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think in this very rare occasion (or bad state) it is fine. Otherwise we would need to garbage collect those orphaned maintenances somewhere else.
An orphaned maintenance (without any server) is pointless and can be deleted without any side-effects

@nagadeesh-nagaraja nagadeesh-nagaraja left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! except for 1 comment about self deleting.

@stefanhipfel

Copy link
Copy Markdown
Contributor Author

closed in favour of: #272

@github-project-automation github-project-automation Bot moved this to Done in Roadmap Jul 31, 2025
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Metal Automation Jul 31, 2025
@afritzler
afritzler deleted the fix_issue_367 branch February 13, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project
Status: Done

Development

Successfully merging this pull request may close these issues.

When deleting BMCs the ServerMaintenance is not being deleted

5 participants