Skip to content

Refactor Device controller and fix defer pattern across all controllers#190

Merged
nikatza merged 6 commits intomainfrom
refactor/device
Feb 25, 2026
Merged

Refactor Device controller and fix defer pattern across all controllers#190
nikatza merged 6 commits intomainfrom
refactor/device

Conversation

@felix-kaestner
Copy link
Contributor

@felix-kaestner felix-kaestner commented Feb 18, 2026

This PR improves the Device controller by adding proper error handling for maintenance operations, reducing unnecessary reconciliations triggered by Secret metadata changes, and removing unused ConfigMap informers. Additionally, it fixes the defer pattern used across all "brick" controllers to ensure both metadata and status are correctly updated after reconciliation.

Please refer to the individual commit messages for detailed explanations of each change.

NOTE: Please rebase-merge to keep the trail of changes incl. their reasoning.

@felix-kaestner felix-kaestner requested a review from a team as a code owner February 18, 2026 21:52
@hardikdr hardikdr added the area/metal-automation Automation processes within the Metal project. label Feb 19, 2026
@hardikdr hardikdr added this to Roadmap Feb 19, 2026
@felix-kaestner felix-kaestner force-pushed the refactor/device branch 3 times, most recently from 827f71c to d969ac6 Compare February 20, 2026 13:36
This patch removes the informers for ConfigMap resources on the Device
controller as they were not used anymore.
This patch changes the predicate to filter events for Secret resource
updates to trigger a reconciliation of a Device resource to only apply
when the generation of the Secret is updated. This will only happen when
the contained secret data is updated and thus the generation is changed.
Previously this also applied to resource version updates, which meant
that changing metadata on the referenced secrets would trigger a
reconciliation of the Device.
This patch improves error handling in the Device controller's maintenance
reconciliation by setting the Ready condition to false with a
MaintenanceFailedReason when maintenance operations fail. Warning events
are now emitted for reboot, factory reset, and reprovision failures,
providing better observability into maintenance operation status.
This patch makes minor improvements to the Device controller:
- Remove unnecessary deletion of maintenance annotation in Provisioning phase
- Add explicit return after transitioning from Provisioned to Running phase
- Fix comment capitalization for consistency
This patch fixes the defer function pattern used to update metadata and
status after reconciliation in all controllers. Previously, the return
statement after patching metadata prevented the status from being updated
when both had changed. Now, both metadata and status are always patched
when they differ from the original.

Additionally, obj.DeepCopy() is now passed to Patch() for metadata updates
to prevent the Patch() call from modifying obj and interfering with the
subsequent status update.
Fixes Vulnerability GO-2026-4394
@github-actions
Copy link

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/ironcore-dev/network-operator/api/core/v1alpha1 0.00% (ø)
github.com/ironcore-dev/network-operator/internal/controller/cisco/nx 64.27% (-0.21%) 👎
github.com/ironcore-dev/network-operator/internal/controller/core 66.48% (-0.39%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/ironcore-dev/network-operator/api/core/v1alpha1/device_types.go 0.00% (ø) 0 0 0
github.com/ironcore-dev/network-operator/api/core/v1alpha1/groupversion_info.go 0.00% (ø) 0 0 0
github.com/ironcore-dev/network-operator/internal/controller/cisco/nx/bordergateway_controller.go 51.63% (-0.22%) 215 (-1) 111 (-1) 104 👎
github.com/ironcore-dev/network-operator/internal/controller/cisco/nx/system_controller.go 65.26% (-0.36%) 95 (-1) 62 (-1) 33 👎
github.com/ironcore-dev/network-operator/internal/controller/cisco/nx/vpcdomain_controller.go 77.07% (-0.11%) 205 (-1) 158 (-1) 47 👎
github.com/ironcore-dev/network-operator/internal/controller/core/acl_controller.go 64.08% (-0.35%) 103 (-1) 66 (-1) 37 👎
github.com/ironcore-dev/network-operator/internal/controller/core/banner_controller.go 62.60% (-0.28%) 131 (-1) 82 (-1) 49 👎
github.com/ironcore-dev/network-operator/internal/controller/core/bgp_controller.go 64.08% (-0.35%) 103 (-1) 66 (-1) 37 👎
github.com/ironcore-dev/network-operator/internal/controller/core/bgp_peer_controller.go 72.14% (-0.20%) 140 (-1) 101 (-1) 39 👎
github.com/ironcore-dev/network-operator/internal/controller/core/certificate_controller.go 63.25% (-0.31%) 117 (-1) 74 (-1) 43 👎
github.com/ironcore-dev/network-operator/internal/controller/core/device_controller.go 65.67% (-1.47%) 201 (-9) 132 (-9) 69 👎
github.com/ironcore-dev/network-operator/internal/controller/core/dns_controller.go 64.00% (-0.36%) 100 (-1) 64 (-1) 36 👎
github.com/ironcore-dev/network-operator/internal/controller/core/evpninstance_controller.go 74.12% (-0.15%) 170 (-1) 126 (-1) 44 👎
github.com/ironcore-dev/network-operator/internal/controller/core/interface_controller.go 74.73% (-0.60%) 372 (-1) 278 (-3) 94 (+2) 👎
github.com/ironcore-dev/network-operator/internal/controller/core/isis_controller.go 60.71% (-0.35%) 112 (-1) 68 (-1) 44 👎
github.com/ironcore-dev/network-operator/internal/controller/core/managementaccess_controller.go 56.41% (-0.37%) 117 (-1) 66 (-1) 51 👎
github.com/ironcore-dev/network-operator/internal/controller/core/ntp_controller.go 64.00% (-0.36%) 100 (-1) 64 (-1) 36 👎
github.com/ironcore-dev/network-operator/internal/controller/core/nve_controller.go 67.84% (-0.16%) 199 (-1) 135 (-1) 64 👎
github.com/ironcore-dev/network-operator/internal/controller/core/ospf_controller.go 59.44% (-0.28%) 143 (-1) 85 (-1) 58 👎
github.com/ironcore-dev/network-operator/internal/controller/core/pim_controller.go 60.71% (-0.35%) 112 (-1) 68 (-1) 44 👎
github.com/ironcore-dev/network-operator/internal/controller/core/prefixset_controller.go 68.93% (-0.30%) 103 (-1) 71 (-1) 32 👎
github.com/ironcore-dev/network-operator/internal/controller/core/routingpolicy_controller.go 71.90% (-0.18%) 153 (-1) 110 (-1) 43 👎
github.com/ironcore-dev/network-operator/internal/controller/core/snmp_controller.go 64.00% (-0.36%) 100 (-1) 64 (-1) 36 👎
github.com/ironcore-dev/network-operator/internal/controller/core/syslog_controller.go 64.08% (-0.35%) 103 (-1) 66 (-1) 37 👎
github.com/ironcore-dev/network-operator/internal/controller/core/user_controller.go 61.07% (-0.29%) 131 (-1) 80 (-1) 51 👎
github.com/ironcore-dev/network-operator/internal/controller/core/vlan_controller.go 67.26% (-0.29%) 113 (-1) 76 (-1) 37 👎
github.com/ironcore-dev/network-operator/internal/controller/core/vrf_controller.go 67.62% (-0.31%) 105 (-1) 71 (-1) 34 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/ironcore-dev/network-operator/internal/controller/core/device_controller_test.go

@nikatza nikatza merged commit 689d0f5 into main Feb 25, 2026
11 checks passed
@nikatza nikatza deleted the refactor/device branch February 25, 2026 16:13
@github-project-automation github-project-automation bot moved this to Done in Roadmap Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/metal-automation Automation processes within the Metal project.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants