Skip to content

Commit bcc6740

Browse files
committed
internal: update networkInterfaces, add carrierState, ipv6 and neighbors
- add fields to registry - handle new registry fields and update crd
1 parent c9128e3 commit bcc6740

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
lines changed

bmc/redfish_kube.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (r *RedfishKubeBMC) SetPXEBootOnce(ctx context.Context, systemURI string) e
7171
if err := system.SetBoot(setBoot); err != nil {
7272
return fmt.Errorf("failed to set the boot order: %w", err)
7373
}
74-
netData := `{"networkInterfaces":[{"name":"dummy0","ipAddress":"127.0.0.2","macAddress":"aa:bb:cc:dd:ee:ff"}]`
74+
netData := `{"networkInterfaces":[{"name":"dummy0","ipAddresses":["127.0.0.2"],"macAddress":"aa:bb:cc:dd:ee:ff"}]`
7575
curlCmd := fmt.Sprintf(
7676
`apk add curl && curl -H 'Content-Type: application/json' \
7777
-d '{"SystemUUID":"%s","data":%s}}' \

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/siderolabs/go-smbios v0.3.3
1313
github.com/spf13/cobra v1.9.1
1414
github.com/stmcginnis/gofish v0.20.0
15+
github.com/stretchr/testify v1.10.0
1516
golang.org/x/crypto v0.42.0
1617
gopkg.in/yaml.v3 v3.0.1
1718
k8s.io/api v0.33.3
@@ -62,6 +63,7 @@ require (
6263
github.com/modern-go/reflect2 v1.0.2 // indirect
6364
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6465
github.com/pkg/errors v0.9.1 // indirect
66+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
6567
github.com/prometheus/client_golang v1.22.0 // indirect
6668
github.com/prometheus/client_model v0.6.2 // indirect
6769
github.com/prometheus/common v0.64.0 // indirect

internal/api/registry/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ package registry
66
// NetworkInterface represents a network interface on a server,
77
// including its IP and MAC addresses.
88
type NetworkInterface struct {
9-
Name string `json:"name"`
10-
IPAddress string `json:"ipAddress"`
11-
MACAddress string `json:"macAddress"`
9+
Name string `json:"name"`
10+
IpAddresses []string `json:"ipAddresses"`
11+
MACAddress string `json:"macAddress"`
12+
CarrierStatus string `json:"carrierStatus"`
1213
}
1314

1415
// Server represents a server with a list of network interfaces.

internal/controller/server_controller.go

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,61 @@ func (r *ServerReconciler) extractServerDetailsFromRegistry(ctx context.Context,
825825
// update network interfaces
826826
nics := make([]metalv1alpha1.NetworkInterface, 0, len(serverDetails.NetworkInterfaces))
827827
for _, s := range serverDetails.NetworkInterfaces {
828-
nics = append(nics, metalv1alpha1.NetworkInterface{
829-
Name: s.Name,
830-
IP: metalv1alpha1.MustParseIP(s.IPAddress),
831-
MACAddress: s.MACAddress,
832-
})
828+
nic := metalv1alpha1.NetworkInterface{
829+
Name: s.Name,
830+
MACAddress: s.MACAddress,
831+
CarrierStatus: s.CarrierStatus,
832+
}
833+
834+
// Process all IP addresses from the single IpAddresses slice
835+
var allIPs []metalv1alpha1.IP
836+
for _, ipAddr := range s.IpAddresses {
837+
if ipAddr != "" {
838+
// Parse and validate the IP address
839+
ip, err := metalv1alpha1.ParseIP(ipAddr)
840+
if err != nil {
841+
log.V(1).Info("Invalid IP address, skipping", "interface", s.Name, "ip", ipAddr, "error", err)
842+
continue
843+
}
844+
845+
// Add all valid IP addresses (both IPv4 and IPv6) to the slice
846+
allIPs = append(allIPs, ip)
847+
}
848+
}
849+
850+
// Set the IPs field with all collected IP addresses
851+
if len(allIPs) > 0 {
852+
nic.IPs = allIPs
853+
}
854+
855+
nics = append(nics, nic)
856+
}
857+
858+
// Merge LLDP neighbors into corresponding network interfaces
859+
for _, lldpIface := range serverDetails.LLDP {
860+
// Find the matching network interface by name
861+
for i := range nics {
862+
if nics[i].Name == lldpIface.InterfaceName {
863+
// Convert LLDP neighbors to the CRD format
864+
neighbors := make([]metalv1alpha1.LLDPNeighbor, 0, len(lldpIface.Neighbors))
865+
for _, neighbor := range lldpIface.Neighbors {
866+
neighbors = append(neighbors, metalv1alpha1.LLDPNeighbor{
867+
MACAddress: neighbor.ChassisID,
868+
PortID: neighbor.PortID,
869+
PortDescription: neighbor.PortDescription,
870+
SystemName: neighbor.SystemName,
871+
SystemDescription: neighbor.SystemDescription,
872+
})
873+
}
874+
nics[i].Neighbors = neighbors
875+
break
876+
}
877+
}
833878
}
879+
834880
server.Status.NetworkInterfaces = nics
835881

882+
log.V(1).Info("Found server information in registry", "nics", nics)
836883
if err := r.Status().Patch(ctx, server, client.MergeFrom(serverBase)); err != nil {
837884
return false, fmt.Errorf("failed to patch server status: %w", err)
838885
}

internal/registry/server_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ var _ = Describe("RegistryServer", func() {
2222
Data: registry.Server{
2323
NetworkInterfaces: []registry.NetworkInterface{
2424
{
25-
Name: "foo",
26-
IPAddress: "1.1.1.1",
27-
MACAddress: "abcd",
25+
Name: "foo",
26+
IpAddresses: []string{"1.1.1.1"},
27+
MACAddress: "abcd",
2828
},
2929
},
3030
},
@@ -48,9 +48,9 @@ var _ = Describe("RegistryServer", func() {
4848
Expect(server).To(Equal(&registry.Server{
4949
NetworkInterfaces: []registry.NetworkInterface{
5050
{
51-
Name: "foo",
52-
IPAddress: "1.1.1.1",
53-
MACAddress: "abcd",
51+
Name: "foo",
52+
IpAddresses: []string{"1.1.1.1"},
53+
MACAddress: "abcd",
5454
},
5555
},
5656
}))

0 commit comments

Comments
 (0)