mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
fixup: add podLister as a member field of DefaultPreemption
This commit is contained in:
parent
52bf6ba8ba
commit
4f7ae54f3e
@ -24,6 +24,7 @@ go_library(
|
||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/informers:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/policy/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/kube-scheduler/extender/v1:go_default_library",
|
||||
"//vendor/k8s.io/klog/v2:go_default_library",
|
||||
|
@ -33,6 +33,7 @@ import (
|
||||
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/v1beta1"
|
||||
extenderv1 "k8s.io/kube-scheduler/extender/v1"
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
@ -52,6 +53,7 @@ const (
|
||||
// DefaultPreemption is a PostFilter plugin implements the preemption logic.
|
||||
type DefaultPreemption struct {
|
||||
fh framework.FrameworkHandle
|
||||
podLister corelisters.PodLister
|
||||
pdbLister policylisters.PodDisruptionBudgetLister
|
||||
}
|
||||
|
||||
@ -66,6 +68,7 @@ func (pl *DefaultPreemption) Name() string {
|
||||
func New(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
|
||||
pl := DefaultPreemption{
|
||||
fh: fh,
|
||||
podLister: fh.SharedInformerFactory().Core().V1().Pods().Lister(),
|
||||
pdbLister: getPDBLister(fh.SharedInformerFactory()),
|
||||
}
|
||||
return &pl, nil
|
||||
@ -109,7 +112,7 @@ func (pl *DefaultPreemption) preempt(ctx context.Context, state *framework.Cycle
|
||||
// It's safe to directly fetch pod here. Because the informer cache has already been
|
||||
// initialized when creating the Scheduler obj, i.e., factory.go#MakeDefaultErrorFunc().
|
||||
// However, tests may need to manually initialize the shared pod informer.
|
||||
pod, err := pl.fh.SharedInformerFactory().Core().V1().Pods().Lister().Pods(pod.Namespace).Get(pod.Name)
|
||||
pod, err := pl.podLister.Pods(pod.Namespace).Get(pod.Name)
|
||||
if err != nil {
|
||||
klog.Errorf("Error getting the updated preemptor pod object: %v", err)
|
||||
return "", err
|
||||
|
@ -218,6 +218,11 @@ func TestPostFilter(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := DefaultPreemption{
|
||||
fh: f,
|
||||
podLister: informerFactory.Core().V1().Pods().Lister(),
|
||||
pdbLister: getPDBLister(informerFactory),
|
||||
}
|
||||
|
||||
state := framework.NewCycleState()
|
||||
// Ensure <state> is populated.
|
||||
@ -225,10 +230,6 @@ func TestPostFilter(t *testing.T) {
|
||||
t.Errorf("Unexpected PreFilter Status: %v", status)
|
||||
}
|
||||
|
||||
p := DefaultPreemption{
|
||||
fh: f,
|
||||
pdbLister: getPDBLister(informerFactory),
|
||||
}
|
||||
gotResult, gotStatus := p.PostFilter(context.TODO(), state, tt.pod, tt.filteredNodesStatuses)
|
||||
if !reflect.DeepEqual(gotStatus, tt.wantStatus) {
|
||||
t.Errorf("Status does not match: %v, want: %v", gotStatus, tt.wantStatus)
|
||||
@ -1307,6 +1308,7 @@ func TestPreempt(t *testing.T) {
|
||||
// Call preempt and check the expected results.
|
||||
pl := DefaultPreemption{
|
||||
fh: fwk,
|
||||
podLister: informerFactory.Core().V1().Pods().Lister(),
|
||||
pdbLister: getPDBLister(informerFactory),
|
||||
}
|
||||
node, err := pl.preempt(context.Background(), state, test.pod, make(framework.NodeToStatusMap))
|
||||
|
Loading…
Reference in New Issue
Block a user