mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
run all PreFilter when the preemption will happen later in the same scheduling cycle
This commit is contained in:
parent
3be9a8cc73
commit
5ab2317947
@ -670,6 +670,7 @@ func (f *frameworkImpl) RunPreFilterPlugins(ctx context.Context, state *framewor
|
|||||||
if verboseLogs {
|
if verboseLogs {
|
||||||
logger = klog.LoggerWithName(logger, "PreFilter")
|
logger = klog.LoggerWithName(logger, "PreFilter")
|
||||||
}
|
}
|
||||||
|
var returnStatus *framework.Status
|
||||||
for _, pl := range f.preFilterPlugins {
|
for _, pl := range f.preFilterPlugins {
|
||||||
ctx := ctx
|
ctx := ctx
|
||||||
if verboseLogs {
|
if verboseLogs {
|
||||||
@ -684,8 +685,17 @@ func (f *frameworkImpl) RunPreFilterPlugins(ctx context.Context, state *framewor
|
|||||||
if !s.IsSuccess() {
|
if !s.IsSuccess() {
|
||||||
s.SetPlugin(pl.Name())
|
s.SetPlugin(pl.Name())
|
||||||
if s.IsRejected() {
|
if s.IsRejected() {
|
||||||
|
if s.Code() == framework.UnschedulableAndUnresolvable {
|
||||||
|
// In this case, the preemption shouldn't happen in this scheduling cycle.
|
||||||
|
// So, no need to execute all PreFilter.
|
||||||
return nil, s
|
return nil, s
|
||||||
}
|
}
|
||||||
|
// In this case, the preemption should happen later in this scheduling cycle.
|
||||||
|
// So we need to execute all PreFilter.
|
||||||
|
// https://github.com/kubernetes/kubernetes/issues/119770
|
||||||
|
returnStatus = s
|
||||||
|
continue
|
||||||
|
}
|
||||||
return nil, framework.AsStatus(fmt.Errorf("running PreFilter plugin %q: %w", pl.Name(), s.AsError())).WithPlugin(pl.Name())
|
return nil, framework.AsStatus(fmt.Errorf("running PreFilter plugin %q: %w", pl.Name(), s.AsError())).WithPlugin(pl.Name())
|
||||||
}
|
}
|
||||||
if !r.AllNodes() {
|
if !r.AllNodes() {
|
||||||
@ -697,10 +707,14 @@ func (f *frameworkImpl) RunPreFilterPlugins(ctx context.Context, state *framewor
|
|||||||
if len(pluginsWithNodes) == 1 {
|
if len(pluginsWithNodes) == 1 {
|
||||||
msg = fmt.Sprintf("node(s) didn't satisfy plugin %v", pluginsWithNodes[0])
|
msg = fmt.Sprintf("node(s) didn't satisfy plugin %v", pluginsWithNodes[0])
|
||||||
}
|
}
|
||||||
return nil, framework.NewStatus(framework.Unschedulable, msg)
|
// In this case, the preemption should happen later in this scheduling cycle.
|
||||||
|
// So we need to execute all PreFilter.
|
||||||
|
// https://github.com/kubernetes/kubernetes/issues/119770
|
||||||
|
returnStatus = framework.NewStatus(framework.Unschedulable, msg)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, returnStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *frameworkImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
|
func (f *frameworkImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
|
||||||
|
@ -197,7 +197,7 @@ func (pl *TestPlugin) ScoreExtensions() framework.ScoreExtensions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pl *TestPlugin) PreFilter(ctx context.Context, state *framework.CycleState, p *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
|
func (pl *TestPlugin) PreFilter(ctx context.Context, state *framework.CycleState, p *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
|
||||||
return nil, framework.NewStatus(framework.Code(pl.inj.PreFilterStatus), injectReason)
|
return pl.inj.PreFilterResult, framework.NewStatus(framework.Code(pl.inj.PreFilterStatus), injectReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pl *TestPlugin) PreFilterExtensions() framework.PreFilterExtensions {
|
func (pl *TestPlugin) PreFilterExtensions() framework.PreFilterExtensions {
|
||||||
@ -1622,6 +1622,56 @@ func TestRunPreFilterPlugins(t *testing.T) {
|
|||||||
wantSkippedPlugins: sets.New("skip1", "skip2"),
|
wantSkippedPlugins: sets.New("skip1", "skip2"),
|
||||||
wantStatusCode: framework.Success,
|
wantStatusCode: framework.Success,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "one PreFilter plugin returned Unschedulable, but another PreFilter plugin should be executed",
|
||||||
|
plugins: []*TestPlugin{
|
||||||
|
{
|
||||||
|
name: "unschedulable",
|
||||||
|
inj: injectedResult{PreFilterStatus: int(framework.Unschedulable)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// to make sure this plugin is executed, this plugin return Skip and we confirm it via wantSkippedPlugins.
|
||||||
|
name: "skip",
|
||||||
|
inj: injectedResult{PreFilterStatus: int(framework.Skip)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantPreFilterResult: nil,
|
||||||
|
wantSkippedPlugins: sets.New("skip"),
|
||||||
|
wantStatusCode: framework.Unschedulable,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "one PreFilter plugin returned UnschedulableAndUnresolvable, and all other plugins aren't executed",
|
||||||
|
plugins: []*TestPlugin{
|
||||||
|
{
|
||||||
|
name: "unresolvable",
|
||||||
|
inj: injectedResult{PreFilterStatus: int(framework.UnschedulableAndUnresolvable)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// to make sure this plugin is not executed, this plugin return Skip and we confirm it via wantSkippedPlugins.
|
||||||
|
name: "skip",
|
||||||
|
inj: injectedResult{PreFilterStatus: int(framework.Skip)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantPreFilterResult: nil,
|
||||||
|
wantStatusCode: framework.UnschedulableAndUnresolvable,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "all nodes are filtered out by prefilter result, but all other plugins are executed",
|
||||||
|
plugins: []*TestPlugin{
|
||||||
|
{
|
||||||
|
name: "reject-all-nodes",
|
||||||
|
inj: injectedResult{PreFilterResult: &framework.PreFilterResult{NodeNames: sets.New[string]()}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// to make sure this plugin is not executed, this plugin return Skip and we confirm it via wantSkippedPlugins.
|
||||||
|
name: "skip",
|
||||||
|
inj: injectedResult{PreFilterStatus: int(framework.Skip)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantPreFilterResult: &framework.PreFilterResult{NodeNames: sets.New[string]()},
|
||||||
|
wantSkippedPlugins: sets.New("skip"),
|
||||||
|
wantStatusCode: framework.Unschedulable,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@ -3228,6 +3278,7 @@ type injectedResult struct {
|
|||||||
NormalizeRes int64 `json:"normalizeRes,omitempty"`
|
NormalizeRes int64 `json:"normalizeRes,omitempty"`
|
||||||
ScoreStatus int `json:"scoreStatus,omitempty"`
|
ScoreStatus int `json:"scoreStatus,omitempty"`
|
||||||
NormalizeStatus int `json:"normalizeStatus,omitempty"`
|
NormalizeStatus int `json:"normalizeStatus,omitempty"`
|
||||||
|
PreFilterResult *framework.PreFilterResult `json:"preFilterResult,omitempty"`
|
||||||
PreFilterStatus int `json:"preFilterStatus,omitempty"`
|
PreFilterStatus int `json:"preFilterStatus,omitempty"`
|
||||||
PreFilterAddPodStatus int `json:"preFilterAddPodStatus,omitempty"`
|
PreFilterAddPodStatus int `json:"preFilterAddPodStatus,omitempty"`
|
||||||
PreFilterRemovePodStatus int `json:"preFilterRemovePodStatus,omitempty"`
|
PreFilterRemovePodStatus int `json:"preFilterRemovePodStatus,omitempty"`
|
||||||
|
Loading…
Reference in New Issue
Block a user