Merge pull request #81091 from Huang-Wei/fix-FakeFilterPlugin-face

Fix a racing issue in FakeFilterPlugin
This commit is contained in:
Kubernetes Prow Robot 2019-08-08 07:59:45 -07:00 committed by GitHub
commit 314aa4f959
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -142,7 +143,7 @@ var emptyFramework, _ = framework.NewFramework(EmptyPluginRegistry, nil, []sched
// FakeFilterPlugin is a test filter plugin used by default scheduler. // FakeFilterPlugin is a test filter plugin used by default scheduler.
type FakeFilterPlugin struct { type FakeFilterPlugin struct {
numFilterCalled int numFilterCalled int32
failFilter bool failFilter bool
} }
@ -162,7 +163,7 @@ func (fp *FakeFilterPlugin) reset() {
// Filter is a test function that returns an error or nil, depending on the // Filter is a test function that returns an error or nil, depending on the
// value of "failFilter". // value of "failFilter".
func (fp *FakeFilterPlugin) Filter(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status { func (fp *FakeFilterPlugin) Filter(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
fp.numFilterCalled++ atomic.AddInt32(&fp.numFilterCalled, 1)
if fp.failFilter { if fp.failFilter {
return framework.NewStatus(framework.Unschedulable, fmt.Sprintf("injecting failure for pod %v", pod.Name)) return framework.NewStatus(framework.Unschedulable, fmt.Sprintf("injecting failure for pod %v", pod.Name))
@ -171,7 +172,7 @@ func (fp *FakeFilterPlugin) Filter(pc *framework.PluginContext, pod *v1.Pod, nod
return nil return nil
} }
// NewFilterPlugin is the factory for filtler plugin. // NewFilterPlugin is the factory for filter plugin.
func NewFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { func NewFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return filterPlugin, nil return filterPlugin, nil
} }