Skip to content

Commit

Permalink
Fix flapping IPs in NetworkInterface status (#1163)
Browse files Browse the repository at this point in the history
* fix flapping IPs in NetworkInterface status

* incorporating review comments

* incorporating review comments
  • Loading branch information
ushabelgur authored Nov 22, 2024
1 parent 3cb61f2 commit 9c991b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
const (
eventuallyTimeout = 3 * time.Second
pollingInterval = 50 * time.Millisecond
consistentlyDuration = 1 * time.Second
consistentlyDuration = 3 * time.Second
apiServiceTimeout = 5 * time.Minute

controllerManagerService = "controller-manager"
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ 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")),
HaveField("Status", MatchFields(IgnoreExtras, Fields{
Expand All @@ -309,6 +308,13 @@ var _ = Describe("MachineController", func() {
})),
))

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{
"Name": Equal("primary"),
Expand Down

0 comments on commit 9c991b5

Please sign in to comment.