Merge pull request #93493 from Huang-Wei/flake-score

Fix integration test flake on TestScorePlugin
This commit is contained in:
Kubernetes Prow Robot 2020-07-27 22:35:10 -07:00 committed by GitHub
commit e79e352d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ package scheduler
import ( import (
"context" "context"
"fmt" "fmt"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -45,7 +46,7 @@ type PreFilterPlugin struct {
type ScorePlugin struct { type ScorePlugin struct {
failScore bool failScore bool
numScoreCalled int numScoreCalled int32
highScoreNode string highScoreNode string
} }
@ -170,13 +171,13 @@ func (sp *ScorePlugin) reset() {
// Score returns the score of scheduling a pod on a specific node. // Score returns the score of scheduling a pod on a specific node.
func (sp *ScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) { func (sp *ScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
sp.numScoreCalled++ curCalled := atomic.AddInt32(&sp.numScoreCalled, 1)
if sp.failScore { if sp.failScore {
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", p.Name)) return 0, framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", p.Name))
} }
score := int64(1) score := int64(1)
if sp.numScoreCalled == 1 { if curCalled == 1 {
// The first node is scored the highest, the rest is scored lower. // The first node is scored the highest, the rest is scored lower.
sp.highScoreNode = nodeName sp.highScoreNode = nodeName
score = framework.MaxNodeScore score = framework.MaxNodeScore