Skip to content

Commit 8021fc5

Browse files
committed
Fix a TaintBasedEviction integration test flake
1 parent 53bb829 commit 8021fc5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/integration/scheduler/taint_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,34 @@ func TestTaintBasedEvictions(t *testing.T) {
733733
t.Errorf("Failed to create node, err: %v", err)
734734
}
735735
}
736+
737+
// Regularly send heartbeat event to APIServer so that the cluster doesn't enter fullyDisruption mode.
738+
// TODO(Huang-Wei): use "NodeDisruptionExclusion" feature to simply the below logic when it's beta.
739+
var heartbeatChans []chan struct{}
740+
for i := 0; i < nodeCount; i++ {
741+
heartbeatChans = append(heartbeatChans, make(chan struct{}))
742+
}
743+
for i := 0; i < nodeCount; i++ {
744+
// Spin up <nodeCount> goroutines to send heartbeat event to APIServer periodically.
745+
go func(i int) {
746+
for {
747+
select {
748+
case <-heartbeatChans[i]:
749+
return
750+
case <-time.Tick(2 * time.Second):
751+
nodes[i].Status.Conditions = []v1.NodeCondition{
752+
{
753+
Type: v1.NodeReady,
754+
Status: v1.ConditionTrue,
755+
LastHeartbeatTime: metav1.Now(),
756+
},
757+
}
758+
updateNodeStatus(cs, nodes[i])
759+
}
760+
}
761+
}(i)
762+
}
763+
736764
neededNode := nodes[1]
737765
if test.pod != nil {
738766
test.pod.Name = fmt.Sprintf("testpod-%d", i)
@@ -759,6 +787,13 @@ func TestTaintBasedEvictions(t *testing.T) {
759787
}
760788
}
761789

790+
for i := 0; i < nodeCount; i++ {
791+
// Stop the neededNode's heartbeat goroutine.
792+
if neededNode.Name == fmt.Sprintf("node-%d", i) {
793+
heartbeatChans[i] <- struct{}{}
794+
break
795+
}
796+
}
762797
neededNode.Status.Conditions = test.nodeConditions
763798
// Update node condition.
764799
err = updateNodeStatus(cs, neededNode)
@@ -788,6 +823,10 @@ func TestTaintBasedEvictions(t *testing.T) {
788823
}
789824
cleanupPods(cs, t, []*v1.Pod{test.pod})
790825
}
826+
// Close all heartbeat channels.
827+
for i := 0; i < nodeCount; i++ {
828+
close(heartbeatChans[i])
829+
}
791830
cleanupNodes(cs, t)
792831
waitForSchedulerCacheCleanup(context.scheduler, t)
793832
})

0 commit comments

Comments
 (0)