mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Fix a racing issue in FakeFilterPlugin
Filter() is called simultaneously, so the member of its (fake) implementation cannot be written without lock. The issue can be triggered by: go test k8s.io/kubernetes/pkg/scheduler/core --race --count=50
This commit is contained in:
parent
82a981fc39
commit
b6b2838a95
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user