rename FilterPlugin NodeResources

Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
This commit is contained in:
zouyee 2019-10-20 12:51:16 +08:00
parent e1685b5b59
commit 04340eaa34
6 changed files with 38 additions and 38 deletions

View File

@ -62,7 +62,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
wantPlugins: map[string][]kubeschedulerconfig.Plugin{ wantPlugins: map[string][]kubeschedulerconfig.Plugin{
"FilterPlugin": { "FilterPlugin": {
{Name: "NodeUnschedulable"}, {Name: "NodeUnschedulable"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
@ -104,7 +104,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": { "FilterPlugin": {
{Name: "NodeUnschedulable"}, {Name: "NodeUnschedulable"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
}, },
@ -153,7 +153,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
}, },
@ -212,7 +212,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeZone"}, {Name: "VolumeZone"},
@ -277,7 +277,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeZone"}, {Name: "VolumeZone"},
@ -348,7 +348,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeZone"}, {Name: "VolumeZone"},
@ -430,7 +430,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeZone"}, {Name: "VolumeZone"},
@ -525,7 +525,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeZone"}, {Name: "VolumeZone"},
@ -621,7 +621,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeBinding"}, {Name: "VolumeBinding"},
@ -723,7 +723,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeBinding"}, {Name: "VolumeBinding"},
@ -838,7 +838,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "VolumeBinding"}, {Name: "VolumeBinding"},
@ -954,7 +954,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "NodeVolumeLimits"}, {Name: "NodeVolumeLimits"},
@ -1071,7 +1071,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "NodeVolumeLimits"}, {Name: "NodeVolumeLimits"},
@ -1192,7 +1192,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "VolumeRestrictions"}, {Name: "VolumeRestrictions"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "NodeVolumeLimits"}, {Name: "NodeVolumeLimits"},
@ -1230,13 +1230,13 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
seenPredicates := sets.NewString() seenPredicates := sets.NewString()
seenPriorities := sets.NewString() seenPriorities := sets.NewString()
mandatoryPredicates := sets.NewString() mandatoryPredicates := sets.NewString()
generalPredicateFilters := []string{"NodeResources", "NodeName", "NodePorts", "NodeAffinity"} generalPredicateFilters := []string{"NodeResourcesFit", "NodeName", "NodePorts", "NodeAffinity"}
filterToPredicateMap := map[string]string{ filterToPredicateMap := map[string]string{
"NodeUnschedulable": "CheckNodeUnschedulable", "NodeUnschedulable": "CheckNodeUnschedulable",
"TaintToleration": "PodToleratesNodeTaints", "TaintToleration": "PodToleratesNodeTaints",
"NodeName": "HostName", "NodeName": "HostName",
"NodePorts": "PodFitsHostPorts", "NodePorts": "PodFitsHostPorts",
"NodeResources": "PodFitsResources", "NodeResourcesFit": "PodFitsResources",
"NodeAffinity": "MatchNodeSelector", "NodeAffinity": "MatchNodeSelector",
"VolumeBinding": "CheckVolumeBinding", "VolumeBinding": "CheckVolumeBinding",
"VolumeRestrictions": "NoDiskConflict", "VolumeRestrictions": "NoDiskConflict",

View File

@ -55,13 +55,13 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
return framework.Registry{ return framework.Registry{
imagelocality.Name: imagelocality.New, imagelocality.Name: imagelocality.New,
tainttoleration.Name: tainttoleration.New, tainttoleration.Name: tainttoleration.New,
noderesources.Name: noderesources.New,
nodename.Name: nodename.New, nodename.Name: nodename.New,
nodeports.Name: nodeports.New, nodeports.Name: nodeports.New,
nodepreferavoidpods.Name: nodepreferavoidpods.New, nodepreferavoidpods.Name: nodepreferavoidpods.New,
nodeaffinity.Name: nodeaffinity.New, nodeaffinity.Name: nodeaffinity.New,
podtopologyspread.Name: podtopologyspread.New, podtopologyspread.Name: podtopologyspread.New,
nodeunschedulable.Name: nodeunschedulable.New, nodeunschedulable.Name: nodeunschedulable.New,
noderesources.FitName: noderesources.NewFit,
noderesources.BalancedAllocationName: noderesources.NewBalancedAllocation, noderesources.BalancedAllocationName: noderesources.NewBalancedAllocation,
noderesources.MostAllocatedName: noderesources.NewMostAllocated, noderesources.MostAllocatedName: noderesources.NewMostAllocated,
noderesources.LeastAllocatedName: noderesources.NewLeastAllocated, noderesources.LeastAllocatedName: noderesources.NewLeastAllocated,
@ -105,7 +105,7 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
registry.RegisterPredicate(predicates.GeneralPred, registry.RegisterPredicate(predicates.GeneralPred,
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
// GeneralPredicate is a combination of predicates. // GeneralPredicate is a combination of predicates.
plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.Name, nil) plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.FitName, nil)
plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil) plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil)
plugins.Filter = appendToPluginSet(plugins.Filter, nodeports.Name, nil) plugins.Filter = appendToPluginSet(plugins.Filter, nodeports.Name, nil)
plugins.Filter = appendToPluginSet(plugins.Filter, nodeaffinity.Name, nil) plugins.Filter = appendToPluginSet(plugins.Filter, nodeaffinity.Name, nil)
@ -118,7 +118,7 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
}) })
registry.RegisterPredicate(predicates.PodFitsResourcesPred, registry.RegisterPredicate(predicates.PodFitsResourcesPred,
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.Name, nil) plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.FitName, nil)
return return
}) })
registry.RegisterPredicate(predicates.HostNamePred, registry.RegisterPredicate(predicates.HostNamePred,

View File

@ -4,9 +4,9 @@ go_library(
name = "go_default_library", name = "go_default_library",
srcs = [ srcs = [
"balanced_allocation.go", "balanced_allocation.go",
"fit.go",
"least_allocated.go", "least_allocated.go",
"most_allocated.go", "most_allocated.go",
"node_resources.go",
"test_util.go", "test_util.go",
], ],
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources", importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources",
@ -42,9 +42,9 @@ go_test(
name = "go_default_test", name = "go_default_test",
srcs = [ srcs = [
"balanced_allocation_test.go", "balanced_allocation_test.go",
"fit_test.go",
"least_allocated_test.go", "least_allocated_test.go",
"most_allocated_test.go", "most_allocated_test.go",
"node_resources_test.go",
], ],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [

View File

@ -28,21 +28,21 @@ import (
"k8s.io/kubernetes/pkg/scheduler/nodeinfo" "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
) )
// NodeResources is a plugin that checks if a node has sufficient resources. // Fit is a plugin that checks if a node has sufficient resources.
type NodeResources struct{} type Fit struct{}
var _ framework.FilterPlugin = &NodeResources{} var _ framework.FilterPlugin = &Fit{}
// Name is the name of the plugin used in the plugin registry and configurations. // FitName is the name of the plugin used in the plugin registry and configurations.
const Name = "NodeResources" const FitName = "NodeResourcesFit"
// Name returns name of the plugin. It is used in logs, etc. // Name returns name of the plugin. It is used in logs, etc.
func (pl *NodeResources) Name() string { func (f *Fit) Name() string {
return Name return FitName
} }
// Filter invoked at the filter extension point. // Filter invoked at the filter extension point.
func (pl *NodeResources) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status { func (f *Fit) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
meta, ok := migration.PredicateMetadata(cycleState).(predicates.PredicateMetadata) meta, ok := migration.PredicateMetadata(cycleState).(predicates.PredicateMetadata)
if !ok { if !ok {
return migration.ErrorToFrameworkStatus(fmt.Errorf("%+v convert to predicates.PredicateMetadata error", cycleState)) return migration.ErrorToFrameworkStatus(fmt.Errorf("%+v convert to predicates.PredicateMetadata error", cycleState))
@ -51,7 +51,7 @@ func (pl *NodeResources) Filter(ctx context.Context, cycleState *framework.Cycle
return migration.PredicateResultToFrameworkStatus(reasons, err) return migration.PredicateResultToFrameworkStatus(reasons, err)
} }
// New initializes a new plugin and returns it. // NewFit initializes a new plugin and returns it.
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { func NewFit(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &NodeResources{}, nil return &Fit{}, nil
} }

View File

@ -89,7 +89,7 @@ func newResourceOverheadPod(pod *v1.Pod, overhead v1.ResourceList) *v1.Pod {
pod.Spec.Overhead = overhead pod.Spec.Overhead = overhead
return pod return pod
} }
func TestNodeResources(t *testing.T) { func TestNodeResourcesFit(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodOverhead, true)() defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodOverhead, true)()
enoughPodsTests := []struct { enoughPodsTests := []struct {
@ -350,7 +350,7 @@ func TestNodeResources(t *testing.T) {
node := v1.Node{Status: v1.NodeStatus{Capacity: makeResources(10, 20, 32, 5, 20, 5).Capacity, Allocatable: makeAllocatableResources(10, 20, 32, 5, 20, 5)}} node := v1.Node{Status: v1.NodeStatus{Capacity: makeResources(10, 20, 32, 5, 20, 5).Capacity, Allocatable: makeAllocatableResources(10, 20, 32, 5, 20, 5)}}
test.nodeInfo.SetNode(&node) test.nodeInfo.SetNode(&node)
p, _ := New(nil, nil) p, _ := NewFit(nil, nil)
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), state, test.pod, test.nodeInfo) gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), state, test.pod, test.nodeInfo)
if !reflect.DeepEqual(gotStatus, test.wantStatus) { if !reflect.DeepEqual(gotStatus, test.wantStatus) {
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus) t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
@ -403,7 +403,7 @@ func TestNodeResources(t *testing.T) {
node := v1.Node{Status: v1.NodeStatus{Capacity: v1.ResourceList{}, Allocatable: makeAllocatableResources(10, 20, 1, 0, 0, 0)}} node := v1.Node{Status: v1.NodeStatus{Capacity: v1.ResourceList{}, Allocatable: makeAllocatableResources(10, 20, 1, 0, 0, 0)}}
test.nodeInfo.SetNode(&node) test.nodeInfo.SetNode(&node)
p, _ := New(nil, nil) p, _ := NewFit(nil, nil)
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), state, test.pod, test.nodeInfo) gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), state, test.pod, test.nodeInfo)
if !reflect.DeepEqual(gotStatus, test.wantStatus) { if !reflect.DeepEqual(gotStatus, test.wantStatus) {
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus) t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
@ -454,7 +454,7 @@ func TestNodeResources(t *testing.T) {
node := v1.Node{Status: v1.NodeStatus{Capacity: makeResources(10, 20, 32, 5, 20, 5).Capacity, Allocatable: makeAllocatableResources(10, 20, 32, 5, 20, 5)}} node := v1.Node{Status: v1.NodeStatus{Capacity: makeResources(10, 20, 32, 5, 20, 5).Capacity, Allocatable: makeAllocatableResources(10, 20, 32, 5, 20, 5)}}
test.nodeInfo.SetNode(&node) test.nodeInfo.SetNode(&node)
p, _ := New(nil, nil) p, _ := NewFit(nil, nil)
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), state, test.pod, test.nodeInfo) gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), state, test.pod, test.nodeInfo)
if !reflect.DeepEqual(gotStatus, test.wantStatus) { if !reflect.DeepEqual(gotStatus, test.wantStatus) {
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus) t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)

View File

@ -141,7 +141,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
expectedPlugins: map[string][]kubeschedulerconfig.Plugin{ expectedPlugins: map[string][]kubeschedulerconfig.Plugin{
"FilterPlugin": { "FilterPlugin": {
{Name: "NodeUnschedulable"}, {Name: "NodeUnschedulable"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
@ -221,7 +221,7 @@ kind: Policy
expectedPlugins: map[string][]kubeschedulerconfig.Plugin{ expectedPlugins: map[string][]kubeschedulerconfig.Plugin{
"FilterPlugin": { "FilterPlugin": {
{Name: "NodeUnschedulable"}, {Name: "NodeUnschedulable"},
{Name: "NodeResources"}, {Name: "NodeResourcesFit"},
{Name: "NodeName"}, {Name: "NodeName"},
{Name: "NodePorts"}, {Name: "NodePorts"},
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},