Skip to content

Commit be35045

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

File tree

4 files changed

+62
-16
lines changed

4 files changed

+62
-16
lines changed

bmc/redfish_kube.go

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

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: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,59 @@ 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).Error(err, "Invalid IP address, skipping", "interface", s.Name, "ip", ipAddr)
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
}
834-
server.Status.NetworkInterfaces = nics
835879

880+
server.Status.NetworkInterfaces = nics
836881
if err := r.Status().Patch(ctx, server, client.MergeFrom(serverBase)); err != nil {
837882
return false, fmt.Errorf("failed to patch server status: %w", err)
838883
}

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)