From 9f371946efb1765094439f5d966b8f0e93e10ad3 Mon Sep 17 00:00:00 2001 From: Axel Christ Date: Mon, 11 Sep 2023 13:07:49 +0200 Subject: [PATCH] Fix metalnet nic state parsing --- metalnetlet/controllers/conversion.go | 13 +++++++++++ .../networkinterface_controller.go | 1 + .../networkinterface_controller_test.go | 22 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/metalnetlet/controllers/conversion.go b/metalnetlet/controllers/conversion.go index 635832e8..ac2b0f9b 100644 --- a/metalnetlet/controllers/conversion.go +++ b/metalnetlet/controllers/conversion.go @@ -54,6 +54,19 @@ func ipsIPFamilies(ips []net.IP) []corev1.IPFamily { return utilslices.Map(ips, net.IP.Family) } +func metalnetNetworkInterfaceStateToNetworkInterfaceStatus(mStatus metalnetv1alpha1.NetworkInterfaceState) v1alpha1.NetworkInterfaceState { + switch mStatus { + case metalnetv1alpha1.NetworkInterfaceStatePending: + return v1alpha1.NetworkInterfaceStatePending + case metalnetv1alpha1.NetworkInterfaceStateReady: + return v1alpha1.NetworkInterfaceStateReady + case metalnetv1alpha1.NetworkInterfaceStateError: + return v1alpha1.NetworkInterfaceStateError + default: + return v1alpha1.NetworkInterfaceStatePending + } +} + func metalnetIPToIP(ip metalnetv1alpha1.IP) net.IP { return net.IP{Addr: ip.Addr} } diff --git a/metalnetlet/controllers/networkinterface_controller.go b/metalnetlet/controllers/networkinterface_controller.go index 8fc69973..b089d24f 100644 --- a/metalnetlet/controllers/networkinterface_controller.go +++ b/metalnetlet/controllers/networkinterface_controller.go @@ -233,6 +233,7 @@ func (r *NetworkInterfaceReconciler) updateStatus( metalnetNic *metalnetv1alpha1.NetworkInterface, ) error { base := nic.DeepCopy() + nic.Status.State = metalnetNetworkInterfaceStateToNetworkInterfaceStatus(metalnetNic.Status.State) if pciAddr := metalnetNic.Status.PCIAddress; pciAddr != nil { nic.Status.PCIAddress = &v1alpha1.PCIAddress{ Domain: pciAddr.Domain, diff --git a/metalnetlet/controllers/networkinterface_controller_test.go b/metalnetlet/controllers/networkinterface_controller_test.go index 4a9741f8..b7ca8e19 100644 --- a/metalnetlet/controllers/networkinterface_controller_test.go +++ b/metalnetlet/controllers/networkinterface_controller_test.go @@ -75,6 +75,28 @@ var _ = Describe("NetworkInterfaceController", func() { NodeName: &metalnetNode.Name, })) + By("updating the metalnet network interface's status") + Eventually(UpdateStatus(metalnetNic, func() { + metalnetNic.Status.State = metalnetv1alpha1.NetworkInterfaceStateReady + metalnetNic.Status.PCIAddress = &metalnetv1alpha1.PCIAddress{ + Domain: "06", + Bus: "0000", + Slot: "3", + Function: "00", + } + })).Should(Succeed()) + + By("waiting for the network interface to reflect the status values") + Eventually(Object(nic)).Should(HaveField("Status", v1alpha1.NetworkInterfaceStatus{ + State: v1alpha1.NetworkInterfaceStateReady, + PCIAddress: &v1alpha1.PCIAddress{ + Domain: "06", + Bus: "0000", + Slot: "3", + Function: "00", + }, + })) + By("deleting the network interface") Expect(k8sClient.Delete(ctx, nic)).To(Succeed())