Files
kubernetes/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption.go
Wei Huang 196056d7fe Introduce a defaultpreemption PostFilter plugin
- Add a defaultpreemption PostFilter plugin
- Make g.Preempt() stateless
    - make g.Preempt() stateless
    - make g.getLowerPriorityNominatedPods() stateless
    - make g.processPreemptionWithExtenders() stateless
2020-06-19 09:13:55 -07:00

62 lines
1.9 KiB
Go

/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package defaultpreemption
import (
"context"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/scheduler/core"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
)
const (
// Name of the plugin used in the plugin registry and configurations.
Name = "DefaultPreemption"
)
// DefaultPreemption is a PostFilter plugin implements the preemption logic.
type DefaultPreemption struct {
fh framework.FrameworkHandle
}
var _ framework.PostFilterPlugin = &DefaultPreemption{}
// Name returns name of the plugin. It is used in logs, etc.
func (pl *DefaultPreemption) Name() string {
return Name
}
// New initializes a new plugin and returns it.
func New(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
pl := DefaultPreemption{fh}
return &pl, nil
}
// PostFilter invoked at the postFilter extension point.
func (pl *DefaultPreemption) PostFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, m framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) {
nnn, err := core.Preempt(ctx, pl.fh, state, pod, m)
if err != nil {
return nil, framework.NewStatus(framework.Error, err.Error())
}
if nnn == "" {
return nil, framework.NewStatus(framework.Unschedulable)
}
return &framework.PostFilterResult{NominatedNodeName: nnn}, framework.NewStatus(framework.Success)
}