diff --git a/pkg/controllers/node/suite_test.go b/pkg/controllers/node/suite_test.go index 2a89e79b121a..76125ff5da80 100644 --- a/pkg/controllers/node/suite_test.go +++ b/pkg/controllers/node/suite_test.go @@ -79,18 +79,18 @@ var _ = Describe("Controller", func() { v1alpha5.ProvisionerNameLabelKey: provisioner.Name, }, }) - ExpectCreated(env.Client, provisioner, n) + ExpectCreated(ctx, env.Client, provisioner, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeTrue()) }) It("should ignore nodes without a provisioner", func() { n := test.Node(test.NodeOptions{Finalizers: []string{v1alpha5.TerminationFinalizer}}) - ExpectCreated(env.Client, provisioner, n) + ExpectCreated(ctx, env.Client, provisioner, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeTrue()) }) It("should delete nodes after expiry", func() { @@ -101,11 +101,11 @@ var _ = Describe("Controller", func() { v1alpha5.ProvisionerNameLabelKey: provisioner.Name, }, }) - ExpectCreated(env.Client, provisioner, n) + ExpectCreated(ctx, env.Client, provisioner, n) // Should still exist ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeTrue()) // Simulate time passing @@ -113,7 +113,7 @@ var _ = Describe("Controller", func() { return time.Now().Add(time.Duration(*provisioner.Spec.TTLSecondsUntilExpired) * time.Second) } ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeFalse()) }) }) @@ -128,11 +128,11 @@ var _ = Describe("Controller", func() { {Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule}, }, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Spec.Taints).To(Equal(n.Spec.Taints)) }) It("should remove the readiness taint if ready", func() { @@ -144,11 +144,11 @@ var _ = Describe("Controller", func() { {Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule}, }, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Spec.Taints).ToNot(Equal([]v1.Taint{n.Spec.Taints[1]})) }) It("should do nothing if ready and the readiness taint does not exist", func() { @@ -157,11 +157,11 @@ var _ = Describe("Controller", func() { Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name}, Taints: []v1.Taint{{Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule}}, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Spec.Taints).To(Equal(n.Spec.Taints)) }) It("should do nothing if not owned by a provisioner", func() { @@ -172,11 +172,11 @@ var _ = Describe("Controller", func() { {Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule}, }, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Spec.Taints).To(Equal(n.Spec.Taints)) }) }) @@ -188,20 +188,20 @@ var _ = Describe("Controller", func() { ReadyStatus: v1.ConditionUnknown, ReadyReason: "NodeStatusNeverUpdated", }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(provisioner)) // Expect node not be deleted - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeTrue()) // Simulate time passing and a n failing to join injectabletime.Now = func() time.Time { return time.Now().Add(node.LivenessTimeout) } ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeFalse()) }) It("should delete nodes if we never hear anything after 5 minutes", func() { @@ -211,19 +211,19 @@ var _ = Describe("Controller", func() { ReadyStatus: v1.ConditionUnknown, ReadyReason: "", }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(provisioner)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeTrue()) // Simulate time passing and a n failing to join injectabletime.Now = func() time.Time { return time.Now().Add(node.LivenessTimeout) } ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.DeletionTimestamp.IsZero()).To(BeFalse()) }) }) @@ -235,11 +235,11 @@ var _ = Describe("Controller", func() { ReadyStatus: v1.ConditionUnknown, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, node) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, node) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) Expect(node.Annotations).ToNot(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey)) }) It("should not TTL nodes that have ready status false", func() { @@ -249,11 +249,11 @@ var _ = Describe("Controller", func() { ReadyStatus: v1.ConditionFalse, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, node) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, node) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) Expect(node.Annotations).ToNot(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey)) }) It("should label nodes as underutilized and add TTL", func() { @@ -261,11 +261,11 @@ var _ = Describe("Controller", func() { node := test.Node(test.NodeOptions{ Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name}, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, node) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, node) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) Expect(node.Annotations).To(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey)) }) It("should remove labels from non-empty nodes", func() { @@ -276,9 +276,9 @@ var _ = Describe("Controller", func() { v1alpha5.EmptinessTimestampAnnotationKey: time.Now().Add(100 * time.Second).Format(time.RFC3339), }, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, node) - ExpectCreatedWithStatus(env.Client, test.Pod(test.PodOptions{ + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, node) + ExpectCreatedWithStatus(ctx, env.Client, test.Pod(test.PodOptions{ Name: strings.ToLower(randomdata.SillyName()), Namespace: provisioner.Namespace, NodeName: node.Name, @@ -286,7 +286,7 @@ var _ = Describe("Controller", func() { })) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) Expect(node.Annotations).ToNot(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey)) }) It("should delete empty nodes past their TTL", func() { @@ -298,10 +298,10 @@ var _ = Describe("Controller", func() { v1alpha5.EmptinessTimestampAnnotationKey: time.Now().Add(-100 * time.Second).Format(time.RFC3339), }, }) - ExpectCreated(env.Client, provisioner, node) + ExpectCreated(ctx, env.Client, provisioner, node) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) Expect(node.DeletionTimestamp.IsZero()).To(BeFalse()) }) }) @@ -311,11 +311,11 @@ var _ = Describe("Controller", func() { Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name}, Finalizers: []string{"fake.com/finalizer"}, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Finalizers).To(ConsistOf(n.Finalizers[0], v1alpha5.TerminationFinalizer)) }) It("should do nothing if terminating", func() { @@ -323,12 +323,12 @@ var _ = Describe("Controller", func() { Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name}, Finalizers: []string{"fake.com/finalizer"}, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) Expect(env.Client.Delete(ctx, n)).To(Succeed()) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Finalizers).To(Equal(n.Finalizers)) }) It("should do nothing if the termination finalizer already exists", func() { @@ -336,22 +336,22 @@ var _ = Describe("Controller", func() { Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name}, Finalizers: []string{v1alpha5.TerminationFinalizer, "fake.com/finalizer"}, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Finalizers).To(Equal(n.Finalizers)) }) It("should do nothing if the not owned by a provisioner", func() { n := test.Node(test.NodeOptions{ Finalizers: []string{"fake.com/finalizer"}, }) - ExpectCreated(env.Client, provisioner) - ExpectCreatedWithStatus(env.Client, n) + ExpectCreated(ctx, env.Client, provisioner) + ExpectCreatedWithStatus(ctx, env.Client, n) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n)) - n = ExpectNodeExists(env.Client, n.Name) + n = ExpectNodeExists(ctx, env.Client, n.Name) Expect(n.Finalizers).To(Equal(n.Finalizers)) }) }) diff --git a/pkg/controllers/provisioning/suite_test.go b/pkg/controllers/provisioning/suite_test.go index 95ab15c5f45a..c4b3df44408f 100644 --- a/pkg/controllers/provisioning/suite_test.go +++ b/pkg/controllers/provisioning/suite_test.go @@ -155,7 +155,7 @@ var _ = Describe("Provisioning", func() { }) Context("Daemonsets and Node Overhead", func() { It("should account for overhead", func() { - ExpectCreated(env.Client, test.DaemonSet( + ExpectCreated(ctx, env.Client, test.DaemonSet( test.DaemonSetOptions{PodOptions: test.PodOptions{ ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}}, }}, @@ -170,7 +170,7 @@ var _ = Describe("Provisioning", func() { Expect(*node.Status.Allocatable.Memory()).To(Equal(resource.MustParse("4Gi"))) }) It("should not schedule if overhead is too large", func() { - ExpectCreated(env.Client, test.DaemonSet( + ExpectCreated(ctx, env.Client, test.DaemonSet( test.DaemonSetOptions{PodOptions: test.PodOptions{ ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("10000"), v1.ResourceMemory: resource.MustParse("10000Gi")}}, }}, @@ -180,7 +180,7 @@ var _ = Describe("Provisioning", func() { }) It("should ignore daemonsets without matching tolerations", func() { provisioner.Spec.Taints = v1alpha5.Taints{{Key: "foo", Value: "bar", Effect: v1.TaintEffectNoSchedule}} - ExpectCreated(env.Client, test.DaemonSet( + ExpectCreated(ctx, env.Client, test.DaemonSet( test.DaemonSetOptions{PodOptions: test.PodOptions{ ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}}, }}, @@ -196,7 +196,7 @@ var _ = Describe("Provisioning", func() { Expect(*node.Status.Allocatable.Memory()).To(Equal(resource.MustParse("2Gi"))) }) It("should ignore daemonsets with an invalid selector", func() { - ExpectCreated(env.Client, test.DaemonSet( + ExpectCreated(ctx, env.Client, test.DaemonSet( test.DaemonSetOptions{PodOptions: test.PodOptions{ NodeSelector: map[string]string{"node": "invalid"}, ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}}, @@ -212,7 +212,7 @@ var _ = Describe("Provisioning", func() { Expect(*node.Status.Allocatable.Memory()).To(Equal(resource.MustParse("2Gi"))) }) It("should ignore daemonsets that don't match pod constraints", func() { - ExpectCreated(env.Client, test.DaemonSet( + ExpectCreated(ctx, env.Client, test.DaemonSet( test.DaemonSetOptions{PodOptions: test.PodOptions{ NodeRequirements: []v1.NodeSelectorRequirement{{Key: v1.LabelTopologyZone, Operator: v1.NodeSelectorOpIn, Values: []string{"test-zone-1"}}}, ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}}, @@ -244,7 +244,7 @@ var _ = Describe("Provisioning", func() { }) Context("Taints", func() { It("should apply unready taints", func() { - ExpectCreated(env.Client, provisioner) + ExpectCreated(ctx, env.Client, provisioner) for _, pod := range ExpectProvisioned(ctx, env.Client, scheduler, provisioners, provisioner, test.UnschedulablePod()) { node := ExpectScheduled(ctx, env.Client, pod) Expect(node.Spec.Taints).To(ContainElement(v1.Taint{Key: v1alpha5.NotReadyTaintKey, Effect: v1.TaintEffectNoSchedule})) diff --git a/pkg/controllers/scheduling/suite_test.go b/pkg/controllers/scheduling/suite_test.go index 88fd7fd4d66b..c176a8751a90 100644 --- a/pkg/controllers/scheduling/suite_test.go +++ b/pkg/controllers/scheduling/suite_test.go @@ -463,7 +463,7 @@ var _ = Describe("Topology", func() { firstNode := test.Node(test.NodeOptions{Labels: map[string]string{v1.LabelTopologyZone: "test-zone-1"}}) secondNode := test.Node(test.NodeOptions{Labels: map[string]string{v1.LabelTopologyZone: "test-zone-2"}}) thirdNode := test.Node(test.NodeOptions{}) // missing topology domain - ExpectCreated(env.Client, provisioner, firstNode, secondNode, thirdNode) + ExpectCreated(ctx, env.Client, provisioner, firstNode, secondNode, thirdNode) topology := []v1.TopologySpreadConstraint{{ TopologyKey: v1.LabelTopologyZone, WhenUnsatisfiable: v1.DoNotSchedule, diff --git a/pkg/controllers/termination/suite_test.go b/pkg/controllers/termination/suite_test.go index 78a7a2126454..915a5df6afa1 100644 --- a/pkg/controllers/termination/suite_test.go +++ b/pkg/controllers/termination/suite_test.go @@ -87,11 +87,11 @@ var _ = Describe("Termination", func() { Context("Reconciliation", func() { It("should delete nodes", func() { - ExpectCreated(env.Client, node) + ExpectCreated(ctx, env.Client, node) Expect(env.Client.Delete(ctx, node)).To(Succeed()) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - ExpectNotFound(env.Client, node) + ExpectNotFound(ctx, env.Client, node) }) It("should not evict pods that tolerate unschedulable taint", func() { podEvict := test.Pod(test.PodOptions{NodeName: node.Name}) @@ -99,11 +99,11 @@ var _ = Describe("Termination", func() { NodeName: node.Name, Tolerations: []v1.Toleration{{Key: v1.TaintNodeUnschedulable, Operator: v1.TolerationOpExists, Effect: v1.TaintEffectNoSchedule}}, }) - ExpectCreated(env.Client, node, podEvict, podSkip) + ExpectCreated(ctx, env.Client, node, podEvict, podSkip) // Trigger Termination Controller Expect(env.Client.Delete(ctx, node)).To(Succeed()) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) // Expect podEvict to be enqueued for eviction @@ -117,9 +117,9 @@ var _ = Describe("Termination", func() { ExpectDeleted(ctx, env.Client, podEvict) // Reconcile to delete node - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - ExpectNotFound(env.Client, node) + ExpectNotFound(ctx, env.Client, node) }) It("should not delete nodes that have a do-not-evict pod", func() { podEvict := test.Pod(test.PodOptions{NodeName: node.Name}) @@ -128,10 +128,10 @@ var _ = Describe("Termination", func() { Annotations: map[string]string{v1alpha5.DoNotEvictPodAnnotationKey: "true"}, }) - ExpectCreated(env.Client, node, podEvict, podNoEvict) + ExpectCreated(ctx, env.Client, node, podEvict, podNoEvict) Expect(env.Client.Delete(ctx, node)).To(Succeed()) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) // Expect no pod to be enqueued for eviction @@ -144,7 +144,7 @@ var _ = Describe("Termination", func() { ExpectDeleted(ctx, env.Client, podNoEvict) // Reconcile node to evict pod - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) // Expect podEvict to be enqueued for eviction then be successful @@ -155,9 +155,9 @@ var _ = Describe("Termination", func() { ExpectDeleted(ctx, env.Client, podEvict) // Reconcile to delete node - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - ExpectNotFound(env.Client, node) + ExpectNotFound(ctx, env.Client, node) }) It("should fail to evict pods that violate a PDB", func() { minAvailable := intstr.FromInt(1) @@ -172,11 +172,11 @@ var _ = Describe("Termination", func() { Labels: labelSelector, }) - ExpectCreated(env.Client, node, podNoEvict, pdb) + ExpectCreated(ctx, env.Client, node, podNoEvict, pdb) // Trigger Termination Controller Expect(env.Client.Delete(ctx, node)).To(Succeed()) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) // Expect the pod to be enqueued for eviction @@ -192,55 +192,55 @@ var _ = Describe("Termination", func() { ExpectDeleted(ctx, env.Client, podNoEvict) // Reconcile to delete node - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - ExpectNotFound(env.Client, node) + ExpectNotFound(ctx, env.Client, node) }) It("should not delete nodes until all pods are deleted", func() { pods := []*v1.Pod{test.Pod(test.PodOptions{NodeName: node.Name}), test.Pod(test.PodOptions{NodeName: node.Name})} - ExpectCreated(env.Client, node, pods[0], pods[1]) + ExpectCreated(ctx, env.Client, node, pods[0], pods[1]) // Trigger Termination Controller Expect(env.Client.Delete(ctx, node)).To(Succeed()) - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) // Expect the pod to be enqueued for eviction ExpectEnqueuedForEviction(evictionQueue, pods[0], pods[1]) // Expect node to exist and be draining, but not deleted - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) ExpectNodeDraining(env.Client, node.Name) ExpectDeleted(ctx, env.Client, pods[1]) // Expect node to exist and be draining, but not deleted - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) ExpectNodeDraining(env.Client, node.Name) ExpectDeleted(ctx, env.Client, pods[0]) // Reconcile to delete node - node = ExpectNodeExists(env.Client, node.Name) + node = ExpectNodeExists(ctx, env.Client, node.Name) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - ExpectNotFound(env.Client, node) + ExpectNotFound(ctx, env.Client, node) }) It("should wait for pods to terminate", func() { pod := test.Pod(test.PodOptions{NodeName: node.Name}) - ExpectCreated(env.Client, node, pod) + ExpectCreated(ctx, env.Client, node, pod) // Before grace period, node should not delete Expect(env.Client.Delete(ctx, node)).To(Succeed()) ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - ExpectNodeExists(env.Client, node.Name) + ExpectNodeExists(ctx, env.Client, node.Name) ExpectEvicted(env.Client, pod) // After grace period, node should delete injectabletime.Now = func() time.Time { return time.Now().Add(30 * time.Second) } ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node)) - ExpectNotFound(env.Client, node) + ExpectNotFound(ctx, env.Client, node) }) }) }) @@ -260,7 +260,7 @@ func ExpectNotEnqueuedForEviction(e *termination.EvictionQueue, pods ...*v1.Pod) func ExpectEvicted(c client.Client, pods ...*v1.Pod) { for _, pod := range pods { Eventually(func() bool { - return ExpectPodExists(c, pod.Name, pod.Namespace).GetDeletionTimestamp().IsZero() + return ExpectPodExists(ctx, c, pod.Name, pod.Namespace).GetDeletionTimestamp().IsZero() }, ReconcilerPropagationTime, RequestInterval).Should(BeFalse(), func() string { return fmt.Sprintf("expected %s/%s to be evicting, but it isn't", pod.Namespace, pod.Name) }) @@ -268,7 +268,7 @@ func ExpectEvicted(c client.Client, pods ...*v1.Pod) { } func ExpectNodeDraining(c client.Client, nodeName string) *v1.Node { - node := ExpectNodeExists(c, nodeName) + node := ExpectNodeExists(ctx, c, nodeName) Expect(node.Spec.Unschedulable).To(BeTrue()) Expect(functional.ContainsString(node.Finalizers, v1alpha5.TerminationFinalizer)).To(BeTrue()) Expect(node.DeletionTimestamp.IsZero()).To(BeFalse()) diff --git a/pkg/test/expectations/expectations.go b/pkg/test/expectations/expectations.go index cdad7a36c35c..6023526be53d 100644 --- a/pkg/test/expectations/expectations.go +++ b/pkg/test/expectations/expectations.go @@ -41,19 +41,19 @@ const ( RequestInterval = 1 * time.Second ) -func ExpectPodExists(c client.Client, name string, namespace string) *v1.Pod { +func ExpectPodExists(ctx context.Context, c client.Client, name string, namespace string) *v1.Pod { pod := &v1.Pod{} Expect(c.Get(context.Background(), client.ObjectKey{Name: name, Namespace: namespace}, pod)).To(Succeed()) return pod } -func ExpectNodeExists(c client.Client, name string) *v1.Node { +func ExpectNodeExists(ctx context.Context, c client.Client, name string) *v1.Node { node := &v1.Node{} Expect(c.Get(context.Background(), client.ObjectKey{Name: name}, node)).To(Succeed()) return node } -func ExpectNotFound(c client.Client, objects ...client.Object) { +func ExpectNotFound(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { Eventually(func() bool { return errors.IsNotFound(c.Get(context.Background(), types.NamespacedName{Name: object.GetName(), Namespace: object.GetNamespace()}, object)) @@ -64,17 +64,17 @@ func ExpectNotFound(c client.Client, objects ...client.Object) { } func ExpectScheduled(ctx context.Context, c client.Client, pod *v1.Pod) *v1.Node { - p := ExpectPodExists(c, pod.Name, pod.Namespace) + p := ExpectPodExists(ctx, c, pod.Name, pod.Namespace) Expect(p.Spec.NodeName).ToNot(BeEmpty(), fmt.Sprintf("expected %s/%s to be scheduled", pod.Namespace, pod.Name)) - return ExpectNodeExists(c, p.Spec.NodeName) + return ExpectNodeExists(ctx, c, p.Spec.NodeName) } func ExpectNotScheduled(ctx context.Context, c client.Client, pod *v1.Pod) { - p := ExpectPodExists(c, pod.Name, pod.Namespace) + p := ExpectPodExists(ctx, c, pod.Name, pod.Namespace) Eventually(p.Spec.NodeName).Should(BeEmpty(), fmt.Sprintf("expected %s/%s to not be scheduled", pod.Namespace, pod.Name)) } -func ExpectApplied(c client.Client, objects ...client.Object) { +func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { if object.GetResourceVersion() == "" { Expect(c.Create(context.Background(), object)).To(Succeed()) @@ -84,23 +84,23 @@ func ExpectApplied(c client.Client, objects ...client.Object) { } } -func ExpectStatusUpdated(c client.Client, objects ...client.Object) { +func ExpectStatusUpdated(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { Expect(c.Status().Update(context.Background(), object)).To(Succeed()) } } -func ExpectCreated(c client.Client, objects ...client.Object) { +func ExpectCreated(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { Expect(c.Create(context.Background(), object)).To(Succeed()) } } -func ExpectCreatedWithStatus(c client.Client, objects ...client.Object) { +func ExpectCreatedWithStatus(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { // Preserve a copy of the status, which is overriden by create status := object.DeepCopyObject().(client.Object) - ExpectApplied(c, object) + ExpectApplied(ctx, c, object) Expect(c.Status().Update(context.Background(), status)).To(Succeed()) } } @@ -115,7 +115,7 @@ func ExpectDeleted(ctx context.Context, c client.Client, objects ...client.Objec } } for _, object := range objects { - ExpectNotFound(c, object) + ExpectNotFound(ctx, c, object) } } @@ -159,10 +159,10 @@ func ExpectProvisioningCleanedUp(ctx context.Context, c client.Client, controlle func ExpectProvisioned(ctx context.Context, c client.Client, scheduler *scheduling.Controller, provisioners *provisioning.Controller, provisioner *v1alpha5.Provisioner, pods ...*v1.Pod) (result []*v1.Pod) { // Persist objects - ExpectApplied(c, provisioner) - ExpectStatusUpdated(c, provisioner) + ExpectApplied(ctx, c, provisioner) + ExpectStatusUpdated(ctx, c, provisioner) for _, pod := range pods { - ExpectCreatedWithStatus(c, pod) + ExpectCreatedWithStatus(ctx, c, pod) } // Wait for reconcile ExpectReconcileSucceeded(ctx, provisioners, client.ObjectKeyFromObject(provisioner)) @@ -177,7 +177,7 @@ func ExpectProvisioned(ctx context.Context, c client.Client, scheduler *scheduli wg.Wait() // Return updated pods for _, pod := range pods { - result = append(result, ExpectPodExists(c, pod.GetName(), pod.GetNamespace())) + result = append(result, ExpectPodExists(ctx, c, pod.GetName(), pod.GetNamespace())) } return result }