Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Use patch in tests instead of update #3231

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions controllers/machinehealthcheck_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,23 @@ var _ = Describe("MachineHealthCheck", func() {
Expect(testEnv.Create(ctx, machine)).To(Succeed())

node := node.DeepCopy()
nodeStatus := node.Status
Expect(testEnv.Create(ctx, node)).To(Succeed())
Expect(testEnv.Status().Update(ctx, node)).To(Succeed())
nodePatch := client.MergeFrom(node.DeepCopy())
node.Status = nodeStatus
Expect(testEnv.Status().Patch(ctx, node, nodePatch)).To(Succeed())
nodes = append(nodes, node)
detiber marked this conversation as resolved.
Show resolved Hide resolved

if nodeRef {
machinePatch := client.MergeFrom(machine.DeepCopy())
machine.Status = machineStatus
machine.Status.NodeRef = &corev1.ObjectReference{
Name: node.Name,
}

now := metav1.NewTime(time.Now())
machine.Status.LastUpdated = &now
Expect(testEnv.Status().Update(ctx, machine)).To(Succeed())
Expect(testEnv.Status().Patch(ctx, machine, machinePatch)).To(Succeed())
}

machines = append(machines, machine)
Expand Down Expand Up @@ -439,8 +443,9 @@ var _ = Describe("MachineHealthCheck", func() {

// Fake an earlier NodeStartupTimeout.
lastUpdatedTwiceNodeStartupTimeout := metav1.NewTime(time.Now().Add(-2 * mhc.Spec.NodeStartupTimeout.Duration))
machinePatch := client.MergeFrom(machines[2].DeepCopy())
machines[2].Status.LastUpdated = &lastUpdatedTwiceNodeStartupTimeout
Expect(testEnv.Status().Update(ctx, machines[2]))
Expect(testEnv.Status().Patch(ctx, machines[2], machinePatch))

// Make sure the status matches.
Eventually(func() *clusterv1.MachineHealthCheckStatus {
Expand Down Expand Up @@ -577,14 +582,15 @@ var _ = Describe("MachineHealthCheck", func() {

// Transition the node to unhealthy.
node := nodes[0]
nodePatch := client.MergeFrom(node.DeepCopy())
node.Status.Conditions = []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionUnknown,
LastTransitionTime: metav1.NewTime(time.Now().Add(-10 * time.Minute)),
},
}
Expect(testEnv.Status().Update(ctx, node)).To(Succeed())
Expect(testEnv.Status().Patch(ctx, node, nodePatch)).To(Succeed())

// Make sure the status matches.
Eventually(func() *clusterv1.MachineHealthCheckStatus {
Expand Down