Add admin status to nic port#655
Conversation
There was a problem hiding this comment.
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_statusto the switch NIC API model/spec to represent desired port state separately fromactual. - Allow toggling a switch port even when no machine is connected to that NIC.
- Adjust
NicStatedesired/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.
| r.sendError(request, response, httperrors.BadRequest(err)) | ||
| return | ||
| } | ||
| r.log.Debug("toggle switch port", "request", requestPayload) |
|
LGTM, as it is much easier to store let's hope it works :-) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
This must be retrofitted into metal-apiserver an apiv2 |
Description
The double-role of the
Actualfield 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