-
Notifications
You must be signed in to change notification settings - Fork 385
perf: Refactor the eviction queue to be multithreaded #2252
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
Changes from 8 commits
062e604
b66a6c2
f456b13
76ccad5
4873fcb
7ab99b9
afa8667
68ff59f
51b3df7
3ac4431
a9e06fc
cb55f4a
f11cdc0
718e558
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ var _ = BeforeSuite(func() { | |
|
|
||
| cloudProvider = fake.NewCloudProvider() | ||
| recorder = test.NewEventRecorder() | ||
| queue = terminator.NewTestingQueue(env.Client, recorder) | ||
| queue = terminator.NewQueue(env.Client, recorder) | ||
| terminationController = termination.NewController(fakeClock, env.Client, cloudProvider, terminator.NewTerminator(fakeClock, env.Client, queue, recorder), recorder) | ||
| }) | ||
|
|
||
|
|
@@ -86,7 +86,7 @@ var _ = Describe("Termination", func() { | |
| BeforeEach(func() { | ||
| fakeClock.SetTime(time.Now()) | ||
| cloudProvider.Reset() | ||
| *queue = lo.FromPtr(terminator.NewTestingQueue(env.Client, recorder)) | ||
| *queue = lo.FromPtr(terminator.NewQueue(env.Client, recorder)) | ||
|
|
||
| nodePool = test.NodePool() | ||
| nodeClaim, node = test.NodeClaimAndNode(v1.NodeClaim{ObjectMeta: metav1.ObjectMeta{Finalizers: []string{v1.TerminationFinalizer}}}) | ||
|
|
@@ -208,8 +208,11 @@ var _ = Describe("Termination", func() { | |
| ExpectApplied(ctx, env.Client, node, nodeClaim, pod, pdb) | ||
| ExpectManualBinding(ctx, env.Client, pod, node) | ||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
|
|
||
| // We only reconcile once since this label should be applied before draining the node | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| _ = ExpectObjectReconcileFailed(ctx, env.Client, queue, pod) | ||
|
|
||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| Expect(node.Labels[corev1.LabelNodeExcludeBalancers]).Should(Equal("karpenter")) | ||
| }) | ||
|
|
@@ -225,9 +228,10 @@ var _ = Describe("Termination", func() { | |
| // Trigger Termination Controller | ||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
|
|
||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| Expect(queue.Has(node, podSkip)).To(BeFalse()) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(queue.Has(podSkip)).To(BeFalse()) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, podEvict) | ||
|
|
||
| // Expect node to exist and be draining | ||
| ExpectNodeWithNodeClaimDraining(env.Client, node.Name) | ||
|
|
@@ -256,9 +260,10 @@ var _ = Describe("Termination", func() { | |
| // Trigger Termination Controller | ||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
|
|
||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| Expect(queue.Has(node, podSkip)).To(BeFalse()) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(queue.Has(podSkip)).To(BeFalse()) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, podEvict) | ||
|
|
||
| // Expect node to exist and be draining | ||
| ExpectNodeWithNodeClaimDraining(env.Client, node.Name) | ||
|
|
@@ -267,7 +272,7 @@ var _ = Describe("Termination", func() { | |
| EventuallyExpectTerminating(ctx, env.Client, podEvict) | ||
| ExpectDeleted(ctx, env.Client, podEvict) | ||
|
|
||
| Expect(queue.Has(node, podSkip)).To(BeFalse()) | ||
| Expect(queue.Has(podSkip)).To(BeFalse()) | ||
|
|
||
| // Reconcile to delete node | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
|
|
@@ -289,7 +294,7 @@ var _ = Describe("Termination", func() { | |
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, podEvict) | ||
|
|
||
| // Expect node to exist and be draining | ||
| ExpectNodeWithNodeClaimDraining(env.Client, node.Name) | ||
|
|
@@ -317,8 +322,9 @@ var _ = Describe("Termination", func() { | |
| ExpectApplied(ctx, env.Client, node, nodeClaim, pod) | ||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
|
|
||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pod) | ||
|
|
||
| // Expect pod with no owner ref to be enqueued for eviction | ||
| EventuallyExpectTerminating(ctx, env.Client, pod) | ||
|
|
@@ -385,13 +391,13 @@ var _ = Describe("Termination", func() { | |
| ExpectNodeWithNodeClaimDraining(env.Client, node.Name) | ||
|
|
||
| // Expect podNoEvict to be added to the queue | ||
| Expect(queue.Has(node, podNoEvict)).To(BeTrue()) | ||
| Expect(queue.Has(podNoEvict)).To(BeTrue()) | ||
|
|
||
| // Attempt to evict the pod, but fail to do so | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| _ = ExpectObjectReconcileFailed(ctx, env.Client, queue, podNoEvict) | ||
|
|
||
| // Expect podNoEvict to fail eviction due to PDB, and be retried | ||
| Expect(queue.Has(node, podNoEvict)).To(BeTrue()) | ||
| Expect(queue.Has(podNoEvict)).To(BeTrue()) | ||
|
|
||
| // Delete pod to simulate successful eviction | ||
| ExpectDeleted(ctx, env.Client, podNoEvict) | ||
|
|
@@ -452,16 +458,16 @@ var _ = Describe("Termination", func() { | |
| } | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) | ||
| ExpectNodeWithNodeClaimDraining(env.Client, node.Name) | ||
| for range podGroup { | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| for _, pod := range podGroup { | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pod) | ||
| } | ||
| // Start draining the pod group, but don't complete it yet | ||
| EventuallyExpectTerminating(ctx, env.Client, lo.Map(podGroup, func(p *corev1.Pod, _ int) client.Object { return p })...) | ||
|
|
||
| // Look at the next pod group and ensure that none of the pods have started terminating on it | ||
| if i != len(podGroups)-1 { | ||
| for range podGroups[i+1] { | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| for _, pod := range podGroups[i+1] { | ||
| Expect(queue.Has(pod)).To(BeFalse()) | ||
DerekFrank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| ConsistentlyExpectNotTerminating(ctx, env.Client, lo.Map(podGroups[i+1], func(p *corev1.Pod, _ int) client.Object { return p })...) | ||
| } | ||
|
|
@@ -487,8 +493,9 @@ var _ = Describe("Termination", func() { | |
| // Trigger Termination Controller | ||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
|
|
||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation (non-critical) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, podEvict) | ||
|
|
||
| // Expect node to exist and be draining | ||
| ExpectNodeWithNodeClaimDraining(env.Client, node.Name) | ||
|
|
@@ -500,8 +507,8 @@ var _ = Describe("Termination", func() { | |
| // Expect the critical pods to be evicted and deleted | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation (critical) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, podNodeCritical) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, podClusterCritical) | ||
|
|
||
| EventuallyExpectTerminating(ctx, env.Client, podNodeCritical, podClusterCritical) | ||
| ExpectDeleted(ctx, env.Client, podNodeCritical) | ||
|
|
@@ -535,10 +542,10 @@ var _ = Describe("Termination", func() { | |
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, podEvict) | ||
|
|
||
| // Expect mirror pod to not be queued for eviction | ||
| Expect(queue.Has(node, podNoEvict)).To(BeFalse()) | ||
| Expect(queue.Has(podNoEvict)).To(BeFalse()) | ||
|
|
||
| // Expect podEvict to be enqueued for eviction then be successful | ||
| EventuallyExpectTerminating(ctx, env.Client, podEvict) | ||
|
|
@@ -566,8 +573,8 @@ var _ = Describe("Termination", func() { | |
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pods[0]) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pods[1]) | ||
|
|
||
| nodeClaim = ExpectExists(ctx, env.Client, nodeClaim) | ||
| Expect(nodeClaim.StatusConditions().Get(v1.ConditionTypeDrained).IsUnknown()).To(BeTrue()) | ||
|
|
@@ -614,8 +621,8 @@ var _ = Describe("Termination", func() { | |
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pods[0]) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pods[1]) | ||
|
|
||
| // Expect the pods to be evicted | ||
| EventuallyExpectTerminating(ctx, env.Client, pods[0], pods[1]) | ||
|
|
@@ -644,8 +651,8 @@ var _ = Describe("Termination", func() { | |
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pods[0]) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pods[1]) | ||
|
|
||
| // Expect the pods to be evicted | ||
| EventuallyExpectTerminating(ctx, env.Client, pods[0], pods[1]) | ||
|
|
@@ -675,7 +682,8 @@ var _ = Describe("Termination", func() { | |
| // Before grace period, node should not delete | ||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pod) | ||
|
|
||
| ExpectNodeExists(ctx, env.Client, node.Name) | ||
| EventuallyExpectTerminating(ctx, env.Client, pod) | ||
|
|
||
|
|
@@ -720,7 +728,7 @@ var _ = Describe("Termination", func() { | |
| ExpectNotFound(ctx, env.Client, node) | ||
|
|
||
| // Expect that the old pod's key still exists in the queue | ||
| Expect(queue.Has(node, pod)).To(BeTrue()) | ||
| Expect(queue.Has(pod)).To(BeTrue()) | ||
|
|
||
| // Re-create the pod and node, it should now have the same name, but a different UUID | ||
| node = test.Node(test.NodeOptions{ | ||
|
|
@@ -738,7 +746,8 @@ var _ = Describe("Termination", func() { | |
| ExpectApplied(ctx, env.Client, node, pod) | ||
|
|
||
| // Trigger eviction queue with the pod key still in it | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(queue.Has(pod)).To(BeTrue()) | ||
| queue.Add(pod) | ||
|
||
|
|
||
| Consistently(func(g Gomega) { | ||
| g.Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(pod), pod)).To(Succeed()) | ||
|
|
@@ -764,6 +773,8 @@ var _ = Describe("Termination", func() { | |
|
|
||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // DrainInitiation | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pod) | ||
|
|
||
| ExpectNodeExists(ctx, env.Client, node.Name) | ||
| pod = ExpectExists(ctx, env.Client, pod) | ||
| Expect(pod.DeletionTimestamp.IsZero()).To(BeFalse()) | ||
|
|
@@ -798,8 +809,9 @@ var _ = Describe("Termination", func() { | |
| // The pod should be deleted 60 seconds before the node's TGP expires | ||
| fakeClock.Step(175 * time.Second) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) | ||
| pod = ExpectExists(ctx, env.Client, pod) | ||
| Expect(pod.DeletionTimestamp.IsZero()).To(BeFalse()) | ||
| ExpectObjectReconciled(ctx, env.Client, queue, pod) | ||
| ExpectDeleted(ctx, env.Client, pod) | ||
|
||
|
|
||
| }) | ||
| Context("VolumeAttachments", func() { | ||
| It("should wait for volume attachments", func() { | ||
|
|
@@ -944,29 +956,6 @@ var _ = Describe("Termination", func() { | |
| Expect(ok).To(BeTrue()) | ||
| Expect(lo.FromPtr(m.GetHistogram().SampleCount)).To(BeNumerically("==", 1)) | ||
| }) | ||
| It("should update the eviction queueDepth metric when reconciling pods", func() { | ||
DerekFrank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| minAvailable := intstr.FromInt32(0) | ||
| labelSelector := map[string]string{test.RandomName(): test.RandomName()} | ||
| pdb := test.PodDisruptionBudget(test.PDBOptions{ | ||
| Labels: labelSelector, | ||
| // Don't let any pod evict | ||
| MinAvailable: &minAvailable, | ||
| }) | ||
| ExpectApplied(ctx, env.Client, pdb, node, nodeClaim) | ||
| pods := test.Pods(5, test.PodOptions{NodeName: node.Name, ObjectMeta: metav1.ObjectMeta{ | ||
| OwnerReferences: defaultOwnerRefs, | ||
| Labels: labelSelector, | ||
| }}) | ||
| ExpectApplied(ctx, env.Client, lo.Map(pods, func(p *corev1.Pod, _ int) client.Object { return p })...) | ||
|
|
||
| wqDepthBefore, _ := FindMetricWithLabelValues("workqueue_adds_total", map[string]string{"name": "eviction.workqueue"}) | ||
| Expect(env.Client.Delete(ctx, node)).To(Succeed()) | ||
| node = ExpectNodeExists(ctx, env.Client, node.Name) | ||
| ExpectRequeued(ExpectObjectReconciled(ctx, env.Client, terminationController, node)) // Drain | ||
| wqDepthAfter, ok := FindMetricWithLabelValues("workqueue_adds_total", map[string]string{"name": "eviction.workqueue"}) | ||
| Expect(ok).To(BeTrue()) | ||
| Expect(lo.FromPtr(wqDepthAfter.GetCounter().Value) - lo.FromPtr(wqDepthBefore.GetCounter().Value)).To(BeNumerically("==", 5)) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.