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