mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #101619 from ikeeip/scheduler_framework_plugin_defaultpreemption_dependency
Scheduler: remove pkg/features dependency from DefaultPreemption plugin
This commit is contained in:
commit
a8035dbc3b
@ -33,17 +33,16 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
corelisters "k8s.io/client-go/listers/core/v1"
|
||||
policylisters "k8s.io/client-go/listers/policy/v1"
|
||||
corev1helpers "k8s.io/component-helpers/scheduling/corev1"
|
||||
extenderv1 "k8s.io/kube-scheduler/extender/v1"
|
||||
kubefeatures "k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config/validation"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature"
|
||||
"k8s.io/kubernetes/pkg/scheduler/metrics"
|
||||
"k8s.io/kubernetes/pkg/scheduler/util"
|
||||
)
|
||||
@ -69,7 +68,7 @@ func (pl *DefaultPreemption) Name() string {
|
||||
}
|
||||
|
||||
// New initializes a new plugin and returns it.
|
||||
func New(dpArgs runtime.Object, fh framework.Handle) (framework.Plugin, error) {
|
||||
func New(dpArgs runtime.Object, fh framework.Handle, fts feature.Features) (framework.Plugin, error) {
|
||||
args, ok := dpArgs.(*config.DefaultPreemptionArgs)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("got args of type %T, want *DefaultPreemptionArgs", dpArgs)
|
||||
@ -81,7 +80,7 @@ func New(dpArgs runtime.Object, fh framework.Handle) (framework.Plugin, error) {
|
||||
fh: fh,
|
||||
args: *args,
|
||||
podLister: fh.SharedInformerFactory().Core().V1().Pods().Lister(),
|
||||
pdbLister: getPDBLister(fh.SharedInformerFactory()),
|
||||
pdbLister: getPDBLister(fh.SharedInformerFactory(), fts.EnablePodDisruptionBudget),
|
||||
}
|
||||
return &pl, nil
|
||||
}
|
||||
@ -796,8 +795,8 @@ func filterPodsWithPDBViolation(podInfos []*framework.PodInfo, pdbs []*policy.Po
|
||||
return violatingPodInfos, nonViolatingPodInfos
|
||||
}
|
||||
|
||||
func getPDBLister(informerFactory informers.SharedInformerFactory) policylisters.PodDisruptionBudgetLister {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.PodDisruptionBudget) {
|
||||
func getPDBLister(informerFactory informers.SharedInformerFactory, enablePodDisruptionBudget bool) policylisters.PodDisruptionBudgetLister {
|
||||
if enablePodDisruptionBudget {
|
||||
return informerFactory.Policy().V1().PodDisruptionBudgets().Lister()
|
||||
}
|
||||
return nil
|
||||
|
@ -291,7 +291,7 @@ func TestPostFilter(t *testing.T) {
|
||||
p := DefaultPreemption{
|
||||
fh: f,
|
||||
podLister: informerFactory.Core().V1().Pods().Lister(),
|
||||
pdbLister: getPDBLister(informerFactory),
|
||||
pdbLister: getPDBLister(informerFactory, true),
|
||||
args: *getDefaultDefaultPreemptionArgs(),
|
||||
}
|
||||
|
||||
@ -1670,7 +1670,7 @@ func TestPreempt(t *testing.T) {
|
||||
pl := DefaultPreemption{
|
||||
fh: fwk,
|
||||
podLister: informerFactory.Core().V1().Pods().Lister(),
|
||||
pdbLister: getPDBLister(informerFactory),
|
||||
pdbLister: getPDBLister(informerFactory, true),
|
||||
args: *getDefaultDefaultPreemptionArgs(),
|
||||
}
|
||||
node, status := pl.preempt(context.Background(), state, test.pod, make(framework.NodeToStatusMap))
|
||||
|
@ -21,4 +21,5 @@ package feature
|
||||
// the internal k8s features pkg.
|
||||
type Features struct {
|
||||
EnablePodAffinityNamespaceSelector bool
|
||||
EnablePodDisruptionBudget bool
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import (
|
||||
func NewInTreeRegistry() runtime.Registry {
|
||||
fts := plfeature.Features{
|
||||
EnablePodAffinityNamespaceSelector: utilfeature.DefaultFeatureGate.Enabled(features.PodAffinityNamespaceSelector),
|
||||
EnablePodDisruptionBudget: utilfeature.DefaultFeatureGate.Enabled(features.PodDisruptionBudget),
|
||||
}
|
||||
|
||||
return runtime.Registry{
|
||||
@ -79,10 +80,12 @@ func NewInTreeRegistry() runtime.Registry {
|
||||
interpodaffinity.Name: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
||||
return interpodaffinity.New(plArgs, fh, fts)
|
||||
},
|
||||
nodelabel.Name: nodelabel.New,
|
||||
serviceaffinity.Name: serviceaffinity.New,
|
||||
queuesort.Name: queuesort.New,
|
||||
defaultbinder.Name: defaultbinder.New,
|
||||
defaultpreemption.Name: defaultpreemption.New,
|
||||
nodelabel.Name: nodelabel.New,
|
||||
serviceaffinity.Name: serviceaffinity.New,
|
||||
queuesort.Name: queuesort.New,
|
||||
defaultbinder.Name: defaultbinder.New,
|
||||
defaultpreemption.Name: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
||||
return defaultpreemption.New(plArgs, fh, fts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user