Skip to content

Add admin status to nic port#655

Merged
iljarotar merged 15 commits into
masterfrom
fix-downports-bug
Jul 15, 2026
Merged

Add admin status to nic port#655
iljarotar merged 15 commits into
masterfrom
fix-downports-bug

Conversation

@iljarotar

@iljarotar iljarotar commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description

The double-role of the Actual field of a switch port causes a bug in the metal-core that sometimes results in ports being set to DOWN by metal-core (metal-stack/metal-core#196).

A cleaner solution would include adding a table for the switch status and remove all status fields from the switch table. Then the reports coming from metal-core will only be reflected in the switch status table while the switch table would only hold the desired state of a switch. Once metal-core is migrated to v2API, we should work on this cleaner solution. For now, this quick solution is okay, I think.

TODO

  • Allow setting port status on ports that don't have a machine connection. Otherwise, this PR would make it impossible to add new machines on ports that were previously down.

@iljarotar
iljarotar requested a review from a team as a code owner June 26, 2026 11:37
@iljarotar
iljarotar requested a review from mwennrich June 26, 2026 11:37
@metal-robot metal-robot Bot added the area: control-plane Affects the metal-stack control-plane area. label Jun 26, 2026
@iljarotar
iljarotar marked this pull request as draft June 30, 2026 10:53
@iljarotar
iljarotar marked this pull request as ready for review July 3, 2026 14:52
@iljarotar
iljarotar marked this pull request as draft July 3, 2026 14:53
@iljarotar iljarotar moved this to In Progress in Development Jul 13, 2026

Copilot AI 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.

Pull request overview

This PR introduces an explicit administrative (desired) port status for switch NICs to avoid the current overloading of Actual, which can lead to metal-core incorrectly driving ports to DOWN. It also relaxes port-toggling behavior so ports without an attached machine can still be administratively enabled/disabled.

Changes:

  • Add admin_status to the switch NIC API model/spec to represent desired port state separately from actual.
  • Allow toggling a switch port even when no machine is connected to that NIC.
  • Adjust NicState desired/actual semantics and update related unit tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
spec/metal-api.json Adds admin_status to the OpenAPI schema for switch NICs (currently marked as required).
cmd/metal-api/internal/testdata/testdata.go Updates test fixtures for switch/machine connection scenarios.
cmd/metal-api/internal/service/v1/switch.go Adds AdminStatus field to the v1 SwitchNic API type.
cmd/metal-api/internal/service/switch-service.go Updates switch port toggle behavior and response mapping for admin_status.
cmd/metal-api/internal/service/switch-service_test.go Updates toggle-port tests to validate AdminStatus behavior and new 200 OK behavior for unconnected NICs.
cmd/metal-api/internal/metal/network.go Simplifies NicState state transitions to preserve Desired across SetState.
cmd/metal-api/internal/metal/network_test.go Updates unit tests to match new NicState transition semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/metal-api/internal/service/switch-service.go
Comment thread cmd/metal-api/internal/service/switch-service.go
Comment thread spec/metal-api.json
Comment thread cmd/metal-api/internal/service/v1/switch.go Outdated
Comment thread cmd/metal-api/internal/metal/network.go
r.sendError(request, response, httperrors.BadRequest(err))
return
}
r.log.Debug("toggle switch port", "request", requestPayload)
@ulrichSchreiner

Copy link
Copy Markdown
Contributor

LGTM, as it is much easier to store Actual/Desired state as-is and don't do a transition from one to the other state and vice versa.

let's hope it works :-)

mwennrich and others added 4 commits July 15, 2026 07:07
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@iljarotar
iljarotar marked this pull request as ready for review July 15, 2026 12:46
@iljarotar
iljarotar merged commit afae26f into master Jul 15, 2026
2 checks passed
@iljarotar
iljarotar deleted the fix-downports-bug branch July 15, 2026 12:46
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Development Jul 15, 2026
@majst01

majst01 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

This must be retrofitted into metal-apiserver an apiv2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: control-plane Affects the metal-stack control-plane area.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants