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

cherry-pick: don't include terminated nodes in budget (#1735) #1736

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions pkg/controllers/disruption/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ func BuildDisruptionBudgets(ctx context.Context, cluster *state.Cluster, clk clo
continue
}

// Additionally, don't consider nodeclaims that have the terminating condition. A nodeclaim should have
// the Terminating condition only when the node is drained and cloudprovider.Delete() was successful
// on the underlying cloud provider machine.
if node.NodeClaim.StatusConditions().Get(v1.ConditionTypeInstanceTerminating).IsTrue() {
continue
}

nodePool := node.Labels()[v1.NodePoolLabelKey]
numNodes[nodePool]++

Expand Down
32 changes: 32 additions & 0 deletions pkg/controllers/disruption/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,38 @@ var _ = Describe("BuildDisruptionBudgetMapping", func() {
Expect(budgets[nodePool.Name][reason]).To(Equal(10))
}
})
It("should not consider nodes that have the terminating status condition as part of disruption count", func() {
nodePool.Spec.Disruption.Budgets = []v1.Budget{{Nodes: "100%"}}
ExpectApplied(ctx, env.Client, nodePool)
nodeClaim, node := test.NodeClaimAndNode(v1.NodeClaim{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{"karpenter.sh/test-finalizer"},
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"),
},
},
})
nodeClaim.StatusConditions().SetTrue(v1.ConditionTypeInstanceTerminating)
ExpectApplied(ctx, env.Client, nodeClaim, node)
ExpectReconcileSucceeded(ctx, nodeStateController, client.ObjectKeyFromObject(node))
ExpectReconcileSucceeded(ctx, nodeClaimStateController, client.ObjectKeyFromObject(nodeClaim))

budgets, err := disruption.BuildDisruptionBudgets(ctx, cluster, fakeClock, env.Client, recorder)
Expect(err).To(Succeed())
// This should not bring in the terminating node.
for _, reason := range v1.WellKnownDisruptionReasons {
Expect(budgets[nodePool.Name][reason]).To(Equal(10))
}
})
It("should not return a negative disruption value", func() {
nodePool.Spec.Disruption.Budgets = []v1.Budget{{Nodes: "10%"}}
ExpectApplied(ctx, env.Client, nodePool)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/state/statenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ func (in *StateNode) PodLimits() corev1.ResourceList {
func (in *StateNode) MarkedForDeletion() bool {
// The Node is marked for deletion if:
// 1. The Node has MarkedForDeletion set
// 2. The Node has a NodeClaim counterpart and is actively deleting
// 2. The Node has a NodeClaim counterpart and is actively deleting (or the nodeclaim is marked as terminating)
// 3. The Node has no NodeClaim counterpart and is actively deleting
return in.markedForDeletion ||
(in.NodeClaim != nil && !in.NodeClaim.DeletionTimestamp.IsZero()) ||
(in.NodeClaim != nil && (!in.NodeClaim.DeletionTimestamp.IsZero() || in.NodeClaim.StatusConditions().Get(v1.ConditionTypeInstanceTerminating).IsTrue())) ||
(in.Node != nil && in.NodeClaim == nil && !in.Node.DeletionTimestamp.IsZero())
}

Expand Down
Loading