Skip to content

Commit

Permalink
internal/machine-controller fix flakes in phases test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi authored and k8s-infra-cherrypick-robot committed May 2, 2023
1 parent a0da0a6 commit ad63320
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions internal/controllers/machine/machine_controller_phases_test.go
Expand Up @@ -213,12 +213,12 @@ func TestReconcileMachinePhases(t *testing.T) {

g.Expect(env.Create(ctx, bootstrapConfig)).To(Succeed())
g.Expect(env.Create(ctx, infraMachine)).To(Succeed())
// We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
preUpdate := time.Now().Add(-2 * time.Second)
g.Expect(env.Create(ctx, machine)).To(Succeed())

// Set the LastUpdated to be able to verify it is updated when the phase changes
modifiedMachine := machine.DeepCopy()
lastUpdated := metav1.NewTime(time.Now().Add(-10 * time.Second))
machine.Status.LastUpdated = &lastUpdated
g.Expect(env.Status().Patch(ctx, modifiedMachine, client.MergeFrom(machine))).To(Succeed())

// Set bootstrap ready.
Expand All @@ -235,7 +235,7 @@ func TestReconcileMachinePhases(t *testing.T) {
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseProvisioning))
// Verify that the LastUpdated timestamp was updated
g.Expect(machine.Status.LastUpdated).NotTo(BeNil())
g.Expect(machine.Status.LastUpdated.After(lastUpdated.Time)).To(BeTrue())
g.Expect(machine.Status.LastUpdated.After(preUpdate)).To(BeTrue())
return true
}, 10*time.Second).Should(BeTrue())
})
Expand Down Expand Up @@ -281,14 +281,13 @@ func TestReconcileMachinePhases(t *testing.T) {

g.Expect(env.Create(ctx, bootstrapConfig)).To(Succeed())
g.Expect(env.Create(ctx, infraMachine)).To(Succeed())
// We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
preUpdate := time.Now().Add(-2 * time.Second)
g.Expect(env.Create(ctx, machine)).To(Succeed())

modifiedMachine := machine.DeepCopy()
// Set NodeRef.
machine.Status.NodeRef = &corev1.ObjectReference{Kind: "Node", Name: node.Name}
// Set the LastUpdated to be able to verify it is updated when the phase changes
lastUpdated := metav1.NewTime(time.Now().Add(-10 * time.Second))
machine.Status.LastUpdated = &lastUpdated
g.Expect(env.Status().Patch(ctx, modifiedMachine, client.MergeFrom(machine))).To(Succeed())

// Set bootstrap ready.
Expand Down Expand Up @@ -322,7 +321,7 @@ func TestReconcileMachinePhases(t *testing.T) {
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseRunning))
// Verify that the LastUpdated timestamp was updated
g.Expect(machine.Status.LastUpdated).NotTo(BeNil())
g.Expect(machine.Status.LastUpdated.After(lastUpdated.Time)).To(BeTrue())
g.Expect(machine.Status.LastUpdated.After(preUpdate)).To(BeTrue())
return true
}, 10*time.Second).Should(BeTrue())
})
Expand Down Expand Up @@ -441,14 +440,13 @@ func TestReconcileMachinePhases(t *testing.T) {

g.Expect(env.Create(ctx, bootstrapConfig)).To(Succeed())
g.Expect(env.Create(ctx, infraMachine)).To(Succeed())
// We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
preUpdate := time.Now().Add(-2 * time.Second)
g.Expect(env.Create(ctx, machine)).To(Succeed())

modifiedMachine := machine.DeepCopy()
// Set NodeRef.
machine.Status.NodeRef = &corev1.ObjectReference{Kind: "Node", Name: node.Name}
// Set the LastUpdated to be able to verify it is updated when the phase changes
lastUpdated := metav1.NewTime(time.Now().Add(-10 * time.Second))
machine.Status.LastUpdated = &lastUpdated
g.Expect(env.Status().Patch(ctx, modifiedMachine, client.MergeFrom(machine))).To(Succeed())

// Set bootstrap ready.
Expand All @@ -470,7 +468,7 @@ func TestReconcileMachinePhases(t *testing.T) {
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseRunning))
// Verify that the LastUpdated timestamp was updated
g.Expect(machine.Status.LastUpdated).NotTo(BeNil())
g.Expect(machine.Status.LastUpdated.After(lastUpdated.Time)).To(BeTrue())
g.Expect(machine.Status.LastUpdated.After(preUpdate)).To(BeTrue())
return true
}, 10*time.Second).Should(BeTrue())
})
Expand Down Expand Up @@ -573,6 +571,8 @@ func TestReconcileMachinePhases(t *testing.T) {

g.Expect(env.Create(ctx, bootstrapConfig)).To(Succeed())
g.Expect(env.Create(ctx, infraMachine)).To(Succeed())
// We have to subtract 2 seconds, because .status.lastUpdated does not contain miliseconds.
preUpdate := time.Now().Add(-2 * time.Second)
g.Expect(env.Create(ctx, machine)).To(Succeed())

// Set bootstrap ready.
Expand All @@ -597,9 +597,6 @@ func TestReconcileMachinePhases(t *testing.T) {
modifiedMachine := machine.DeepCopy()
// Set NodeRef.
machine.Status.NodeRef = &corev1.ObjectReference{Kind: "Node", Name: node.Name}
// Set the LastUpdated to be able to verify it is updated when the phase changes
lastUpdated := metav1.NewTime(time.Now().Add(-10 * time.Second))
machine.Status.LastUpdated = &lastUpdated
g.Expect(env.Status().Patch(ctx, modifiedMachine, client.MergeFrom(machine))).To(Succeed())

modifiedMachine = machine.DeepCopy()
Expand All @@ -621,7 +618,7 @@ func TestReconcileMachinePhases(t *testing.T) {
g.Expect(nodeHealthyCondition.Reason).To(Equal(clusterv1.DeletingReason))
// Verify that the LastUpdated timestamp was updated
g.Expect(machine.Status.LastUpdated).NotTo(BeNil())
g.Expect(machine.Status.LastUpdated.After(lastUpdated.Time)).To(BeTrue())
g.Expect(machine.Status.LastUpdated.After(preUpdate)).To(BeTrue())
return true
}, 10*time.Second).Should(BeTrue())
})
Expand Down

0 comments on commit ad63320

Please sign in to comment.