Rename PostFilter
plugin to PreScore
This commit is contained in:
@@ -227,6 +227,23 @@ plugins:
|
||||
- name: baz
|
||||
pluginConfig:
|
||||
- name: foo
|
||||
`, configKubeconfig)), os.FileMode(0600)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// v1alpha1 postfilter plugin config
|
||||
postfilterPluginConfigFile := filepath.Join(tmpDir, "v1alpha1_postfilter_plugin.yaml")
|
||||
if err := ioutil.WriteFile(postfilterPluginConfigFile, []byte(fmt.Sprintf(`
|
||||
apiVersion: kubescheduler.config.k8s.io/v1alpha1
|
||||
kind: KubeSchedulerConfiguration
|
||||
clientConnection:
|
||||
kubeconfig: "%s"
|
||||
plugins:
|
||||
postFilter:
|
||||
enabled:
|
||||
- name: foo
|
||||
- name: bar
|
||||
disabled:
|
||||
- name: baz
|
||||
`, configKubeconfig)), os.FileMode(0600)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -554,6 +571,62 @@ pluginConfig:
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "v1alpha1 postfilter plugin config",
|
||||
options: &Options{
|
||||
ConfigFile: postfilterPluginConfigFile,
|
||||
},
|
||||
expectedUsername: "config",
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
SchedulerName: "default-scheduler",
|
||||
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
|
||||
HardPodAffinitySymmetricWeight: 1,
|
||||
HealthzBindAddress: "0.0.0.0:10251",
|
||||
MetricsBindAddress: "0.0.0.0:10251",
|
||||
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
|
||||
EnableProfiling: true,
|
||||
EnableContentionProfiling: true,
|
||||
},
|
||||
LeaderElection: kubeschedulerconfig.KubeSchedulerLeaderElectionConfiguration{
|
||||
LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
|
||||
LeaderElect: true,
|
||||
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
|
||||
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
|
||||
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
|
||||
ResourceLock: "endpointsleases",
|
||||
ResourceNamespace: "kube-system",
|
||||
ResourceName: "kube-scheduler",
|
||||
},
|
||||
},
|
||||
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
|
||||
Kubeconfig: configKubeconfig,
|
||||
QPS: 50,
|
||||
Burst: 100,
|
||||
ContentType: "application/vnd.kubernetes.protobuf",
|
||||
},
|
||||
PercentageOfNodesToScore: defaultPercentageOfNodesToScore,
|
||||
BindTimeoutSeconds: defaultBindTimeoutSeconds,
|
||||
PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
|
||||
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
|
||||
Plugins: &kubeschedulerconfig.Plugins{
|
||||
PreScore: &kubeschedulerconfig.PluginSet{
|
||||
Enabled: []kubeschedulerconfig.Plugin{
|
||||
{
|
||||
Name: "foo",
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
Disabled: []kubeschedulerconfig.Plugin{
|
||||
{
|
||||
Name: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no config",
|
||||
options: &Options{},
|
||||
|
@@ -106,7 +106,7 @@ func getDefaultConfig() *schedulerapi.Plugins {
|
||||
{Name: interpodaffinity.Name},
|
||||
},
|
||||
},
|
||||
PostFilter: &schedulerapi.PluginSet{
|
||||
PreScore: &schedulerapi.PluginSet{
|
||||
Enabled: []schedulerapi.Plugin{
|
||||
{Name: interpodaffinity.Name},
|
||||
{Name: defaultpodtopologyspread.Name},
|
||||
@@ -151,7 +151,7 @@ func applyFeatureGates(config *schedulerapi.Plugins) {
|
||||
f := schedulerapi.Plugin{Name: podtopologyspread.Name}
|
||||
config.PreFilter.Enabled = append(config.PreFilter.Enabled, f)
|
||||
config.Filter.Enabled = append(config.Filter.Enabled, f)
|
||||
config.PostFilter.Enabled = append(config.PostFilter.Enabled, f)
|
||||
config.PreScore.Enabled = append(config.PreScore.Enabled, f)
|
||||
s := schedulerapi.Plugin{Name: podtopologyspread.Name, Weight: 1}
|
||||
config.Score.Enabled = append(config.Score.Enabled, s)
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func applyFeatureGates(config *schedulerapi.Plugins) {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.ResourceLimitsPriorityFunction) {
|
||||
klog.Infof("Registering resourcelimits priority function")
|
||||
s := schedulerapi.Plugin{Name: noderesources.ResourceLimitsName}
|
||||
config.PostFilter.Enabled = append(config.PostFilter.Enabled, s)
|
||||
config.PreScore.Enabled = append(config.PreScore.Enabled, s)
|
||||
s = schedulerapi.Plugin{Name: noderesources.ResourceLimitsName, Weight: 1}
|
||||
config.Score.Enabled = append(config.Score.Enabled, s)
|
||||
}
|
||||
|
@@ -76,7 +76,7 @@ func TestClusterAutoscalerProvider(t *testing.T) {
|
||||
{Name: interpodaffinity.Name},
|
||||
},
|
||||
},
|
||||
PostFilter: &schedulerapi.PluginSet{
|
||||
PreScore: &schedulerapi.PluginSet{
|
||||
Enabled: []schedulerapi.Plugin{
|
||||
{Name: interpodaffinity.Name},
|
||||
{Name: defaultpodtopologyspread.Name},
|
||||
@@ -149,7 +149,7 @@ func TestApplyFeatureGates(t *testing.T) {
|
||||
{Name: interpodaffinity.Name},
|
||||
},
|
||||
},
|
||||
PostFilter: &schedulerapi.PluginSet{
|
||||
PreScore: &schedulerapi.PluginSet{
|
||||
Enabled: []schedulerapi.Plugin{
|
||||
{Name: interpodaffinity.Name},
|
||||
{Name: defaultpodtopologyspread.Name},
|
||||
@@ -211,7 +211,7 @@ func TestApplyFeatureGates(t *testing.T) {
|
||||
{Name: podtopologyspread.Name},
|
||||
},
|
||||
},
|
||||
PostFilter: &schedulerapi.PluginSet{
|
||||
PreScore: &schedulerapi.PluginSet{
|
||||
Enabled: []schedulerapi.Plugin{
|
||||
{Name: interpodaffinity.Name},
|
||||
{Name: defaultpodtopologyspread.Name},
|
||||
|
@@ -135,7 +135,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "NodeLabel"},
|
||||
{Name: "ServiceAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {{Name: "DefaultPodTopologySpread"}},
|
||||
"PreScorePlugin": {{Name: "DefaultPodTopologySpread"}},
|
||||
"ScorePlugin": {
|
||||
{Name: "NodeResourcesLeastAllocated", Weight: 1},
|
||||
{Name: "NodeLabel", Weight: 4},
|
||||
@@ -190,7 +190,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "NodeLabel"},
|
||||
{Name: "ServiceAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {{Name: "DefaultPodTopologySpread"}},
|
||||
"PreScorePlugin": {{Name: "DefaultPodTopologySpread"}},
|
||||
"ScorePlugin": {
|
||||
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
|
||||
{Name: "NodeResourcesLeastAllocated", Weight: 2},
|
||||
@@ -253,7 +253,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "AzureDiskLimits"},
|
||||
{Name: "VolumeZone"},
|
||||
},
|
||||
"PostFilterPlugin": {{Name: "DefaultPodTopologySpread"}},
|
||||
"PreScorePlugin": {{Name: "DefaultPodTopologySpread"}},
|
||||
"ScorePlugin": {
|
||||
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
|
||||
{Name: "ImageLocality", Weight: 2},
|
||||
@@ -323,7 +323,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -399,7 +399,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -486,7 +486,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -584,7 +584,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -684,7 +684,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -787,7 +787,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -902,7 +902,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -1020,7 +1020,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -1138,7 +1138,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -1260,7 +1260,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -1318,7 +1318,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{Name: "TaintToleration"},
|
||||
{Name: "PodTopologySpread"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "PodTopologySpread"},
|
||||
},
|
||||
"ScorePlugin": {
|
||||
@@ -1342,7 +1342,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
},
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"QueueSortPlugin": {{Name: "PrioritySort"}},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "NodeResourceLimits"},
|
||||
},
|
||||
"FilterPlugin": {
|
||||
@@ -1440,7 +1440,7 @@ func TestAlgorithmProviderCompatibility(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -1500,7 +1500,7 @@ func TestAlgorithmProviderCompatibility(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -1550,5 +1550,4 @@ func TestAlgorithmProviderCompatibility(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -168,8 +168,8 @@ type Plugins struct {
|
||||
// Filter is a list of plugins that should be invoked when filtering out nodes that cannot run the Pod.
|
||||
Filter *PluginSet
|
||||
|
||||
// PostFilter is a list of plugins that are invoked after filtering out infeasible nodes.
|
||||
PostFilter *PluginSet
|
||||
// PreScore is a list of plugins that are invoked before scoring.
|
||||
PreScore *PluginSet
|
||||
|
||||
// Score is a list of plugins that should be invoked when ranking nodes that have passed the filtering phase.
|
||||
Score *PluginSet
|
||||
@@ -262,7 +262,7 @@ func (p *Plugins) Append(src *Plugins) {
|
||||
p.QueueSort = appendPluginSet(p.QueueSort, src.QueueSort)
|
||||
p.PreFilter = appendPluginSet(p.PreFilter, src.PreFilter)
|
||||
p.Filter = appendPluginSet(p.Filter, src.Filter)
|
||||
p.PostFilter = appendPluginSet(p.PostFilter, src.PostFilter)
|
||||
p.PreScore = appendPluginSet(p.PreScore, src.PreScore)
|
||||
p.Score = appendPluginSet(p.Score, src.Score)
|
||||
p.Reserve = appendPluginSet(p.Reserve, src.Reserve)
|
||||
p.Permit = appendPluginSet(p.Permit, src.Permit)
|
||||
@@ -281,7 +281,7 @@ func (p *Plugins) Apply(customPlugins *Plugins) {
|
||||
p.QueueSort = mergePluginSets(p.QueueSort, customPlugins.QueueSort)
|
||||
p.PreFilter = mergePluginSets(p.PreFilter, customPlugins.PreFilter)
|
||||
p.Filter = mergePluginSets(p.Filter, customPlugins.Filter)
|
||||
p.PostFilter = mergePluginSets(p.PostFilter, customPlugins.PostFilter)
|
||||
p.PreScore = mergePluginSets(p.PreScore, customPlugins.PreScore)
|
||||
p.Score = mergePluginSets(p.Score, customPlugins.Score)
|
||||
p.Reserve = mergePluginSets(p.Reserve, customPlugins.Reserve)
|
||||
p.Permit = mergePluginSets(p.Permit, customPlugins.Permit)
|
||||
|
@@ -56,14 +56,14 @@ func TestPluginsApply(t *testing.T) {
|
||||
{Name: "CustomPlugin"},
|
||||
},
|
||||
},
|
||||
PostFilter: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
PreScore: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -97,14 +97,14 @@ func TestPluginsApply(t *testing.T) {
|
||||
{Name: "DefaultPlugin2"},
|
||||
},
|
||||
},
|
||||
PostFilter: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
PreScore: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -139,14 +139,14 @@ func TestPluginsApply(t *testing.T) {
|
||||
{Name: "DefaultPlugin2"},
|
||||
},
|
||||
},
|
||||
PostFilter: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
PreScore: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -179,14 +179,14 @@ func TestPluginsApply(t *testing.T) {
|
||||
{Name: "DefaultPlugin1"},
|
||||
},
|
||||
},
|
||||
PostFilter: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
PreScore: &PluginSet{Enabled: []Plugin{}},
|
||||
Score: &PluginSet{Enabled: []Plugin{}},
|
||||
Reserve: &PluginSet{Enabled: []Plugin{}},
|
||||
Permit: &PluginSet{Enabled: []Plugin{}},
|
||||
PreBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Bind: &PluginSet{Enabled: []Plugin{}},
|
||||
PostBind: &PluginSet{Enabled: []Plugin{}},
|
||||
Unreserve: &PluginSet{Enabled: []Plugin{}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@@ -37,9 +37,12 @@ go_test(
|
||||
"//pkg/scheduler/apis/config:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/config:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library",
|
||||
"//staging/src/k8s.io/kube-scheduler/config/v1alpha1:go_default_library",
|
||||
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@@ -66,3 +66,39 @@ func Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSch
|
||||
out.LockObjectName = in.ResourceName
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *config.Plugins, s conversion.Scope) error {
|
||||
if err := autoConvert_v1alpha1_Plugins_To_config_Plugins(in, out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if in.PostFilter != nil {
|
||||
postFilter, preScore := &in.PostFilter, &out.PreScore
|
||||
*preScore = new(config.PluginSet)
|
||||
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*postFilter, *preScore, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.PreScore = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error {
|
||||
if err := autoConvert_config_Plugins_To_v1alpha1_Plugins(in, out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if in.PreScore != nil {
|
||||
preScore, postFilter := &in.PreScore, &out.PostFilter
|
||||
*postFilter = new(v1alpha1.PluginSet)
|
||||
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*preScore, *postFilter, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.PostFilter = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -19,7 +19,11 @@ package v1alpha1
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
|
||||
v1alpha1 "k8s.io/kube-scheduler/config/v1alpha1"
|
||||
@@ -191,3 +195,207 @@ func TestConfigToV1alpha1KubeSchedulerLeaderElectionConfiguration(t *testing.T)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertBetweenV1Alpha1PluginsAndConfigPlugins(t *testing.T) {
|
||||
// weight is assigned to score plugins
|
||||
weight := int32(10)
|
||||
// DummyWeight is a placeholder for the v1alpha1.plugins' weight will be filled with zero when
|
||||
// convert back from config.
|
||||
dummyWeight := int32(42)
|
||||
v1alpha1Plugins := v1alpha1.Plugins{
|
||||
QueueSort: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "queuesort-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-queuesort-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
PreFilter: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "prefilter-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-prefilter-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
Filter: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "filter-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-filter-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
PostFilter: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "postfilter-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-postfilter-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
Score: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "score-plugin", Weight: &weight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-score-plugin", Weight: &weight},
|
||||
},
|
||||
},
|
||||
Reserve: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "reserve-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-reserve-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
Permit: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "permit-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-permit-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
PreBind: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "prebind-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-prebind-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
Bind: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "bind-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-bind-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
PostBind: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "postbind-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-postbind-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
Unreserve: &v1alpha1.PluginSet{
|
||||
Enabled: []v1alpha1.Plugin{
|
||||
{Name: "unreserve-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
Disabled: []v1alpha1.Plugin{
|
||||
{Name: "disabled-unreserve-plugin", Weight: &dummyWeight},
|
||||
},
|
||||
},
|
||||
}
|
||||
configPlugins := config.Plugins{
|
||||
QueueSort: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "queuesort-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-queuesort-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
PreFilter: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "prefilter-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-prefilter-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
Filter: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "filter-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-filter-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
PreScore: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "postfilter-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-postfilter-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
Score: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "score-plugin", Weight: weight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-score-plugin", Weight: weight},
|
||||
},
|
||||
},
|
||||
Reserve: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "reserve-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-reserve-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
Permit: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "permit-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-permit-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
PreBind: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "prebind-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-prebind-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
Bind: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "bind-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-bind-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
PostBind: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "postbind-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-postbind-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
Unreserve: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "unreserve-plugin", Weight: dummyWeight},
|
||||
},
|
||||
Disabled: []config.Plugin{
|
||||
{Name: "disabled-unreserve-plugin", Weight: dummyWeight},
|
||||
},
|
||||
},
|
||||
}
|
||||
convertedConfigPlugins := config.Plugins{}
|
||||
convertedV1Alpha1Plugins := v1alpha1.Plugins{}
|
||||
scheme := runtime.NewScheme()
|
||||
utilruntime.Must(AddToScheme(scheme))
|
||||
if err := scheme.Convert(&v1alpha1Plugins, &convertedConfigPlugins, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := scheme.Convert(&configPlugins, &convertedV1Alpha1Plugins, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(configPlugins, convertedConfigPlugins); diff != "" {
|
||||
t.Errorf("unexpected plugins diff (-want, +got): %s", diff)
|
||||
}
|
||||
if diff := cmp.Diff(v1alpha1Plugins, convertedV1Alpha1Plugins); diff != "" {
|
||||
t.Errorf("unexpected plugins diff (-want, +got): %s", diff)
|
||||
}
|
||||
}
|
||||
|
@@ -78,16 +78,6 @@ func RegisterConversions(s *runtime.Scheme) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*v1alpha1.Plugins)(nil), (*config.Plugins)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_Plugins_To_config_Plugins(a.(*v1alpha1.Plugins), b.(*config.Plugins), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*config.Plugins)(nil), (*v1alpha1.Plugins)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_config_Plugins_To_v1alpha1_Plugins(a.(*config.Plugins), b.(*v1alpha1.Plugins), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*v1alpha1.SchedulerAlgorithmSource)(nil), (*config.SchedulerAlgorithmSource)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_SchedulerAlgorithmSource_To_config_SchedulerAlgorithmSource(a.(*v1alpha1.SchedulerAlgorithmSource), b.(*config.SchedulerAlgorithmSource), scope)
|
||||
}); err != nil {
|
||||
@@ -133,11 +123,21 @@ func RegisterConversions(s *runtime.Scheme) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*config.Plugins)(nil), (*v1alpha1.Plugins)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_config_Plugins_To_v1alpha1_Plugins(a.(*config.Plugins), b.(*v1alpha1.Plugins), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*v1alpha1.KubeSchedulerLeaderElectionConfiguration)(nil), (*config.KubeSchedulerLeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(a.(*v1alpha1.KubeSchedulerLeaderElectionConfiguration), b.(*config.KubeSchedulerLeaderElectionConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*v1alpha1.Plugins)(nil), (*config.Plugins)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_Plugins_To_config_Plugins(a.(*v1alpha1.Plugins), b.(*config.Plugins), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -411,15 +411,7 @@ func autoConvert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *c
|
||||
} else {
|
||||
out.Filter = nil
|
||||
}
|
||||
if in.PostFilter != nil {
|
||||
in, out := &in.PostFilter, &out.PostFilter
|
||||
*out = new(config.PluginSet)
|
||||
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.PostFilter = nil
|
||||
}
|
||||
// WARNING: in.PostFilter requires manual conversion: does not exist in peer-type
|
||||
if in.Score != nil {
|
||||
in, out := &in.Score, &out.Score
|
||||
*out = new(config.PluginSet)
|
||||
@@ -486,11 +478,6 @@ func autoConvert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *c
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert_v1alpha1_Plugins_To_config_Plugins is an autogenerated conversion function.
|
||||
func Convert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *config.Plugins, s conversion.Scope) error {
|
||||
return autoConvert_v1alpha1_Plugins_To_config_Plugins(in, out, s)
|
||||
}
|
||||
|
||||
func autoConvert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error {
|
||||
if in.QueueSort != nil {
|
||||
in, out := &in.QueueSort, &out.QueueSort
|
||||
@@ -519,15 +506,7 @@ func autoConvert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1a
|
||||
} else {
|
||||
out.Filter = nil
|
||||
}
|
||||
if in.PostFilter != nil {
|
||||
in, out := &in.PostFilter, &out.PostFilter
|
||||
*out = new(v1alpha1.PluginSet)
|
||||
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.PostFilter = nil
|
||||
}
|
||||
// WARNING: in.PreScore requires manual conversion: does not exist in peer-type
|
||||
if in.Score != nil {
|
||||
in, out := &in.Score, &out.Score
|
||||
*out = new(v1alpha1.PluginSet)
|
||||
@@ -594,11 +573,6 @@ func autoConvert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1a
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert_config_Plugins_To_v1alpha1_Plugins is an autogenerated conversion function.
|
||||
func Convert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error {
|
||||
return autoConvert_config_Plugins_To_v1alpha1_Plugins(in, out, s)
|
||||
}
|
||||
|
||||
func autoConvert_v1alpha1_SchedulerAlgorithmSource_To_config_SchedulerAlgorithmSource(in *v1alpha1.SchedulerAlgorithmSource, out *config.SchedulerAlgorithmSource, s conversion.Scope) error {
|
||||
out.Policy = (*config.SchedulerPolicySource)(unsafe.Pointer(in.Policy))
|
||||
out.Provider = (*string)(unsafe.Pointer(in.Provider))
|
||||
|
@@ -419,14 +419,14 @@ func autoConvert_v1alpha2_Plugins_To_config_Plugins(in *v1alpha2.Plugins, out *c
|
||||
} else {
|
||||
out.Filter = nil
|
||||
}
|
||||
if in.PostFilter != nil {
|
||||
in, out := &in.PostFilter, &out.PostFilter
|
||||
if in.PreScore != nil {
|
||||
in, out := &in.PreScore, &out.PreScore
|
||||
*out = new(config.PluginSet)
|
||||
if err := Convert_v1alpha2_PluginSet_To_config_PluginSet(*in, *out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.PostFilter = nil
|
||||
out.PreScore = nil
|
||||
}
|
||||
if in.Score != nil {
|
||||
in, out := &in.Score, &out.Score
|
||||
@@ -527,14 +527,14 @@ func autoConvert_config_Plugins_To_v1alpha2_Plugins(in *config.Plugins, out *v1a
|
||||
} else {
|
||||
out.Filter = nil
|
||||
}
|
||||
if in.PostFilter != nil {
|
||||
in, out := &in.PostFilter, &out.PostFilter
|
||||
if in.PreScore != nil {
|
||||
in, out := &in.PreScore, &out.PreScore
|
||||
*out = new(v1alpha2.PluginSet)
|
||||
if err := Convert_config_PluginSet_To_v1alpha2_PluginSet(*in, *out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.PostFilter = nil
|
||||
out.PreScore = nil
|
||||
}
|
||||
if in.Score != nil {
|
||||
in, out := &in.Score, &out.Score
|
||||
|
@@ -269,8 +269,8 @@ func (in *Plugins) DeepCopyInto(out *Plugins) {
|
||||
*out = new(PluginSet)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.PostFilter != nil {
|
||||
in, out := &in.PostFilter, &out.PostFilter
|
||||
if in.PreScore != nil {
|
||||
in, out := &in.PreScore, &out.PreScore
|
||||
*out = new(PluginSet)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
|
@@ -194,12 +194,6 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
|
||||
}
|
||||
trace.Step("Computing predicates done")
|
||||
|
||||
// Run "postfilter" plugins.
|
||||
postfilterStatus := g.framework.RunPostFilterPlugins(ctx, state, pod, filteredNodes, filteredNodesStatuses)
|
||||
if !postfilterStatus.IsSuccess() {
|
||||
return result, postfilterStatus.AsError()
|
||||
}
|
||||
|
||||
if len(filteredNodes) == 0 {
|
||||
return result, &FitError{
|
||||
Pod: pod,
|
||||
@@ -207,7 +201,14 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
|
||||
FilteredNodesStatuses: filteredNodesStatuses,
|
||||
}
|
||||
}
|
||||
trace.Step("Running postfilter plugins done")
|
||||
|
||||
// Run "prescore" plugins.
|
||||
prescoreStatus := g.framework.RunPreScorePlugins(ctx, state, pod, filteredNodes, filteredNodesStatuses)
|
||||
if !prescoreStatus.IsSuccess() {
|
||||
return result, prescoreStatus.AsError()
|
||||
}
|
||||
trace.Step("Running prescore plugins done")
|
||||
|
||||
metrics.DeprecatedSchedulingAlgorithmPredicateEvaluationSecondsDuration.Observe(metrics.SinceInSeconds(startPredicateEvalTime))
|
||||
metrics.DeprecatedSchedulingDuration.WithLabelValues(metrics.PredicateEvaluation).Observe(metrics.SinceInSeconds(startPredicateEvalTime))
|
||||
|
||||
|
@@ -1115,7 +1115,7 @@ func TestZeroRequest(t *testing.T) {
|
||||
st.RegisterScorePlugin(noderesources.LeastAllocatedName, noderesources.NewLeastAllocated, 1),
|
||||
st.RegisterScorePlugin(noderesources.BalancedAllocationName, noderesources.NewBalancedAllocation, 1),
|
||||
st.RegisterScorePlugin(defaultpodtopologyspread.Name, defaultpodtopologyspread.New, 1),
|
||||
st.RegisterPostFilterPlugin(defaultpodtopologyspread.Name, defaultpodtopologyspread.New),
|
||||
st.RegisterPreScorePlugin(defaultpodtopologyspread.Name, defaultpodtopologyspread.New),
|
||||
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
|
||||
}
|
||||
fwk, err := st.NewFramework(
|
||||
@@ -1148,7 +1148,7 @@ func TestZeroRequest(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("error filtering nodes: %+v", err)
|
||||
}
|
||||
scheduler.framework.RunPostFilterPlugins(ctx, state, test.pod, test.nodes, filteredNodesStatuses)
|
||||
scheduler.framework.RunPreScorePlugins(ctx, state, test.pod, test.nodes, filteredNodesStatuses)
|
||||
list, err := scheduler.prioritizeNodes(
|
||||
ctx,
|
||||
state,
|
||||
|
@@ -43,8 +43,8 @@ var _ framework.ScorePlugin = &DefaultPodTopologySpread{}
|
||||
const (
|
||||
// Name is the name of the plugin used in the plugin registry and configurations.
|
||||
Name = "DefaultPodTopologySpread"
|
||||
// postFilterStateKey is the key in CycleState to DefaultPodTopologySpread pre-computed data for Scoring.
|
||||
postFilterStateKey = "PostFilter" + Name
|
||||
// preScoreStateKey is the key in CycleState to DefaultPodTopologySpread pre-computed data for Scoring.
|
||||
preScoreStateKey = "PreScore" + Name
|
||||
|
||||
// When zone information is present, give 2/3 of the weighting to zone spreading, 1/3 to node spreading
|
||||
// TODO: Any way to justify this weighting?
|
||||
@@ -56,14 +56,14 @@ func (pl *DefaultPodTopologySpread) Name() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
// postFilterState computed at PostFilter and used at Score.
|
||||
type postFilterState struct {
|
||||
// preScoreState computed at PreScore and used at Score.
|
||||
type preScoreState struct {
|
||||
selector labels.Selector
|
||||
}
|
||||
|
||||
// Clone implements the mandatory Clone interface. We don't really copy the data since
|
||||
// there is no need for that.
|
||||
func (s *postFilterState) Clone() framework.StateData {
|
||||
func (s *preScoreState) Clone() framework.StateData {
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -80,14 +80,14 @@ func (pl *DefaultPodTopologySpread) Score(ctx context.Context, state *framework.
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
c, err := state.Read(postFilterStateKey)
|
||||
c, err := state.Read(preScoreStateKey)
|
||||
if err != nil {
|
||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("Error reading %q from cycleState: %v", postFilterStateKey, err))
|
||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("Error reading %q from cycleState: %v", preScoreStateKey, err))
|
||||
}
|
||||
|
||||
s, ok := c.(*postFilterState)
|
||||
s, ok := c.(*preScoreState)
|
||||
if !ok {
|
||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("%+v convert to tainttoleration.postFilterState error", c))
|
||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("%+v convert to tainttoleration.preScoreState error", c))
|
||||
}
|
||||
|
||||
nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
|
||||
@@ -177,8 +177,8 @@ func (pl *DefaultPodTopologySpread) ScoreExtensions() framework.ScoreExtensions
|
||||
return pl
|
||||
}
|
||||
|
||||
// PostFilter builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *DefaultPodTopologySpread) PostFilter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node, _ framework.NodeToStatusMap) *framework.Status {
|
||||
// PreScore builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *DefaultPodTopologySpread) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node, _ framework.NodeToStatusMap) *framework.Status {
|
||||
var selector labels.Selector
|
||||
informerFactory := pl.handle.SharedInformerFactory()
|
||||
selector = getSelector(
|
||||
@@ -188,10 +188,10 @@ func (pl *DefaultPodTopologySpread) PostFilter(ctx context.Context, cycleState *
|
||||
informerFactory.Apps().V1().ReplicaSets().Lister(),
|
||||
informerFactory.Apps().V1().StatefulSets().Lister(),
|
||||
)
|
||||
state := &postFilterState{
|
||||
state := &preScoreState{
|
||||
selector: selector,
|
||||
}
|
||||
cycleState.Write(postFilterStateKey, state)
|
||||
cycleState.Write(preScoreStateKey, state)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -73,7 +73,7 @@ func BenchmarkTestSelectorSpreadPriority(b *testing.B) {
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
state := framework.NewCycleState()
|
||||
status := plugin.PostFilter(ctx, state, pod, allNodes, nil)
|
||||
status := plugin.PreScore(ctx, state, pod, allNodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
b.Fatalf("unexpected error: %v", status)
|
||||
}
|
||||
|
@@ -386,7 +386,7 @@ func TestDefaultPodTopologySpreadScore(t *testing.T) {
|
||||
handle: fh,
|
||||
}
|
||||
|
||||
status := plugin.PostFilter(ctx, state, test.pod, nodes, nil)
|
||||
status := plugin.PreScore(ctx, state, test.pod, nodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
t.Fatalf("unexpected error: %v", status)
|
||||
}
|
||||
@@ -638,7 +638,7 @@ func TestZoneSelectorSpreadPriority(t *testing.T) {
|
||||
}
|
||||
|
||||
state := framework.NewCycleState()
|
||||
status := plugin.PostFilter(ctx, state, test.pod, nodes, nil)
|
||||
status := plugin.PreScore(ctx, state, test.pod, nodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
t.Fatalf("unexpected error: %v", status)
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ type Args struct {
|
||||
|
||||
var _ framework.PreFilterPlugin = &InterPodAffinity{}
|
||||
var _ framework.FilterPlugin = &InterPodAffinity{}
|
||||
var _ framework.PostFilterPlugin = &InterPodAffinity{}
|
||||
var _ framework.PreScorePlugin = &InterPodAffinity{}
|
||||
var _ framework.ScorePlugin = &InterPodAffinity{}
|
||||
|
||||
// InterPodAffinity is a plugin that checks inter pod affinity
|
||||
|
@@ -29,11 +29,11 @@ import (
|
||||
schedutil "k8s.io/kubernetes/pkg/scheduler/util"
|
||||
)
|
||||
|
||||
// postFilterStateKey is the key in CycleState to InterPodAffinity pre-computed data for Scoring.
|
||||
const postFilterStateKey = "PostFilter" + Name
|
||||
// preScoreStateKey is the key in CycleState to InterPodAffinity pre-computed data for Scoring.
|
||||
const preScoreStateKey = "PreScore" + Name
|
||||
|
||||
// postFilterState computed at PostFilter and used at Score.
|
||||
type postFilterState struct {
|
||||
// preScoreState computed at PreScore and used at Score.
|
||||
type preScoreState struct {
|
||||
topologyScore map[string]map[string]int64
|
||||
affinityTerms []*weightedAffinityTerm
|
||||
antiAffinityTerms []*weightedAffinityTerm
|
||||
@@ -41,7 +41,7 @@ type postFilterState struct {
|
||||
|
||||
// Clone implements the mandatory Clone interface. We don't really copy the data since
|
||||
// there is no need for that.
|
||||
func (s *postFilterState) Clone() framework.StateData {
|
||||
func (s *preScoreState) Clone() framework.StateData {
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func getWeightedAffinityTerms(pod *v1.Pod, v1Terms []v1.WeightedPodAffinityTerm)
|
||||
}
|
||||
|
||||
func (pl *InterPodAffinity) processTerm(
|
||||
state *postFilterState,
|
||||
state *preScoreState,
|
||||
term *weightedAffinityTerm,
|
||||
podToCheck *v1.Pod,
|
||||
fixedNode *v1.Node,
|
||||
@@ -100,14 +100,14 @@ func (pl *InterPodAffinity) processTerm(
|
||||
return
|
||||
}
|
||||
|
||||
func (pl *InterPodAffinity) processTerms(state *postFilterState, terms []*weightedAffinityTerm, podToCheck *v1.Pod, fixedNode *v1.Node, multiplier int) error {
|
||||
func (pl *InterPodAffinity) processTerms(state *preScoreState, terms []*weightedAffinityTerm, podToCheck *v1.Pod, fixedNode *v1.Node, multiplier int) error {
|
||||
for _, term := range terms {
|
||||
pl.processTerm(state, term, podToCheck, fixedNode, multiplier)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pl *InterPodAffinity) processExistingPod(state *postFilterState, existingPod *v1.Pod, existingPodNodeInfo *nodeinfo.NodeInfo, incomingPod *v1.Pod) error {
|
||||
func (pl *InterPodAffinity) processExistingPod(state *preScoreState, existingPod *v1.Pod, existingPodNodeInfo *nodeinfo.NodeInfo, incomingPod *v1.Pod) error {
|
||||
existingPodAffinity := existingPod.Spec.Affinity
|
||||
existingHasAffinityConstraints := existingPodAffinity != nil && existingPodAffinity.PodAffinity != nil
|
||||
existingHasAntiAffinityConstraints := existingPodAffinity != nil && existingPodAffinity.PodAntiAffinity != nil
|
||||
@@ -166,8 +166,8 @@ func (pl *InterPodAffinity) processExistingPod(state *postFilterState, existingP
|
||||
return nil
|
||||
}
|
||||
|
||||
// PostFilter builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *InterPodAffinity) PostFilter(
|
||||
// PreScore builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *InterPodAffinity) PreScore(
|
||||
pCtx context.Context,
|
||||
cycleState *framework.CycleState,
|
||||
pod *v1.Pod,
|
||||
@@ -215,7 +215,7 @@ func (pl *InterPodAffinity) PostFilter(
|
||||
}
|
||||
}
|
||||
|
||||
state := &postFilterState{
|
||||
state := &preScoreState{
|
||||
topologyScore: make(map[string]map[string]int64),
|
||||
affinityTerms: affinityTerms,
|
||||
antiAffinityTerms: antiAffinityTerms,
|
||||
@@ -248,19 +248,19 @@ func (pl *InterPodAffinity) PostFilter(
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
}
|
||||
|
||||
cycleState.Write(postFilterStateKey, state)
|
||||
cycleState.Write(preScoreStateKey, state)
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPostFilterState(cycleState *framework.CycleState) (*postFilterState, error) {
|
||||
c, err := cycleState.Read(postFilterStateKey)
|
||||
func getPreScoreState(cycleState *framework.CycleState) (*preScoreState, error) {
|
||||
c, err := cycleState.Read(preScoreStateKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error reading %q from cycleState: %v", postFilterStateKey, err)
|
||||
return nil, fmt.Errorf("Error reading %q from cycleState: %v", preScoreStateKey, err)
|
||||
}
|
||||
|
||||
s, ok := c.(*postFilterState)
|
||||
s, ok := c.(*preScoreState)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%+v convert to interpodaffinity.postFilterState error", c)
|
||||
return nil, fmt.Errorf("%+v convert to interpodaffinity.preScoreState error", c)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func (pl *InterPodAffinity) Score(ctx context.Context, cycleState *framework.Cyc
|
||||
}
|
||||
node := nodeInfo.Node()
|
||||
|
||||
s, err := getPostFilterState(cycleState)
|
||||
s, err := getPreScoreState(cycleState)
|
||||
if err != nil {
|
||||
return 0, framework.NewStatus(framework.Error, err.Error())
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func (pl *InterPodAffinity) Score(ctx context.Context, cycleState *framework.Cyc
|
||||
// The basic rule is: the bigger the score(matching number of pods) is, the smaller the
|
||||
// final normalized score will be.
|
||||
func (pl *InterPodAffinity) NormalizeScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, scores framework.NodeScoreList) *framework.Status {
|
||||
s, err := getPostFilterState(cycleState)
|
||||
s, err := getPreScoreState(cycleState)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
@@ -523,7 +523,7 @@ func TestPreferredAffinity(t *testing.T) {
|
||||
hardPodAffinityWeight: 1,
|
||||
}
|
||||
|
||||
status := p.PostFilter(context.Background(), state, test.pod, test.nodes, nil)
|
||||
status := p.PreScore(context.Background(), state, test.pod, test.nodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
t.Errorf("unexpected error: %v", status)
|
||||
}
|
||||
@@ -631,7 +631,7 @@ func TestPreferredAffinityWithHardPodAffinitySymmetricWeight(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
status := p.(framework.PostFilterPlugin).PostFilter(context.Background(), state, test.pod, test.nodes, nil)
|
||||
status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
t.Errorf("unexpected error: %v", status)
|
||||
}
|
||||
|
@@ -330,12 +330,12 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
registry.registerPriorityConfigProducer(SelectorSpreadPriority,
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.Score = appendToPluginSet(plugins.Score, defaultpodtopologyspread.Name, &args.Weight)
|
||||
plugins.PostFilter = appendToPluginSet(plugins.PostFilter, defaultpodtopologyspread.Name, nil)
|
||||
plugins.PreScore = appendToPluginSet(plugins.PreScore, defaultpodtopologyspread.Name, nil)
|
||||
return
|
||||
})
|
||||
registry.registerPriorityConfigProducer(TaintTolerationPriority,
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.PostFilter = appendToPluginSet(plugins.PostFilter, tainttoleration.Name, nil)
|
||||
plugins.PreScore = appendToPluginSet(plugins.PreScore, tainttoleration.Name, nil)
|
||||
plugins.Score = appendToPluginSet(plugins.Score, tainttoleration.Name, &args.Weight)
|
||||
return
|
||||
})
|
||||
@@ -351,7 +351,7 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
})
|
||||
registry.registerPriorityConfigProducer(InterPodAffinityPriority,
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.PostFilter = appendToPluginSet(plugins.PostFilter, interpodaffinity.Name, nil)
|
||||
plugins.PreScore = appendToPluginSet(plugins.PreScore, interpodaffinity.Name, nil)
|
||||
plugins.Score = appendToPluginSet(plugins.Score, interpodaffinity.Name, &args.Weight)
|
||||
pluginConfig = append(pluginConfig, makePluginConfig(interpodaffinity.Name, args.InterPodAffinityArgs))
|
||||
return
|
||||
@@ -420,7 +420,7 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
|
||||
registry.registerPriorityConfigProducer(EvenPodsSpreadPriority,
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.PostFilter = appendToPluginSet(plugins.PostFilter, podtopologyspread.Name, nil)
|
||||
plugins.PreScore = appendToPluginSet(plugins.PreScore, podtopologyspread.Name, nil)
|
||||
plugins.Score = appendToPluginSet(plugins.Score, podtopologyspread.Name, &args.Weight)
|
||||
return
|
||||
})
|
||||
@@ -433,7 +433,7 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
|
||||
registry.registerPriorityConfigProducer(ResourceLimitsPriority,
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.PostFilter = appendToPluginSet(plugins.PostFilter, noderesources.ResourceLimitsName, nil)
|
||||
plugins.PreScore = appendToPluginSet(plugins.PreScore, noderesources.ResourceLimitsName, nil)
|
||||
plugins.Score = appendToPluginSet(plugins.Score, noderesources.ResourceLimitsName, &args.Weight)
|
||||
return
|
||||
})
|
||||
|
@@ -102,7 +102,7 @@ func TestRegisterConfigProducers(t *testing.T) {
|
||||
{Name: testFilterName2},
|
||||
},
|
||||
},
|
||||
PostFilter: &config.PluginSet{},
|
||||
PreScore: &config.PluginSet{},
|
||||
Score: &config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: testScoreName1, Weight: 1},
|
||||
|
@@ -32,25 +32,25 @@ type ResourceLimits struct {
|
||||
handle framework.FrameworkHandle
|
||||
}
|
||||
|
||||
var _ = framework.PostFilterPlugin(&ResourceLimits{})
|
||||
var _ = framework.PreScorePlugin(&ResourceLimits{})
|
||||
var _ = framework.ScorePlugin(&ResourceLimits{})
|
||||
|
||||
const (
|
||||
// ResourceLimitsName is the name of the plugin used in the plugin registry and configurations.
|
||||
ResourceLimitsName = "NodeResourceLimits"
|
||||
|
||||
// postFilterStateKey is the key in CycleState to NodeResourceLimits pre-computed data.
|
||||
// preScoreStateKey is the key in CycleState to NodeResourceLimits pre-computed data.
|
||||
// Using the name of the plugin will likely help us avoid collisions with other plugins.
|
||||
postFilterStateKey = "PostFilter" + ResourceLimitsName
|
||||
preScoreStateKey = "PreScore" + ResourceLimitsName
|
||||
)
|
||||
|
||||
// postFilterState computed at PostFilter and used at Score.
|
||||
type postFilterState struct {
|
||||
// preScoreState computed at PreScore and used at Score.
|
||||
type preScoreState struct {
|
||||
podResourceRequest *schedulernodeinfo.Resource
|
||||
}
|
||||
|
||||
// Clone the postFilter state.
|
||||
func (s *postFilterState) Clone() framework.StateData {
|
||||
// Clone the preScore state.
|
||||
func (s *preScoreState) Clone() framework.StateData {
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ func (rl *ResourceLimits) Name() string {
|
||||
return ResourceLimitsName
|
||||
}
|
||||
|
||||
// PostFilter builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (rl *ResourceLimits) PostFilter(
|
||||
// PreScore builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (rl *ResourceLimits) PreScore(
|
||||
pCtx context.Context,
|
||||
cycleState *framework.CycleState,
|
||||
pod *v1.Pod,
|
||||
@@ -75,22 +75,22 @@ func (rl *ResourceLimits) PostFilter(
|
||||
if rl.handle.SnapshotSharedLister() == nil {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("empty shared lister"))
|
||||
}
|
||||
s := &postFilterState{
|
||||
s := &preScoreState{
|
||||
podResourceRequest: getResourceLimits(pod),
|
||||
}
|
||||
cycleState.Write(postFilterStateKey, s)
|
||||
cycleState.Write(preScoreStateKey, s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPodResource(cycleState *framework.CycleState) (*schedulernodeinfo.Resource, error) {
|
||||
c, err := cycleState.Read(postFilterStateKey)
|
||||
c, err := cycleState.Read(preScoreStateKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error reading %q from cycleState: %v", postFilterStateKey, err)
|
||||
return nil, fmt.Errorf("Error reading %q from cycleState: %v", preScoreStateKey, err)
|
||||
}
|
||||
|
||||
s, ok := c.(*postFilterState)
|
||||
s, ok := c.(*preScoreState)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%+v convert to ResourceLimits.postFilterState error", c)
|
||||
return nil, fmt.Errorf("%+v convert to ResourceLimits.preScoreState error", c)
|
||||
}
|
||||
return s.podResourceRequest, nil
|
||||
}
|
||||
|
@@ -99,11 +99,11 @@ func TestResourceLimits(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
// input pod
|
||||
pod *v1.Pod
|
||||
nodes []*v1.Node
|
||||
expectedList framework.NodeScoreList
|
||||
name string
|
||||
skipPostFilter bool
|
||||
pod *v1.Pod
|
||||
nodes []*v1.Node
|
||||
expectedList framework.NodeScoreList
|
||||
name string
|
||||
skipPreScore bool
|
||||
}{
|
||||
{
|
||||
pod: &v1.Pod{Spec: noResources},
|
||||
@@ -136,11 +136,11 @@ func TestResourceLimits(t *testing.T) {
|
||||
name: "node does not advertise its allocatables",
|
||||
},
|
||||
{
|
||||
pod: &v1.Pod{Spec: cpuAndMemory},
|
||||
nodes: []*v1.Node{makeNode("machine1", 0, 0)},
|
||||
expectedList: []framework.NodeScore{{Name: "machine1", Score: 0}},
|
||||
skipPostFilter: true,
|
||||
name: "postFilter skipped",
|
||||
pod: &v1.Pod{Spec: cpuAndMemory},
|
||||
nodes: []*v1.Node{makeNode("machine1", 0, 0)},
|
||||
expectedList: []framework.NodeScore{{Name: "machine1", Score: 0}},
|
||||
skipPreScore: true,
|
||||
name: "preScore skipped",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -151,15 +151,15 @@ func TestResourceLimits(t *testing.T) {
|
||||
p := &ResourceLimits{handle: fh}
|
||||
for i := range test.nodes {
|
||||
state := framework.NewCycleState()
|
||||
if !test.skipPostFilter {
|
||||
status := p.PostFilter(context.Background(), state, test.pod, test.nodes, nil)
|
||||
if !test.skipPreScore {
|
||||
status := p.PreScore(context.Background(), state, test.pod, test.nodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
t.Errorf("unexpected error: %v", status)
|
||||
}
|
||||
}
|
||||
|
||||
gotScore, err := p.Score(context.Background(), state, test.pod, test.nodes[i].Name)
|
||||
if test.skipPostFilter {
|
||||
if test.skipPreScore {
|
||||
if err == nil {
|
||||
t.Errorf("expected error")
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ type PodTopologySpread struct {
|
||||
|
||||
var _ framework.PreFilterPlugin = &PodTopologySpread{}
|
||||
var _ framework.FilterPlugin = &PodTopologySpread{}
|
||||
var _ framework.PostFilterPlugin = &PodTopologySpread{}
|
||||
var _ framework.PreScorePlugin = &PodTopologySpread{}
|
||||
var _ framework.ScorePlugin = &PodTopologySpread{}
|
||||
|
||||
const (
|
||||
|
@@ -31,10 +31,10 @@ import (
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
)
|
||||
|
||||
const postFilterStateKey = "PostFilter" + Name
|
||||
const preScoreStateKey = "PreScore" + Name
|
||||
|
||||
// postFilterState computed at PostFilter and used at Score.
|
||||
type postFilterState struct {
|
||||
// preScoreState computed at PreScore and used at Score.
|
||||
type preScoreState struct {
|
||||
constraints []topologySpreadConstraint
|
||||
// nodeNameSet is a string set holding all node names which have all constraints[*].topologyKey present.
|
||||
nodeNameSet sets.String
|
||||
@@ -44,7 +44,7 @@ type postFilterState struct {
|
||||
|
||||
// Clone implements the mandatory Clone interface. We don't really copy the data since
|
||||
// there is no need for that.
|
||||
func (s *postFilterState) Clone() framework.StateData {
|
||||
func (s *preScoreState) Clone() framework.StateData {
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func (s *postFilterState) Clone() framework.StateData {
|
||||
// and initialize two maps:
|
||||
// 1) s.topologyPairToPodCounts: keyed with both eligible topology pair and node names.
|
||||
// 2) s.nodeNameSet: keyed with node name, and valued with a *int64 pointer for eligible node only.
|
||||
func (s *postFilterState) initialize(pod *v1.Pod, filteredNodes []*v1.Node) error {
|
||||
func (s *preScoreState) initialize(pod *v1.Pod, filteredNodes []*v1.Node) error {
|
||||
constraints, err := filterTopologySpreadConstraints(pod.Spec.TopologySpreadConstraints, v1.ScheduleAnyway)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -78,8 +78,8 @@ func (s *postFilterState) initialize(pod *v1.Pod, filteredNodes []*v1.Node) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// PostFilter builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *PodTopologySpread) PostFilter(
|
||||
// PreScore builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *PodTopologySpread) PreScore(
|
||||
ctx context.Context,
|
||||
cycleState *framework.CycleState,
|
||||
pod *v1.Pod,
|
||||
@@ -96,18 +96,18 @@ func (pl *PodTopologySpread) PostFilter(
|
||||
return nil
|
||||
}
|
||||
|
||||
state := &postFilterState{
|
||||
state := &preScoreState{
|
||||
nodeNameSet: sets.String{},
|
||||
topologyPairToPodCounts: make(map[topologyPair]*int64),
|
||||
}
|
||||
err = state.initialize(pod, filteredNodes)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("error when calculating postFilterState: %v", err))
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("error when calculating preScoreState: %v", err))
|
||||
}
|
||||
|
||||
// return if incoming pod doesn't have soft topology spread constraints.
|
||||
if state.constraints == nil {
|
||||
cycleState.Write(postFilterStateKey, state)
|
||||
cycleState.Write(preScoreStateKey, state)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (pl *PodTopologySpread) PostFilter(
|
||||
}
|
||||
workqueue.ParallelizeUntil(ctx, 16, len(allNodes), processAllNode)
|
||||
|
||||
cycleState.Write(postFilterStateKey, state)
|
||||
cycleState.Write(preScoreStateKey, state)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ func (pl *PodTopologySpread) Score(ctx context.Context, cycleState *framework.Cy
|
||||
}
|
||||
|
||||
node := nodeInfo.Node()
|
||||
s, err := getPostFilterState(cycleState)
|
||||
s, err := getPreScoreState(cycleState)
|
||||
if err != nil {
|
||||
return 0, framework.NewStatus(framework.Error, err.Error())
|
||||
}
|
||||
@@ -187,7 +187,7 @@ func (pl *PodTopologySpread) Score(ctx context.Context, cycleState *framework.Cy
|
||||
|
||||
// NormalizeScore invoked after scoring all nodes.
|
||||
func (pl *PodTopologySpread) NormalizeScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, scores framework.NodeScoreList) *framework.Status {
|
||||
s, err := getPostFilterState(cycleState)
|
||||
s, err := getPreScoreState(cycleState)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
}
|
||||
@@ -246,15 +246,15 @@ func (pl *PodTopologySpread) ScoreExtensions() framework.ScoreExtensions {
|
||||
return pl
|
||||
}
|
||||
|
||||
func getPostFilterState(cycleState *framework.CycleState) (*postFilterState, error) {
|
||||
c, err := cycleState.Read(postFilterStateKey)
|
||||
func getPreScoreState(cycleState *framework.CycleState) (*preScoreState, error) {
|
||||
c, err := cycleState.Read(preScoreStateKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading %q from cycleState: %v", postFilterStateKey, err)
|
||||
return nil, fmt.Errorf("error reading %q from cycleState: %v", preScoreStateKey, err)
|
||||
}
|
||||
|
||||
s, ok := c.(*postFilterState)
|
||||
s, ok := c.(*preScoreState)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%+v convert to podtopologyspread.postFilterState error", c)
|
||||
return nil, fmt.Errorf("%+v convert to podtopologyspread.preScoreState error", c)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import (
|
||||
st "k8s.io/kubernetes/pkg/scheduler/testing"
|
||||
)
|
||||
|
||||
func TestPostFilterStateInitialize(t *testing.T) {
|
||||
func TestPreScoreStateInitialize(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pod *v1.Pod
|
||||
@@ -77,7 +77,7 @@ func TestPostFilterStateInitialize(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &postFilterState{
|
||||
s := &preScoreState{
|
||||
nodeNameSet: sets.String{},
|
||||
topologyPairToPodCounts: make(map[topologyPair]*int64),
|
||||
}
|
||||
@@ -476,7 +476,7 @@ func TestPodTopologySpreadScore(t *testing.T) {
|
||||
snapshot := cache.NewSnapshot(tt.existingPods, allNodes)
|
||||
p := &PodTopologySpread{sharedLister: snapshot}
|
||||
|
||||
status := p.PostFilter(context.Background(), state, tt.pod, tt.nodes, nil)
|
||||
status := p.PreScore(context.Background(), state, tt.pod, tt.nodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
t.Errorf("unexpected error: %v", status)
|
||||
}
|
||||
@@ -546,7 +546,7 @@ func BenchmarkTestPodTopologySpreadScore(b *testing.B) {
|
||||
snapshot := cache.NewSnapshot(existingPods, allNodes)
|
||||
p := &PodTopologySpread{sharedLister: snapshot}
|
||||
|
||||
status := p.PostFilter(context.Background(), state, tt.pod, filteredNodes, nil)
|
||||
status := p.PreScore(context.Background(), state, tt.pod, filteredNodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
b.Fatalf("unexpected error: %v", status)
|
||||
}
|
||||
@@ -605,7 +605,7 @@ func BenchmarkTestDefaultEvenPodsSpreadPriority(b *testing.B) {
|
||||
snapshot := cache.NewSnapshot(existingPods, allNodes)
|
||||
p := &PodTopologySpread{sharedLister: snapshot}
|
||||
|
||||
status := p.PostFilter(context.Background(), state, pod, filteredNodes, nil)
|
||||
status := p.PreScore(context.Background(), state, pod, filteredNodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
b.Fatalf("unexpected error: %v", status)
|
||||
}
|
||||
|
@@ -34,14 +34,14 @@ type TaintToleration struct {
|
||||
}
|
||||
|
||||
var _ framework.FilterPlugin = &TaintToleration{}
|
||||
var _ framework.PostFilterPlugin = &TaintToleration{}
|
||||
var _ framework.PreScorePlugin = &TaintToleration{}
|
||||
var _ framework.ScorePlugin = &TaintToleration{}
|
||||
|
||||
const (
|
||||
// Name is the name of the plugin used in the plugin registry and configurations.
|
||||
Name = "TaintToleration"
|
||||
// postFilterStateKey is the key in CycleState to TaintToleration pre-computed data for Scoring.
|
||||
postFilterStateKey = "PostFilter" + Name
|
||||
// preScoreStateKey is the key in CycleState to TaintToleration pre-computed data for Scoring.
|
||||
preScoreStateKey = "PreScore" + Name
|
||||
// ErrReasonNotMatch is the Filter reason status when not matching.
|
||||
ErrReasonNotMatch = "node(s) had taints that the pod didn't tolerate"
|
||||
)
|
||||
@@ -77,14 +77,14 @@ func (pl *TaintToleration) Filter(ctx context.Context, state *framework.CycleSta
|
||||
return framework.NewStatus(framework.UnschedulableAndUnresolvable, errReason)
|
||||
}
|
||||
|
||||
// postFilterState computed at PostFilter and used at Score.
|
||||
type postFilterState struct {
|
||||
// preScoreState computed at PreScore and used at Score.
|
||||
type preScoreState struct {
|
||||
tolerationsPreferNoSchedule []v1.Toleration
|
||||
}
|
||||
|
||||
// Clone implements the mandatory Clone interface. We don't really copy the data since
|
||||
// there is no need for that.
|
||||
func (s *postFilterState) Clone() framework.StateData {
|
||||
func (s *preScoreState) Clone() framework.StateData {
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -99,28 +99,28 @@ func getAllTolerationPreferNoSchedule(tolerations []v1.Toleration) (tolerationLi
|
||||
return
|
||||
}
|
||||
|
||||
// PostFilter builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *TaintToleration) PostFilter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node, _ framework.NodeToStatusMap) *framework.Status {
|
||||
// PreScore builds and writes cycle state used by Score and NormalizeScore.
|
||||
func (pl *TaintToleration) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node, _ framework.NodeToStatusMap) *framework.Status {
|
||||
if len(nodes) == 0 {
|
||||
return nil
|
||||
}
|
||||
tolerationsPreferNoSchedule := getAllTolerationPreferNoSchedule(pod.Spec.Tolerations)
|
||||
state := &postFilterState{
|
||||
state := &preScoreState{
|
||||
tolerationsPreferNoSchedule: tolerationsPreferNoSchedule,
|
||||
}
|
||||
cycleState.Write(postFilterStateKey, state)
|
||||
cycleState.Write(preScoreStateKey, state)
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPostFilterState(cycleState *framework.CycleState) (*postFilterState, error) {
|
||||
c, err := cycleState.Read(postFilterStateKey)
|
||||
func getPreScoreState(cycleState *framework.CycleState) (*preScoreState, error) {
|
||||
c, err := cycleState.Read(preScoreStateKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error reading %q from cycleState: %v", postFilterStateKey, err)
|
||||
return nil, fmt.Errorf("Error reading %q from cycleState: %v", preScoreStateKey, err)
|
||||
}
|
||||
|
||||
s, ok := c.(*postFilterState)
|
||||
s, ok := c.(*preScoreState)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%+v convert to tainttoleration.postFilterState error", c)
|
||||
return nil, fmt.Errorf("%+v convert to tainttoleration.preScoreState error", c)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (pl *TaintToleration) Score(ctx context.Context, state *framework.CycleStat
|
||||
}
|
||||
node := nodeInfo.Node()
|
||||
|
||||
s, err := getPostFilterState(state)
|
||||
s, err := getPreScoreState(state)
|
||||
if err != nil {
|
||||
return 0, framework.NewStatus(framework.Error, err.Error())
|
||||
}
|
||||
|
@@ -233,7 +233,7 @@ func TestTaintTolerationScore(t *testing.T) {
|
||||
fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot))
|
||||
|
||||
p, _ := New(nil, fh)
|
||||
status := p.(framework.PostFilterPlugin).PostFilter(context.Background(), state, test.pod, test.nodes, nil)
|
||||
status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes, nil)
|
||||
if !status.IsSuccess() {
|
||||
t.Errorf("unexpected error: %v", status)
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ const (
|
||||
preFilter = "PreFilter"
|
||||
preFilterExtensionAddPod = "PreFilterExtensionAddPod"
|
||||
preFilterExtensionRemovePod = "PreFilterExtensionRemovePod"
|
||||
postFilter = "PostFilter"
|
||||
preScore = "PreScore"
|
||||
score = "Score"
|
||||
scoreExtensionNormalize = "ScoreExtensionNormalize"
|
||||
preBind = "PreBind"
|
||||
@@ -67,7 +67,7 @@ type framework struct {
|
||||
queueSortPlugins []QueueSortPlugin
|
||||
preFilterPlugins []PreFilterPlugin
|
||||
filterPlugins []FilterPlugin
|
||||
postFilterPlugins []PostFilterPlugin
|
||||
preScorePlugins []PreScorePlugin
|
||||
scorePlugins []ScorePlugin
|
||||
reservePlugins []ReservePlugin
|
||||
preBindPlugins []PreBindPlugin
|
||||
@@ -103,7 +103,7 @@ func (f *framework) getExtensionPoints(plugins *config.Plugins) []extensionPoint
|
||||
{plugins.PreFilter, &f.preFilterPlugins},
|
||||
{plugins.Filter, &f.filterPlugins},
|
||||
{plugins.Reserve, &f.reservePlugins},
|
||||
{plugins.PostFilter, &f.postFilterPlugins},
|
||||
{plugins.PreScore, &f.preScorePlugins},
|
||||
{plugins.Score, &f.scorePlugins},
|
||||
{plugins.PreBind, &f.preBindPlugins},
|
||||
{plugins.Bind, &f.bindPlugins},
|
||||
@@ -461,10 +461,10 @@ func (f *framework) runFilterPlugin(ctx context.Context, pl FilterPlugin, state
|
||||
return status
|
||||
}
|
||||
|
||||
// RunPostFilterPlugins runs the set of configured post-filter plugins. If any
|
||||
// of these plugins returns any status other than "Success", the given node is
|
||||
// RunPreScorePlugins runs the set of configured pre-score plugins. If any
|
||||
// of these plugins returns any status other than "Success", the given pod is
|
||||
// rejected. The filteredNodeStatuses is the set of filtered nodes and their statuses.
|
||||
func (f *framework) RunPostFilterPlugins(
|
||||
func (f *framework) RunPreScorePlugins(
|
||||
ctx context.Context,
|
||||
state *CycleState,
|
||||
pod *v1.Pod,
|
||||
@@ -473,12 +473,12 @@ func (f *framework) RunPostFilterPlugins(
|
||||
) (status *Status) {
|
||||
startTime := time.Now()
|
||||
defer func() {
|
||||
metrics.FrameworkExtensionPointDuration.WithLabelValues(postFilter, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
|
||||
metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
|
||||
}()
|
||||
for _, pl := range f.postFilterPlugins {
|
||||
status = f.runPostFilterPlugin(ctx, pl, state, pod, nodes, filteredNodesStatuses)
|
||||
for _, pl := range f.preScorePlugins {
|
||||
status = f.runPreScorePlugin(ctx, pl, state, pod, nodes, filteredNodesStatuses)
|
||||
if !status.IsSuccess() {
|
||||
msg := fmt.Sprintf("error while running %q postfilter plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
|
||||
msg := fmt.Sprintf("error while running %q prescore plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
|
||||
klog.Error(msg)
|
||||
return NewStatus(Error, msg)
|
||||
}
|
||||
@@ -487,13 +487,13 @@ func (f *framework) RunPostFilterPlugins(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *framework) runPostFilterPlugin(ctx context.Context, pl PostFilterPlugin, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status {
|
||||
func (f *framework) runPreScorePlugin(ctx context.Context, pl PreScorePlugin, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status {
|
||||
if !state.ShouldRecordPluginMetrics() {
|
||||
return pl.PostFilter(ctx, state, pod, nodes, filteredNodesStatuses)
|
||||
return pl.PreScore(ctx, state, pod, nodes, filteredNodesStatuses)
|
||||
}
|
||||
startTime := time.Now()
|
||||
status := pl.PostFilter(ctx, state, pod, nodes, filteredNodesStatuses)
|
||||
f.metricsRecorder.observePluginDurationAsync(postFilter, pl.Name(), status, metrics.SinceInSeconds(startTime))
|
||||
status := pl.PreScore(ctx, state, pod, nodes, filteredNodesStatuses)
|
||||
f.metricsRecorder.observePluginDurationAsync(preScore, pl.Name(), status, metrics.SinceInSeconds(startTime))
|
||||
return status
|
||||
}
|
||||
|
||||
|
@@ -169,8 +169,8 @@ func (pl *TestPlugin) Filter(ctx context.Context, state *CycleState, pod *v1.Pod
|
||||
return NewStatus(Code(pl.inj.FilterStatus), "injected filter status")
|
||||
}
|
||||
|
||||
func (pl *TestPlugin) PostFilter(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status {
|
||||
return NewStatus(Code(pl.inj.PostFilterStatus), "injected status")
|
||||
func (pl *TestPlugin) PreScore(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status {
|
||||
return NewStatus(Code(pl.inj.PreScoreStatus), "injected status")
|
||||
}
|
||||
|
||||
func (pl *TestPlugin) Reserve(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) *Status {
|
||||
@@ -1328,9 +1328,9 @@ func TestRecordingMetrics(t *testing.T) {
|
||||
wantStatus: Success,
|
||||
},
|
||||
{
|
||||
name: "PostFilter - Success",
|
||||
action: func(f Framework) { f.RunPostFilterPlugins(context.Background(), state, pod, nil, nil) },
|
||||
wantExtensionPoint: "PostFilter",
|
||||
name: "PreScore - Success",
|
||||
action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil, nil) },
|
||||
wantExtensionPoint: "PreScore",
|
||||
wantStatus: Success,
|
||||
},
|
||||
{
|
||||
@@ -1384,10 +1384,10 @@ func TestRecordingMetrics(t *testing.T) {
|
||||
wantStatus: Error,
|
||||
},
|
||||
{
|
||||
name: "PostFilter - Error",
|
||||
action: func(f Framework) { f.RunPostFilterPlugins(context.Background(), state, pod, nil, nil) },
|
||||
inject: injectedResult{PostFilterStatus: int(Error)},
|
||||
wantExtensionPoint: "PostFilter",
|
||||
name: "PreScore - Error",
|
||||
action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil, nil) },
|
||||
inject: injectedResult{PreScoreStatus: int(Error)},
|
||||
wantExtensionPoint: "PreScore",
|
||||
wantStatus: Error,
|
||||
},
|
||||
{
|
||||
@@ -1441,16 +1441,16 @@ func TestRecordingMetrics(t *testing.T) {
|
||||
})
|
||||
pluginSet := &config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin, Weight: 1}}}
|
||||
plugins := &config.Plugins{
|
||||
Score: pluginSet,
|
||||
PreFilter: pluginSet,
|
||||
Filter: pluginSet,
|
||||
PostFilter: pluginSet,
|
||||
Reserve: pluginSet,
|
||||
Permit: pluginSet,
|
||||
PreBind: pluginSet,
|
||||
Bind: pluginSet,
|
||||
PostBind: pluginSet,
|
||||
Unreserve: pluginSet,
|
||||
Score: pluginSet,
|
||||
PreFilter: pluginSet,
|
||||
Filter: pluginSet,
|
||||
PreScore: pluginSet,
|
||||
Reserve: pluginSet,
|
||||
Permit: pluginSet,
|
||||
PreBind: pluginSet,
|
||||
Bind: pluginSet,
|
||||
PostBind: pluginSet,
|
||||
Unreserve: pluginSet,
|
||||
}
|
||||
recorder := newMetricsRecorder(100, time.Nanosecond)
|
||||
f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs, withMetricsRecorder(recorder))
|
||||
@@ -1682,7 +1682,7 @@ type injectedResult struct {
|
||||
PreFilterAddPodStatus int `json:"preFilterAddPodStatus,omitempty"`
|
||||
PreFilterRemovePodStatus int `json:"preFilterRemovePodStatus,omitempty"`
|
||||
FilterStatus int `json:"filterStatus,omitempty"`
|
||||
PostFilterStatus int `json:"postFilterStatus,omitempty"`
|
||||
PreScoreStatus int `json:"preScoreStatus,omitempty"`
|
||||
ReserveStatus int `json:"reserveStatus,omitempty"`
|
||||
PreBindStatus int `json:"preBindStatus,omitempty"`
|
||||
BindStatus int `json:"bindStatus,omitempty"`
|
||||
|
@@ -302,17 +302,17 @@ type FilterPlugin interface {
|
||||
Filter(ctx context.Context, state *CycleState, pod *v1.Pod, nodeInfo *schedulernodeinfo.NodeInfo) *Status
|
||||
}
|
||||
|
||||
// PostFilterPlugin is an interface for Post-filter plugin. Post-filter is an
|
||||
// PreScorePlugin is an interface for Pre-score plugin. Pre-score is an
|
||||
// informational extension point. Plugins will be called with a list of nodes
|
||||
// that passed the filtering phase. A plugin may use this data to update internal
|
||||
// state or to generate logs/metrics.
|
||||
type PostFilterPlugin interface {
|
||||
type PreScorePlugin interface {
|
||||
Plugin
|
||||
// PostFilter is called by the scheduling framework after a list of nodes
|
||||
// passed the filtering phase. All postfilter plugins must return success or
|
||||
// PreScore is called by the scheduling framework after a list of nodes
|
||||
// passed the filtering phase. All prescore plugins must return success or
|
||||
// the pod will be rejected. The filteredNodesStatuses is the set of filtered nodes
|
||||
// and their filter status.
|
||||
PostFilter(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status
|
||||
PreScore(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status
|
||||
}
|
||||
|
||||
// ScoreExtensions is an interface for Score extended functionality.
|
||||
@@ -438,10 +438,10 @@ type Framework interface {
|
||||
// status other than Success.
|
||||
RunPreFilterExtensionRemovePod(ctx context.Context, state *CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *schedulernodeinfo.NodeInfo) *Status
|
||||
|
||||
// RunPostFilterPlugins runs the set of configured post-filter plugins. If any
|
||||
// of these plugins returns any status other than "Success", the given node is
|
||||
// RunPreScorePlugins runs the set of configured pre-score plugins. If any
|
||||
// of these plugins returns any status other than "Success", the given pod is
|
||||
// rejected. The filteredNodeStatuses is the set of filtered nodes and their statuses.
|
||||
RunPostFilterPlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status
|
||||
RunPreScorePlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status
|
||||
|
||||
// RunScorePlugins runs the set of configured scoring plugins. It returns a map that
|
||||
// stores for each scoring plugin name the corresponding NodeScoreList(s).
|
||||
|
@@ -51,9 +51,9 @@ func RegisterScorePlugin(pluginName string, pluginNewFunc framework.PluginFactor
|
||||
return RegisterPluginAsExtensionsWithWeight(pluginName, weight, pluginNewFunc, "Score")
|
||||
}
|
||||
|
||||
// RegisterPostFilterPlugin returns a function to register a Score Plugin to a given registry.
|
||||
func RegisterPostFilterPlugin(pluginName string, pluginNewFunc framework.PluginFactory) RegisterPluginFunc {
|
||||
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "PostFilter")
|
||||
// RegisterPreScorePlugin returns a function to register a Score Plugin to a given registry.
|
||||
func RegisterPreScorePlugin(pluginName string, pluginNewFunc framework.PluginFactory) RegisterPluginFunc {
|
||||
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "PreScore")
|
||||
}
|
||||
|
||||
// RegisterBindPlugin returns a function to register a Bind Plugin to a given registry.
|
||||
@@ -91,8 +91,8 @@ func getPluginSetByExtension(plugins *schedulerapi.Plugins, extension string) *s
|
||||
return initializeIfNeeded(&plugins.Filter)
|
||||
case "PreFilter":
|
||||
return initializeIfNeeded(&plugins.PreFilter)
|
||||
case "PostFilter":
|
||||
return initializeIfNeeded(&plugins.PostFilter)
|
||||
case "PreScore":
|
||||
return initializeIfNeeded(&plugins.PreScore)
|
||||
case "Score":
|
||||
return initializeIfNeeded(&plugins.Score)
|
||||
case "Bind":
|
||||
|
@@ -163,8 +163,8 @@ type Plugins struct {
|
||||
// Filter is a list of plugins that should be invoked when filtering out nodes that cannot run the Pod.
|
||||
Filter *PluginSet `json:"filter,omitempty"`
|
||||
|
||||
// PostFilter is a list of plugins that are invoked after filtering out infeasible nodes.
|
||||
PostFilter *PluginSet `json:"postFilter,omitempty"`
|
||||
// PreScore is a list of plugins that are invoked before scoring.
|
||||
PreScore *PluginSet `json:"preScore,omitempty"`
|
||||
|
||||
// Score is a list of plugins that should be invoked when ranking nodes that have passed the filtering phase.
|
||||
Score *PluginSet `json:"score,omitempty"`
|
||||
|
@@ -213,8 +213,8 @@ func (in *Plugins) DeepCopyInto(out *Plugins) {
|
||||
*out = new(PluginSet)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.PostFilter != nil {
|
||||
in, out := &in.PostFilter, &out.PostFilter
|
||||
if in.PreScore != nil {
|
||||
in, out := &in.PreScore, &out.PreScore
|
||||
*out = new(PluginSet)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
|
@@ -62,9 +62,9 @@ type ReservePlugin struct {
|
||||
failReserve bool
|
||||
}
|
||||
|
||||
type PostFilterPlugin struct {
|
||||
numPostFilterCalled int
|
||||
failPostFilter bool
|
||||
type PreScorePlugin struct {
|
||||
numPreScoreCalled int
|
||||
failPreScore bool
|
||||
}
|
||||
|
||||
type PreBindPlugin struct {
|
||||
@@ -111,7 +111,7 @@ const (
|
||||
scorePluginName = "score-plugin"
|
||||
scoreWithNormalizePluginName = "score-with-normalize-plugin"
|
||||
filterPluginName = "filter-plugin"
|
||||
postFilterPluginName = "postfilter-plugin"
|
||||
preScorePluginName = "prescore-plugin"
|
||||
reservePluginName = "reserve-plugin"
|
||||
preBindPluginName = "prebind-plugin"
|
||||
unreservePluginName = "unreserve-plugin"
|
||||
@@ -125,7 +125,7 @@ var _ framework.FilterPlugin = &FilterPlugin{}
|
||||
var _ framework.ScorePlugin = &ScorePlugin{}
|
||||
var _ framework.ScorePlugin = &ScoreWithNormalizePlugin{}
|
||||
var _ framework.ReservePlugin = &ReservePlugin{}
|
||||
var _ framework.PostFilterPlugin = &PostFilterPlugin{}
|
||||
var _ framework.PreScorePlugin = &PreScorePlugin{}
|
||||
var _ framework.PreBindPlugin = &PreBindPlugin{}
|
||||
var _ framework.BindPlugin = &BindPlugin{}
|
||||
var _ framework.PostBindPlugin = &PostBindPlugin{}
|
||||
@@ -242,24 +242,24 @@ func (rp *ReservePlugin) reset() {
|
||||
}
|
||||
|
||||
// Name returns name of the plugin.
|
||||
func (*PostFilterPlugin) Name() string {
|
||||
return postFilterPluginName
|
||||
func (*PreScorePlugin) Name() string {
|
||||
return preScorePluginName
|
||||
}
|
||||
|
||||
// PostFilter is a test function.
|
||||
func (pfp *PostFilterPlugin) PostFilter(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, _ []*v1.Node, _ framework.NodeToStatusMap) *framework.Status {
|
||||
pfp.numPostFilterCalled++
|
||||
if pfp.failPostFilter {
|
||||
// PreScore is a test function.
|
||||
func (pfp *PreScorePlugin) PreScore(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, _ []*v1.Node, _ framework.NodeToStatusMap) *framework.Status {
|
||||
pfp.numPreScoreCalled++
|
||||
if pfp.failPreScore {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// reset used to reset postfilter plugin.
|
||||
func (pfp *PostFilterPlugin) reset() {
|
||||
pfp.numPostFilterCalled = 0
|
||||
pfp.failPostFilter = false
|
||||
// reset used to reset prescore plugin.
|
||||
func (pfp *PreScorePlugin) reset() {
|
||||
pfp.numPreScoreCalled = 0
|
||||
pfp.failPreScore = false
|
||||
}
|
||||
|
||||
// Name returns name of the plugin.
|
||||
@@ -1396,31 +1396,31 @@ func TestFilterPlugin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestPostFilterPlugin tests invocation of post-filter plugins.
|
||||
func TestPostFilterPlugin(t *testing.T) {
|
||||
// Create a plugin registry for testing. Register only a post-filter plugin.
|
||||
postFilterPlugin := &PostFilterPlugin{}
|
||||
registry := framework.Registry{postFilterPluginName: newPlugin(postFilterPlugin)}
|
||||
// TestPreScorePlugin tests invocation of pre-score plugins.
|
||||
func TestPreScorePlugin(t *testing.T) {
|
||||
// Create a plugin registry for testing. Register only a pre-score plugin.
|
||||
preScorePlugin := &PreScorePlugin{}
|
||||
registry := framework.Registry{preScorePluginName: newPlugin(preScorePlugin)}
|
||||
|
||||
// Setup initial post-filter plugin for testing.
|
||||
// Setup initial pre-score plugin for testing.
|
||||
plugins := &schedulerconfig.Plugins{
|
||||
PostFilter: &schedulerconfig.PluginSet{
|
||||
PreScore: &schedulerconfig.PluginSet{
|
||||
Enabled: []schedulerconfig.Plugin{
|
||||
{
|
||||
Name: postFilterPluginName,
|
||||
Name: preScorePluginName,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "post-filter-plugin", nil), 2,
|
||||
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "pre-score-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
||||
defer cleanupTest(t, testCtx)
|
||||
|
||||
for _, fail := range []bool{false, true} {
|
||||
postFilterPlugin.failPostFilter = fail
|
||||
preScorePlugin.failPreScore = fail
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(testCtx.clientSet,
|
||||
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
|
||||
@@ -1438,11 +1438,11 @@ func TestPostFilterPlugin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if postFilterPlugin.numPostFilterCalled == 0 {
|
||||
t.Errorf("Expected the post-filter plugin to be called.")
|
||||
if preScorePlugin.numPreScoreCalled == 0 {
|
||||
t.Errorf("Expected the pre-score plugin to be called.")
|
||||
}
|
||||
|
||||
postFilterPlugin.reset()
|
||||
preScorePlugin.reset()
|
||||
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
@@ -123,7 +123,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
@@ -209,7 +209,7 @@ kind: Policy
|
||||
{Name: "VolumeZone"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
"PostFilterPlugin": {
|
||||
"PreScorePlugin": {
|
||||
{Name: "InterPodAffinity"},
|
||||
{Name: "DefaultPodTopologySpread"},
|
||||
{Name: "TaintToleration"},
|
||||
|
Reference in New Issue
Block a user