-
Notifications
You must be signed in to change notification settings - Fork 378
feat: prioritize emptiness over other consolidation methods #2180
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 2 commits
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 |
|---|---|---|
|
|
@@ -122,7 +122,7 @@ var _ = Describe("Drift", func() { | |
| ExpectApplied(ctx, env.Client, rs) | ||
| Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(rs), rs)).To(Succeed()) | ||
| }) | ||
| It("should allow all empty nodes to be disrupted", func() { | ||
| It("should not disrupt empty nodes during drift", func() { | ||
| nodeClaims, nodes = test.NodeClaimsAndNodes(numNodes, v1.NodeClaim{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Labels: map[string]string{ | ||
|
|
@@ -151,56 +151,18 @@ var _ = Describe("Drift", func() { | |
| ExpectMakeNodesAndNodeClaimsInitializedAndStateUpdated(ctx, env.Client, nodeStateController, nodeClaimStateController, nodes, nodeClaims) | ||
| ExpectSingletonReconciled(ctx, disruptionController) | ||
|
|
||
| metric, found := FindMetricWithLabelValues("karpenter_nodepools_allowed_disruptions", map[string]string{ | ||
| metric, found := FindMetricWithLabelValues("karpenter_voluntary_disruption_decisions_total", map[string]string{ | ||
| "nodepool": nodePool.Name, | ||
| "reason": string(v1.DisruptionReasonDrifted), | ||
| }) | ||
| Expect(found).To(BeTrue()) | ||
| Expect(metric.GetGauge().GetValue()).To(BeNumerically("==", 10)) | ||
|
|
||
| // Execute command, thus deleting all nodes | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(0)) | ||
| }) | ||
| It("should allow no empty nodes to be disrupted", func() { | ||
rschalo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| nodeClaims, nodes = test.NodeClaimsAndNodes(numNodes, v1.NodeClaim{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Labels: map[string]string{ | ||
| v1.NodePoolLabelKey: nodePool.Name, | ||
| corev1.LabelInstanceTypeStable: mostExpensiveInstance.Name, | ||
| v1.CapacityTypeLabelKey: mostExpensiveOffering.Requirements.Get(v1.CapacityTypeLabelKey).Any(), | ||
| corev1.LabelTopologyZone: mostExpensiveOffering.Requirements.Get(corev1.LabelTopologyZone).Any(), | ||
| }, | ||
| }, | ||
| Status: v1.NodeClaimStatus{ | ||
| Allocatable: map[corev1.ResourceName]resource.Quantity{ | ||
| corev1.ResourceCPU: resource.MustParse("32"), | ||
| corev1.ResourcePods: resource.MustParse("100"), | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| nodePool.Spec.Disruption.Budgets = []v1.Budget{{Nodes: "0%"}} | ||
|
|
||
| ExpectApplied(ctx, env.Client, nodePool) | ||
| for i := 0; i < numNodes; i++ { | ||
| nodeClaims[i].StatusConditions().SetTrue(v1.ConditionTypeDrifted) | ||
| ExpectApplied(ctx, env.Client, nodeClaims[i], nodes[i]) | ||
| } | ||
| // inform cluster state about nodes and nodeclaims | ||
| ExpectMakeNodesAndNodeClaimsInitializedAndStateUpdated(ctx, env.Client, nodeStateController, nodeClaimStateController, nodes, nodeClaims) | ||
| ExpectSingletonReconciled(ctx, disruptionController) | ||
|
|
||
| metric, found := FindMetricWithLabelValues("karpenter_nodepools_allowed_disruptions", map[string]string{ | ||
| "nodepool": nodePool.Name, | ||
| }) | ||
| Expect(found).To(BeTrue()) | ||
| Expect(found).To(BeFalse()) | ||
| Expect(metric.GetGauge().GetValue()).To(BeNumerically("==", 0)) | ||
|
|
||
| // Execute command, thus deleting no nodes | ||
| // Execute command, thus deleting all nodes | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(numNodes)) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(10)) | ||
| }) | ||
| It("should only allow 3 empty nodes to be disrupted", func() { | ||
| It("should only allow 3 nodes to be disrupted", func() { | ||
rschalo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| nodeClaims, nodes = test.NodeClaimsAndNodes(numNodes, v1.NodeClaim{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Labels: map[string]string{ | ||
|
|
@@ -234,9 +196,9 @@ var _ = Describe("Drift", func() { | |
| Expect(found).To(BeTrue()) | ||
| Expect(metric.GetGauge().GetValue()).To(BeNumerically("==", 3)) | ||
|
|
||
| // Execute command, thus deleting 3 nodes | ||
| // emptiness is not performed in drift, so expect all nodeclaims to exist | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(7)) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(10)) | ||
| }) | ||
| It("should disrupt 3 nodes, taking into account commands in progress", func() { | ||
| nodeClaims, nodes = test.NodeClaimsAndNodes(numNodes, v1.NodeClaim{ | ||
|
|
@@ -373,9 +335,9 @@ var _ = Describe("Drift", func() { | |
| Expect(metric.GetGauge().GetValue()).To(BeNumerically("==", 2)) | ||
| } | ||
|
|
||
| // Execute the command in the queue, only deleting 20 nodes | ||
| // emptiness is not performed in drift, so expect all nodeclaims to exist | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(10)) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(30)) | ||
| }) | ||
| It("should allow all nodes from each nodePool to be deleted", func() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would now happen in emptiness because the test used to have empty && drifted nodes. There is a test that covers disruptions across multiple nodepools. |
||
| // Create 10 nodepools | ||
|
|
@@ -434,9 +396,9 @@ var _ = Describe("Drift", func() { | |
| Expect(metric.GetGauge().GetValue()).To(BeNumerically("==", 3)) | ||
| } | ||
|
|
||
| // Execute the command in the queue, deleting all nodes | ||
| // emptiness is not performed in drift, so expect all nodeclaims to exist | ||
rschalo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ExpectSingletonReconciled(ctx, queue) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(0)) | ||
| Expect(len(ExpectNodeClaims(ctx, env.Client))).To(Equal(30)) | ||
| }) | ||
| }) | ||
| Context("Drift", func() { | ||
|
|
@@ -616,63 +578,6 @@ var _ = Describe("Drift", func() { | |
| Expect(ExpectNodeClaims(ctx, env.Client)).To(HaveLen(1)) | ||
| ExpectExists(ctx, env.Client, nodeClaim) | ||
| }) | ||
| It("can delete drifted nodes", func() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered by |
||
| ExpectApplied(ctx, env.Client, nodeClaim, node, nodePool) | ||
|
|
||
| // inform cluster state about nodes and nodeclaims | ||
| ExpectMakeNodesAndNodeClaimsInitializedAndStateUpdated(ctx, env.Client, nodeStateController, nodeClaimStateController, []*corev1.Node{node}, []*v1.NodeClaim{nodeClaim}) | ||
|
|
||
| fakeClock.Step(10 * time.Minute) | ||
| ExpectSingletonReconciled(ctx, disruptionController) | ||
| // Process the item so that the nodes can be deleted. | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| // Cascade any deletion of the nodeClaim to the node | ||
| ExpectNodeClaimsCascadeDeletion(ctx, env.Client, nodeClaim) | ||
|
|
||
| // We should delete the nodeClaim that has drifted | ||
| Expect(ExpectNodeClaims(ctx, env.Client)).To(HaveLen(0)) | ||
| Expect(ExpectNodes(ctx, env.Client)).To(HaveLen(0)) | ||
| ExpectNotFound(ctx, env.Client, nodeClaim, node) | ||
| }) | ||
| It("should disrupt all empty drifted nodes in parallel", func() { | ||
rschalo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| nodeClaims, nodes := test.NodeClaimsAndNodes(100, v1.NodeClaim{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Labels: map[string]string{ | ||
| v1.NodePoolLabelKey: nodePool.Name, | ||
| corev1.LabelInstanceTypeStable: mostExpensiveInstance.Name, | ||
| v1.CapacityTypeLabelKey: mostExpensiveOffering.Requirements.Get(v1.CapacityTypeLabelKey).Any(), | ||
| corev1.LabelTopologyZone: mostExpensiveOffering.Requirements.Get(corev1.LabelTopologyZone).Any(), | ||
| }, | ||
| }, | ||
| Status: v1.NodeClaimStatus{ | ||
| Allocatable: map[corev1.ResourceName]resource.Quantity{ | ||
| corev1.ResourceCPU: resource.MustParse("32"), | ||
| corev1.ResourcePods: resource.MustParse("100"), | ||
| }, | ||
| }, | ||
| }) | ||
| for _, m := range nodeClaims { | ||
| m.StatusConditions().SetTrue(v1.ConditionTypeDrifted) | ||
| ExpectApplied(ctx, env.Client, m) | ||
| } | ||
| for _, n := range nodes { | ||
| ExpectApplied(ctx, env.Client, n) | ||
| } | ||
| ExpectApplied(ctx, env.Client, nodePool) | ||
|
|
||
| // inform cluster state about nodes and nodeClaims | ||
| ExpectMakeNodesAndNodeClaimsInitializedAndStateUpdated(ctx, env.Client, nodeStateController, nodeClaimStateController, nodes, nodeClaims) | ||
| ExpectSingletonReconciled(ctx, disruptionController) | ||
|
|
||
| // Process the item so that the nodes can be deleted. | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| // Cascade any deletion of the nodeClaim to the node | ||
| ExpectNodeClaimsCascadeDeletion(ctx, env.Client, nodeClaims...) | ||
|
|
||
| // Expect that the drifted nodeClaims are gone | ||
| Expect(ExpectNodes(ctx, env.Client)).To(HaveLen(0)) | ||
| Expect(ExpectNodeClaims(ctx, env.Client)).To(HaveLen(0)) | ||
| }) | ||
| It("can replace drifted nodes", func() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered by new |
||
| labels := map[string]string{ | ||
| "app": "test", | ||
|
|
@@ -941,24 +846,5 @@ var _ = Describe("Drift", func() { | |
| ExpectExists(ctx, env.Client, nodeClaim) | ||
| ExpectExists(ctx, env.Client, node) | ||
| }) | ||
| It("should delete nodes with the karpenter.sh/do-not-disrupt annotation set to false", func() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to other annotation test in same file. |
||
| node.Annotations = lo.Assign(node.Annotations, map[string]string{v1.DoNotDisruptAnnotationKey: "false"}) | ||
| ExpectApplied(ctx, env.Client, nodeClaim, node, nodePool) | ||
|
|
||
| // inform cluster state about nodes and nodeclaims | ||
| ExpectMakeNodesAndNodeClaimsInitializedAndStateUpdated(ctx, env.Client, nodeStateController, nodeClaimStateController, []*corev1.Node{node}, []*v1.NodeClaim{nodeClaim}) | ||
|
|
||
| fakeClock.Step(10 * time.Minute) | ||
| ExpectSingletonReconciled(ctx, disruptionController) | ||
| // Process the item so that the nodes can be deleted. | ||
| ExpectSingletonReconciled(ctx, queue) | ||
| // Cascade any deletion of the nodeClaim to the node | ||
| ExpectNodeClaimsCascadeDeletion(ctx, env.Client, nodeClaim) | ||
|
|
||
| // We should delete the nodeClaim that has drifted | ||
| Expect(ExpectNodeClaims(ctx, env.Client)).To(HaveLen(0)) | ||
| Expect(ExpectNodes(ctx, env.Client)).To(HaveLen(0)) | ||
| ExpectNotFound(ctx, env.Client, nodeClaim, node) | ||
| }) | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.