Skip to content

Refactor controller reconcile signatures and add event-driven watches#300

Open
felix-kaestner wants to merge 1 commit intodevicefrom
refactor/controller
Open

Refactor controller reconcile signatures and add event-driven watches#300
felix-kaestner wants to merge 1 commit intodevicefrom
refactor/controller

Conversation

@felix-kaestner
Copy link
Copy Markdown
Contributor

@felix-kaestner felix-kaestner commented Apr 15, 2026

Consistently apply the following patterns across all controllers:

  • Change reconcile() return type from (ctrl.Result, error) to (error). Move the RequeueAfter result to the Reconcile() caller so reconcile() is only responsible for business logic, not requeue scheduling.

  • Remove the RequeueInterval field from ISIS, PIM, and VRF reconcilers (and the corresponding validation in SetupWithManager and wiring in cmd/main.go). These controllers now use proper watch triggers to reconcile based on referenced resource changes. Unlike controllers that track operational state (e.g. interface oper-status), these resources have no device-side operational state requiring periodic syncs.

  • Remove cached references from scope structs (e.g. Interfaces, VRF, PeerLink in lldpScope, dhcprelayScope, vpcdomainScope). Previously these fields were fetched and set in sub-reconciler functions, then read back in reconcile() through the scope. This is a poor pattern because: 1) the values never leave the reconcile() function scope and 2) they are absent from the scope when passed to finalize(), where a reader might assume they are populated. Use local variables within reconcile() instead.

  • Add Interface Watches to ISIS, OSPF, and PIM controllers that trigger reconciliation when a referenced Interface's Configured condition changes, replacing the previous poll-based requeue.

  • Align vpcdomain_controller with the rest of the codebase: rename import aliases (nxv1 to nxv1alpha1, corev1 to unaliased v1alpha1), replace meta.FindStatusCondition with conditions.Get in watch predicates, extract field indexer key strings into package-level constants, and remove the now unused conditionChanged helper.

  • Add kubebuilder default markers and a Reset() method to VPCDomainStatus instead of having a method on the reconciler.

@felix-kaestner felix-kaestner requested a review from a team as a code owner April 15, 2026 13:36
@felix-kaestner felix-kaestner force-pushed the refactor/events-api-group branch from 8faf1be to ed93b40 Compare April 16, 2026 07:29
@hardikdr hardikdr added the area/switch-automation Automation processes for network switch management and operations. label Apr 16, 2026
@hardikdr hardikdr added this to Roadmap Apr 16, 2026
Base automatically changed from refactor/events-api-group to main April 16, 2026 07:39
@github-actions github-actions bot added size/XXL and removed size/XL labels Apr 16, 2026
@felix-kaestner felix-kaestner changed the base branch from main to device April 16, 2026 08:23
Consistently apply the following patterns across all controllers:

- Change reconcile() return type from (ctrl.Result, error) to
  (error). Move the RequeueAfter result to the Reconcile() caller
  so reconcile() is only responsible for business logic, not
  requeue scheduling.

- Remove the RequeueInterval field from ISIS, PIM, and VRF
  reconcilers (and the corresponding validation in
  SetupWithManager and wiring in cmd/main.go). These controllers
  now use proper watch triggers to reconcile based on referenced
  resource changes. Unlike controllers that track operational
  state (e.g. interface oper-status), these resources have no
  device-side operational state requiring periodic syncs.

- Remove cached references from scope structs (e.g. Interfaces,
  VRF, PeerLink in lldpScope, dhcprelayScope, vpcdomainScope).
  Previously these fields were fetched and set in sub-reconciler
  functions, then read back in reconcile() through the scope.
  This pattern should be avoided because: 1) the values never leave the
  reconcile() function scope and 2) they are absent from the
  scope when passed to finalize(), where a reader might assume
  they are populated. Use local variables within reconcile()
  instead.

- Add Interface Watches to ISIS, OSPF, and PIM controllers that
  trigger reconciliation when a referenced Interface's Configured
  condition changes, replacing the previous poll-based requeue.

- Align vpcdomain_controller with the rest of the codebase:
  rename import aliases (nxv1 to nxv1alpha1, corev1 to
  unaliased v1alpha1), replace meta.FindStatusCondition with
  conditions.Get in watch predicates, extract field indexer key
  strings into package-level constants, and remove the now
  unused conditionChanged helper.

- Add kubebuilder default markers and a Reset() method to
  VPCDomainStatus instead of having a method on the reconciler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/switch-automation Automation processes for network switch management and operations. size/XL

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants