From 8021fc5a37a25f1cc229126c0a4e41cb9c4bf7cb Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Mon, 4 Nov 2019 16:20:28 -0800 Subject: [PATCH] Fix a TaintBasedEviction integration test flake --- test/integration/scheduler/taint_test.go | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/integration/scheduler/taint_test.go b/test/integration/scheduler/taint_test.go index 222612a5bf0..1fc76a95dbf 100644 --- a/test/integration/scheduler/taint_test.go +++ b/test/integration/scheduler/taint_test.go @@ -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 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) })