Skip to content

Commit

Permalink
fix flapping IPs in NetworkInterface status
Browse files Browse the repository at this point in the history
  • Loading branch information
ushabelgur committed Nov 19, 2024
1 parent 3217ad6 commit 35d01e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
16 changes: 10 additions & 6 deletions poollet/machinepoollet/controllers/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strconv"
"time"

Expand Down Expand Up @@ -542,17 +543,20 @@ func (r *MachineReconciler) updateNetworkInterfaceStatusFromIRIStatus(
return nil // nothing to do
}

nicBase := nic.DeepCopy()
nic.Status.IPs = commonv1alpha1.MustParseIPs(iriNicStatus.Ips...)
nic.Status.LastStateTransitionTime = &metav1.Time{Time: time.Now()}
nicState, ok := iriNetworkInterfaceStateToNetworkInterfaceState[iriNicStatus.State]
if !ok {
return fmt.Errorf("encountered unknown network interface state %s", iriNicStatus.State)
}
nic.Status.State = nicState

if err := r.Status().Patch(ctx, nic, client.MergeFrom(nicBase)); err != nil {
return fmt.Errorf("failed to patch network interface status: %w", err)
nicBase := nic.DeepCopy()
if nicBase.Status.State != nicState || !slices.Equal(nic.Status.IPs, commonv1alpha1.MustParseIPs(iriNicStatus.Ips...)) {
nic.Status.LastStateTransitionTime = &metav1.Time{Time: time.Now()}
nic.Status.IPs = commonv1alpha1.MustParseIPs(iriNicStatus.Ips...)
nic.Status.State = nicState

if err := r.Status().Patch(ctx, nic, client.MergeFrom(nicBase)); err != nil {
return fmt.Errorf("failed to patch network interface status: %w", err)
}
}

return nil
Expand Down
7 changes: 4 additions & 3 deletions poollet/machinepoollet/controllers/machine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ var _ = Describe("MachineController", func() {
srv.SetMachines([]*testingmachine.FakeMachine{iriMachine})

By("waiting for the ironcore network interface to have a provider id set")
Eventually(Object(nic)).Should(And(
HaveField("Spec.ProviderID", Equal("primary-handle")),
Eventually(Object(nic)).Should(HaveField("Spec.ProviderID", Equal("primary-handle")))

Consistently(Object(nic)).Should(
HaveField("Status", MatchFields(IgnoreExtras, Fields{
"State": Equal(networkingv1alpha1.NetworkInterfaceStateAvailable),
"IPs": ContainElement(commonv1alpha1.MustParseIP("10.0.0.1")),
})),
))
)

By("ensuring the ironcore machine status networkInterfaces to have correct NetworkInterfaceRef")
Eventually(Object(machine)).Should(HaveField("Status.NetworkInterfaces", ConsistOf(MatchFields(IgnoreExtras, Fields{
Expand Down

0 comments on commit 35d01e5

Please sign in to comment.