mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #84766 from Huang-Wei/tbe-flake
Fix a TaintBasedEviction integration test flake
This commit is contained in:
commit
ee309ced7e
@ -733,6 +733,34 @@ func TestTaintBasedEvictions(t *testing.T) {
|
||||
t.Errorf("Failed to create node, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Regularly send heartbeat event to APIServer so that the cluster doesn't enter fullyDisruption mode.
|
||||
// TODO(Huang-Wei): use "NodeDisruptionExclusion" feature to simply the below logic when it's beta.
|
||||
var heartbeatChans []chan struct{}
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
heartbeatChans = append(heartbeatChans, make(chan struct{}))
|
||||
}
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
// Spin up <nodeCount> goroutines to send heartbeat event to APIServer periodically.
|
||||
go func(i int) {
|
||||
for {
|
||||
select {
|
||||
case <-heartbeatChans[i]:
|
||||
return
|
||||
case <-time.Tick(2 * time.Second):
|
||||
nodes[i].Status.Conditions = []v1.NodeCondition{
|
||||
{
|
||||
Type: v1.NodeReady,
|
||||
Status: v1.ConditionTrue,
|
||||
LastHeartbeatTime: metav1.Now(),
|
||||
},
|
||||
}
|
||||
updateNodeStatus(cs, nodes[i])
|
||||
}
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
neededNode := nodes[1]
|
||||
if test.pod != nil {
|
||||
test.pod.Name = fmt.Sprintf("testpod-%d", i)
|
||||
@ -759,6 +787,13 @@ func TestTaintBasedEvictions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
// Stop the neededNode's heartbeat goroutine.
|
||||
if neededNode.Name == fmt.Sprintf("node-%d", i) {
|
||||
heartbeatChans[i] <- struct{}{}
|
||||
break
|
||||
}
|
||||
}
|
||||
neededNode.Status.Conditions = test.nodeConditions
|
||||
// Update node condition.
|
||||
err = updateNodeStatus(cs, neededNode)
|
||||
@ -788,6 +823,10 @@ func TestTaintBasedEvictions(t *testing.T) {
|
||||
}
|
||||
cleanupPods(cs, t, []*v1.Pod{test.pod})
|
||||
}
|
||||
// Close all heartbeat channels.
|
||||
for i := 0; i < nodeCount; i++ {
|
||||
close(heartbeatChans[i])
|
||||
}
|
||||
cleanupNodes(cs, t)
|
||||
waitForSchedulerCacheCleanup(context.scheduler, t)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user