Skip to content

Update metalnet load balancers on instance updates#487

Merged
afritzler merged 1 commit intomainfrom
fix/metalnet-instance-updates
Apr 22, 2026
Merged

Update metalnet load balancers on instance updates#487
afritzler merged 1 commit intomainfrom
fix/metalnet-instance-updates

Conversation

@adracus
Copy link
Copy Markdown
Contributor

@adracus adracus commented Apr 22, 2026

Fix missing updates metalnet load balancers when the desired spec via an instance does not match the current metalnet load balancer spec.

Add test case verifying this behavior.

Summary by CodeRabbit

  • Bug Fixes

    • Improved load balancer configuration synchronization when instance specifications are updated.
  • Tests

    • Enhanced test coverage for instance updates with multiple load balancer ports.

Fix missing updates metalnet load balancers when the desired spec via an
instance does not match the current metalnet load balancer spec.

Add test case verifying this behavior.
@adracus adracus requested a review from afritzler April 22, 2026 08:42
@adracus adracus requested a review from a team as a code owner April 22, 2026 08:42
@github-actions github-actions Bot added bug Something isn't working size/L labels Apr 22, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

This change adds semantic equality support for Metalnet API types and implements logic to update existing Metalnet load balancers when their specifications differ from desired values during instance reconciliation. The controller now compares current vs. desired specs and applies patches when changes are detected.

Changes

Cohort / File(s) Summary
Equality Support
metalnetlet/controllers/common.go
Introduced MetalnetEqualities package variable and AddFuncs function to register custom equality functions for metalnetv1alpha1.IP and metalnetv1alpha1.IPPrefix types, extending equality machinery for Metalnet API types.
Load Balancer Reconciliation
metalnetlet/controllers/instance_controller.go
Refactored LoadBalancerSpec construction into a centralized metalnetLoadBalancerSpec helper and added updateMetalnetLoadBalancerIfNecessary to conditionally patch existing Metalnet load balancers when their specs differ from desired state.
Test Verification
metalnetlet/controllers/instance_controller_test.go
Extended reconciliation test with an additional phase that mutates an Instance by appending a LoadBalancerPort and verifies that the corresponding Metalnet LoadBalancer resources reflect the updated port specifications.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

bug, size/S, area/networking

Suggested reviewers

  • afritzler
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 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.
Description check ❓ Inconclusive The description addresses the key issue and adds test verification, but does not follow the required template structure with 'Proposed Changes' and 'Fixes #' sections. Restructure the description to match the template with 'Proposed Changes' bullet points and include the issue number in 'Fixes #' format.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: updating metalnet load balancers when instances are updated.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/metalnet-instance-updates

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@metalnetlet/controllers/instance_controller_test.go`:
- Around line 63-69: The update callback passed to Eventually(Update(...)) must
be idempotent: replace the append mutation with a direct assignment to
inst.Spec.LoadBalancerPorts using the full desired slice (e.g.
inst.Spec.LoadBalancerPorts = []v1alpha1.LoadBalancerPort{ { Protocol:
&protocol, Port: 1001 } }) so retries won't duplicate port 1001; update the
callback that currently calls append to assign the slice instead, keeping the
same types (v1alpha1.LoadBalancerPort) and values.

In `@metalnetlet/controllers/instance_controller.go`:
- Around line 155-166: The current updateMetalnetLoadBalancerIfNecessary builds
desiredSpec from the existing metalnetLoadBalancer state, preventing drift
detection for NetworkRef, NodeName and LBtype; change
updateMetalnetLoadBalancerIfNecessary to accept the current desired inputs
(e.g., networkUID types.UID, metalnetNodeName string, metalnetLoadBalancerType
metalnetv1alpha1.LoadBalancerType, and the matched ip) and call
r.metalnetLoadBalancerSpec(inst, networkUID, metalnetNodeName,
metalnetLoadBalancerType, ip) so desiredSpec is derived from current Instance
inputs; then update the caller manageMetalnetLoadBalancers to pass those current
values when invoking updateMetalnetLoadBalancerIfNecessary (also fix the
analogous call/site referenced at the other location).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1814388e-c141-4bcc-97c6-768b409ceece

📥 Commits

Reviewing files that changed from the base of the PR and between b4864c5 and f1160ef.

📒 Files selected for processing (3)
  • metalnetlet/controllers/common.go
  • metalnetlet/controllers/instance_controller.go
  • metalnetlet/controllers/instance_controller_test.go

Comment thread metalnetlet/controllers/instance_controller_test.go
Comment thread metalnetlet/controllers/instance_controller.go
@afritzler afritzler merged commit 2229dae into main Apr 22, 2026
10 checks passed
@afritzler afritzler deleted the fix/metalnet-instance-updates branch April 22, 2026 08:50
@hardikdr hardikdr added the area/networking Networking-related tasks and improvements. label Apr 23, 2026
@hardikdr hardikdr added this to Roadmap Apr 23, 2026
@github-project-automation github-project-automation Bot moved this to Done in Roadmap Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking Networking-related tasks and improvements. bug Something isn't working size/L

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants