Skip to content

Commit f021362

Browse files
committed
add test for context deadline timeout
1 parent 43dfd0a commit f021362

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

pkg/controllers/disruption/suite_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,62 @@ var _ = Describe("Metrics", func() {
20222022
"consolidation_type": "multi",
20232023
})
20242024
})
2025+
It("should stop multi-node consolidation after context deadline is reached", func() {
2026+
nodeClaims, nodes = test.NodeClaimsAndNodes(3, v1.NodeClaim{
2027+
ObjectMeta: metav1.ObjectMeta{
2028+
Labels: map[string]string{
2029+
v1.NodePoolLabelKey: nodePool.Name,
2030+
corev1.LabelInstanceTypeStable: mostExpensiveInstance.Name,
2031+
v1.CapacityTypeLabelKey: mostExpensiveOffering.Requirements.Get(v1.CapacityTypeLabelKey).Any(),
2032+
corev1.LabelTopologyZone: mostExpensiveOffering.Requirements.Get(corev1.LabelTopologyZone).Any(),
2033+
},
2034+
},
2035+
Status: v1.NodeClaimStatus{
2036+
Allocatable: map[corev1.ResourceName]resource.Quantity{
2037+
corev1.ResourceCPU: resource.MustParse("32"),
2038+
corev1.ResourcePods: resource.MustParse("100"),
2039+
},
2040+
},
2041+
})
2042+
for _, nc := range nodeClaims {
2043+
nc.StatusConditions().SetTrue(v1.ConditionTypeConsolidatable)
2044+
}
2045+
// create our RS so we can link a pod to it
2046+
rs := test.ReplicaSet()
2047+
ExpectApplied(ctx, env.Client, rs)
2048+
pods := test.Pods(4, test.PodOptions{
2049+
ObjectMeta: metav1.ObjectMeta{Labels: labels,
2050+
OwnerReferences: []metav1.OwnerReference{
2051+
{
2052+
APIVersion: "apps/v1",
2053+
Kind: "ReplicaSet",
2054+
Name: rs.Name,
2055+
UID: rs.UID,
2056+
Controller: lo.ToPtr(true),
2057+
BlockOwnerDeletion: lo.ToPtr(true),
2058+
},
2059+
},
2060+
},
2061+
})
2062+
2063+
ExpectApplied(ctx, env.Client, rs, pods[0], pods[1], pods[2], pods[3], nodeClaims[0], nodes[0], nodeClaims[1], nodes[1], nodeClaims[2], nodes[2], nodePool)
2064+
2065+
// bind pods to nodes
2066+
ExpectManualBinding(ctx, env.Client, pods[0], nodes[0])
2067+
ExpectManualBinding(ctx, env.Client, pods[1], nodes[1])
2068+
ExpectManualBinding(ctx, env.Client, pods[2], nodes[2])
2069+
ExpectManualBinding(ctx, env.Client, pods[3], nodes[2])
2070+
2071+
// inform cluster state about nodes and nodeclaims
2072+
ExpectMakeNodesAndNodeClaimsInitializedAndStateUpdated(ctx, env.Client, nodeStateController, nodeClaimStateController, []*corev1.Node{nodes[0], nodes[1], nodes[2]}, []*v1.NodeClaim{nodeClaims[0], nodeClaims[1], nodeClaims[2]})
2073+
// create deadline in the past
2074+
deadlineCtx, cancel := context.WithDeadline(ctx, fakeClock.Now().Add(-disruption.MultiNodeConsolidationTimeoutDuration))
2075+
defer cancel()
2076+
2077+
ExpectSingletonReconciled(deadlineCtx, disruptionController)
2078+
// expect that due to timeout zero nodes were tainted in consolidation
2079+
ExpectTaintedNodeCount(ctx, env.Client, 0)
2080+
})
20252081
})
20262082

20272083
func leastExpensiveInstanceWithZone(zone string) *cloudprovider.InstanceType {

0 commit comments

Comments
 (0)