From c10e6d6c129b0db29415fb2043e4b8b07532ecab Mon Sep 17 00:00:00 2001 From: sunxiaofei Date: Thu, 22 Sep 2022 16:02:13 +0800 Subject: [PATCH] fix sharedInformerFactory register --- pkg/descheduler/descheduler.go | 39 +++++++++---------- pkg/descheduler/node/node.go | 6 +-- pkg/descheduler/node/node_test.go | 8 ++-- pkg/descheduler/pod/pods.go | 7 ++-- pkg/descheduler/pod/pods_test.go | 2 +- .../plugins/defaultevictor/defaultevictor.go | 2 +- .../defaultevictor/defaultevictor_test.go | 4 +- .../highnodeutilization_test.go | 4 +- .../lownodeutilization_test.go | 4 +- .../plugins/podlifetime/pod_lifetime_test.go | 2 +- .../removeduplicates/removeduplicates_test.go | 4 +- .../removefailedpods/failedpods_test.go | 2 +- .../toomanyrestarts_test.go | 2 +- .../pod_antiaffinity_test.go | 2 +- .../node_affinity_test.go | 2 +- .../node_taint_test.go | 2 +- .../topologyspreadconstraint_test.go | 2 +- test/e2e/e2e_test.go | 28 ++++++------- 18 files changed, 59 insertions(+), 63 deletions(-) diff --git a/pkg/descheduler/descheduler.go b/pkg/descheduler/descheduler.go index b2a887c37b..58ed255117 100644 --- a/pkg/descheduler/descheduler.go +++ b/pkg/descheduler/descheduler.go @@ -29,10 +29,10 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/informers" - corev1informers "k8s.io/client-go/informers/core/v1" - schedulingv1informers "k8s.io/client-go/informers/scheduling/v1" clientset "k8s.io/client-go/kubernetes" fakeclientset "k8s.io/client-go/kubernetes/fake" + listersv1 "k8s.io/client-go/listers/core/v1" + schedulingv1 "k8s.io/client-go/listers/scheduling/v1" core "k8s.io/client-go/testing" "sigs.k8s.io/descheduler/cmd/descheduler/app/options" @@ -93,10 +93,10 @@ type strategyFunction func(ctx context.Context, client clientset.Interface, stra func cachedClient( realClient clientset.Interface, - podInformer corev1informers.PodInformer, - nodeInformer corev1informers.NodeInformer, - namespaceInformer corev1informers.NamespaceInformer, - priorityClassInformer schedulingv1informers.PriorityClassInformer, + podLister listersv1.PodLister, + nodeLister listersv1.NodeLister, + namespaceLister listersv1.NamespaceLister, + priorityClassLister schedulingv1.PriorityClassLister, ) (clientset.Interface, error) { fakeClient := fakeclientset.NewSimpleClientset() // simulate a pod eviction by deleting a pod @@ -120,7 +120,7 @@ func cachedClient( }) klog.V(3).Infof("Pulling resources for the cached client from the cluster") - pods, err := podInformer.Lister().List(labels.Everything()) + pods, err := podLister.List(labels.Everything()) if err != nil { return nil, fmt.Errorf("unable to list pods: %v", err) } @@ -131,7 +131,7 @@ func cachedClient( } } - nodes, err := nodeInformer.Lister().List(labels.Everything()) + nodes, err := nodeLister.List(labels.Everything()) if err != nil { return nil, fmt.Errorf("unable to list nodes: %v", err) } @@ -142,7 +142,7 @@ func cachedClient( } } - namespaces, err := namespaceInformer.Lister().List(labels.Everything()) + namespaces, err := namespaceLister.List(labels.Everything()) if err != nil { return nil, fmt.Errorf("unable to list namespaces: %v", err) } @@ -153,7 +153,7 @@ func cachedClient( } } - priorityClasses, err := priorityClassInformer.Lister().List(labels.Everything()) + priorityClasses, err := priorityClassLister.List(labels.Everything()) if err != nil { return nil, fmt.Errorf("unable to list priorityclasses: %v", err) } @@ -227,18 +227,15 @@ func (hi *handleImpl) Evictor() framework.Evictor { func RunDeschedulerStrategies(ctx context.Context, rs *options.DeschedulerServer, deschedulerPolicy *api.DeschedulerPolicy, evictionPolicyGroupVersion string) error { sharedInformerFactory := informers.NewSharedInformerFactory(rs.Client, 0) - nodeInformer := sharedInformerFactory.Core().V1().Nodes() - podInformer := sharedInformerFactory.Core().V1().Pods() - namespaceInformer := sharedInformerFactory.Core().V1().Namespaces() - priorityClassInformer := sharedInformerFactory.Scheduling().V1().PriorityClasses() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() + podLister := sharedInformerFactory.Core().V1().Pods().Lister() + nodeLister := sharedInformerFactory.Core().V1().Nodes().Lister() + namespaceLister := sharedInformerFactory.Core().V1().Namespaces().Lister() + priorityClassLister := sharedInformerFactory.Scheduling().V1().PriorityClasses().Lister() ctx, cancel := context.WithCancel(ctx) defer cancel() - // create the informers - namespaceInformer.Informer() - priorityClassInformer.Informer() - getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { return fmt.Errorf("build get pods assigned to node function error: %v", err) @@ -302,7 +299,7 @@ func RunDeschedulerStrategies(ctx context.Context, rs *options.DeschedulerServer defer eventBroadcaster.Shutdown() wait.NonSlidingUntil(func() { - nodes, err := nodeutil.ReadyNodes(ctx, rs.Client, nodeInformer, nodeSelector) + nodes, err := nodeutil.ReadyNodes(ctx, rs.Client, nodeLister, nodeSelector) if err != nil { klog.V(1).InfoS("Unable to get ready nodes", "err", err) cancel() @@ -322,14 +319,14 @@ func RunDeschedulerStrategies(ctx context.Context, rs *options.DeschedulerServer if rs.DryRun { klog.V(3).Infof("Building a cached client from the cluster for the dry run") // Create a new cache so we start from scratch without any leftovers - fakeClient, err := cachedClient(rs.Client, podInformer, nodeInformer, namespaceInformer, priorityClassInformer) + fakeClient, err := cachedClient(rs.Client, podLister, nodeLister, namespaceLister, priorityClassLister) if err != nil { klog.Error(err) return } fakeSharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - getPodsAssignedToNode, err = podutil.BuildGetPodsAssignedToNodeFunc(fakeSharedInformerFactory.Core().V1().Pods()) + getPodsAssignedToNode, err = podutil.BuildGetPodsAssignedToNodeFunc(fakeSharedInformerFactory.Core().V1().Pods().Informer()) if err != nil { klog.Errorf("build get pods assigned to node function error: %v", err) return diff --git a/pkg/descheduler/node/node.go b/pkg/descheduler/node/node.go index c476ec98ed..bdf00eeb6b 100644 --- a/pkg/descheduler/node/node.go +++ b/pkg/descheduler/node/node.go @@ -24,8 +24,8 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - coreinformers "k8s.io/client-go/informers/core/v1" clientset "k8s.io/client-go/kubernetes" + listersv1 "k8s.io/client-go/listers/core/v1" "k8s.io/klog/v2" podutil "sigs.k8s.io/descheduler/pkg/descheduler/pod" "sigs.k8s.io/descheduler/pkg/utils" @@ -33,7 +33,7 @@ import ( // ReadyNodes returns ready nodes irrespective of whether they are // schedulable or not. -func ReadyNodes(ctx context.Context, client clientset.Interface, nodeInformer coreinformers.NodeInformer, nodeSelector string) ([]*v1.Node, error) { +func ReadyNodes(ctx context.Context, client clientset.Interface, nodeLister listersv1.NodeLister, nodeSelector string) ([]*v1.Node, error) { ns, err := labels.Parse(nodeSelector) if err != nil { return []*v1.Node{}, err @@ -41,7 +41,7 @@ func ReadyNodes(ctx context.Context, client clientset.Interface, nodeInformer co var nodes []*v1.Node // err is defined above - if nodes, err = nodeInformer.Lister().List(ns); err != nil { + if nodes, err = nodeLister.List(ns); err != nil { return []*v1.Node{}, err } diff --git a/pkg/descheduler/node/node_test.go b/pkg/descheduler/node/node_test.go index bd22542ecb..a53646ecaa 100644 --- a/pkg/descheduler/node/node_test.go +++ b/pkg/descheduler/node/node_test.go @@ -70,14 +70,14 @@ func TestReadyNodesWithNodeSelector(t *testing.T) { nodeSelector := "type=compute" sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - nodeInformer := sharedInformerFactory.Core().V1().Nodes() + nodeLister := sharedInformerFactory.Core().V1().Nodes().Lister() stopChannel := make(chan struct{}) sharedInformerFactory.Start(stopChannel) sharedInformerFactory.WaitForCacheSync(stopChannel) defer close(stopChannel) - nodes, _ := ReadyNodes(ctx, fakeClient, nodeInformer, nodeSelector) + nodes, _ := ReadyNodes(ctx, fakeClient, nodeLister, nodeSelector) if nodes[0].Name != "node1" { t.Errorf("Expected node1, got %s", nodes[0].Name) @@ -207,7 +207,7 @@ func TestPodFitsCurrentNode(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { @@ -737,7 +737,7 @@ func TestPodFitsAnyOtherNode(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/descheduler/pod/pods.go b/pkg/descheduler/pod/pods.go index 15390ec43e..4f00116844 100644 --- a/pkg/descheduler/pod/pods.go +++ b/pkg/descheduler/pod/pods.go @@ -23,7 +23,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/sets" - coreinformers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/tools/cache" "sigs.k8s.io/descheduler/pkg/utils" @@ -118,9 +117,9 @@ func (o *Options) BuildFilterFunc() (FilterFunc, error) { // BuildGetPodsAssignedToNodeFunc establishes an indexer to map the pods and their assigned nodes. // It returns a function to help us get all the pods that assigned to a node based on the indexer. -func BuildGetPodsAssignedToNodeFunc(podInformer coreinformers.PodInformer) (GetPodsAssignedToNodeFunc, error) { +func BuildGetPodsAssignedToNodeFunc(podInformer cache.SharedIndexInformer) (GetPodsAssignedToNodeFunc, error) { // Establish an indexer to map the pods and their assigned nodes. - err := podInformer.Informer().AddIndexers(cache.Indexers{ + err := podInformer.AddIndexers(cache.Indexers{ nodeNameKeyIndex: func(obj interface{}) ([]string, error) { pod, ok := obj.(*v1.Pod) if !ok { @@ -137,7 +136,7 @@ func BuildGetPodsAssignedToNodeFunc(podInformer coreinformers.PodInformer) (GetP } // The indexer helps us get all the pods that assigned to a node. - podIndexer := podInformer.Informer().GetIndexer() + podIndexer := podInformer.GetIndexer() getPodsAssignedToNode := func(nodeName string, filter FilterFunc) ([]*v1.Pod, error) { objs, err := podIndexer.ByIndex(nodeNameKeyIndex, nodeName) if err != nil { diff --git a/pkg/descheduler/pod/pods_test.go b/pkg/descheduler/pod/pods_test.go index d5ec097d5c..5aef6c3b03 100644 --- a/pkg/descheduler/pod/pods_test.go +++ b/pkg/descheduler/pod/pods_test.go @@ -94,7 +94,7 @@ func TestListPodsOnANode(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/defaultevictor/defaultevictor.go b/pkg/framework/plugins/defaultevictor/defaultevictor.go index 8717fcdd48..ee2e7df600 100644 --- a/pkg/framework/plugins/defaultevictor/defaultevictor.go +++ b/pkg/framework/plugins/defaultevictor/defaultevictor.go @@ -149,7 +149,7 @@ func (d *DefaultEvictor) Name() string { func (d *DefaultEvictor) PreEvictionFilter(pod *v1.Pod) bool { defaultEvictorArgs := d.args.(*DefaultEvictorArgs) if defaultEvictorArgs.NodeFit { - nodes, err := nodeutil.ReadyNodes(context.TODO(), d.handle.ClientSet(), d.handle.SharedInformerFactory().Core().V1().Nodes(), defaultEvictorArgs.NodeSelector) + nodes, err := nodeutil.ReadyNodes(context.TODO(), d.handle.ClientSet(), d.handle.SharedInformerFactory().Core().V1().Nodes().Lister(), defaultEvictorArgs.NodeSelector) if err != nil { klog.V(1).ErrorS(fmt.Errorf("Pod fails the following checks"), "pod", klog.KObj(pod)) return false diff --git a/pkg/framework/plugins/defaultevictor/defaultevictor_test.go b/pkg/framework/plugins/defaultevictor/defaultevictor_test.go index cf36b23518..262f747259 100644 --- a/pkg/framework/plugins/defaultevictor/defaultevictor_test.go +++ b/pkg/framework/plugins/defaultevictor/defaultevictor_test.go @@ -316,7 +316,7 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { @@ -722,7 +722,7 @@ func TestDefaultEvictorFilter(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/nodeutilization/highnodeutilization_test.go b/pkg/framework/plugins/nodeutilization/highnodeutilization_test.go index 1ba9b9e221..a4053f8f5a 100644 --- a/pkg/framework/plugins/nodeutilization/highnodeutilization_test.go +++ b/pkg/framework/plugins/nodeutilization/highnodeutilization_test.go @@ -451,7 +451,7 @@ func TestHighNodeUtilization(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { @@ -625,7 +625,7 @@ func TestHighNodeUtilizationWithTaints(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/nodeutilization/lownodeutilization_test.go b/pkg/framework/plugins/nodeutilization/lownodeutilization_test.go index eccffefb69..30f5401a6b 100644 --- a/pkg/framework/plugins/nodeutilization/lownodeutilization_test.go +++ b/pkg/framework/plugins/nodeutilization/lownodeutilization_test.go @@ -717,7 +717,7 @@ func TestLowNodeUtilization(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { @@ -911,7 +911,7 @@ func TestLowNodeUtilizationWithTaints(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 63e05549f1..5e859bd651 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -334,7 +334,7 @@ func TestPodLifeTime(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 1c25b82d00..ec022a9d61 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -301,7 +301,7 @@ func TestFindDuplicatePods(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { @@ -751,7 +751,7 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/removefailedpods/failedpods_test.go b/pkg/framework/plugins/removefailedpods/failedpods_test.go index 624e0c483f..561f97066a 100644 --- a/pkg/framework/plugins/removefailedpods/failedpods_test.go +++ b/pkg/framework/plugins/removefailedpods/failedpods_test.go @@ -279,7 +279,7 @@ func TestRemoveFailedPods(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index a975f343dc..78650f8a94 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -240,7 +240,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 094338c633..eacc704755 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -205,7 +205,7 @@ func TestPodAntiAffinity(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go b/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go index 2adbd70335..221e919dfd 100644 --- a/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go +++ b/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go @@ -204,7 +204,7 @@ func TestRemovePodsViolatingNodeAffinity(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/removepodsviolatingnodetaints/node_taint_test.go b/pkg/framework/plugins/removepodsviolatingnodetaints/node_taint_test.go index bddf0bfebb..a778bffe44 100644 --- a/pkg/framework/plugins/removepodsviolatingnodetaints/node_taint_test.go +++ b/pkg/framework/plugins/removepodsviolatingnodetaints/node_taint_test.go @@ -341,7 +341,7 @@ func TestDeletePodsViolatingNodeTaints(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/pkg/framework/plugins/removepodsviolatingtopologyspreadconstraint/topologyspreadconstraint_test.go b/pkg/framework/plugins/removepodsviolatingtopologyspreadconstraint/topologyspreadconstraint_test.go index 86dcf37bd4..e2158ede50 100644 --- a/pkg/framework/plugins/removepodsviolatingtopologyspreadconstraint/topologyspreadconstraint_test.go +++ b/pkg/framework/plugins/removepodsviolatingtopologyspreadconstraint/topologyspreadconstraint_test.go @@ -1136,7 +1136,7 @@ func TestTopologySpreadConstraint(t *testing.T) { fakeClient := fake.NewSimpleClientset(objs...) sharedInformerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - podInformer := sharedInformerFactory.Core().V1().Pods() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 770aefa73c..aa62b6c3e2 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -34,8 +34,8 @@ import ( "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/informers" - coreinformers "k8s.io/client-go/informers/core/v1" clientset "k8s.io/client-go/kubernetes" + listersv1 "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/events" "k8s.io/utils/pointer" "sigs.k8s.io/descheduler/cmd/descheduler/app/options" @@ -110,7 +110,7 @@ func RcByNameContainer(name, namespace string, replicas int32, labels map[string } } -func initializeClient(t *testing.T) (clientset.Interface, informers.SharedInformerFactory, coreinformers.NodeInformer, podutil.GetPodsAssignedToNodeFunc, chan struct{}) { +func initializeClient(t *testing.T) (clientset.Interface, informers.SharedInformerFactory, listersv1.NodeLister, podutil.GetPodsAssignedToNodeFunc, chan struct{}) { clientSet, err := client.CreateClient(os.Getenv("KUBECONFIG"), "") if err != nil { t.Errorf("Error during client creation with %v", err) @@ -119,8 +119,8 @@ func initializeClient(t *testing.T) (clientset.Interface, informers.SharedInform stopChannel := make(chan struct{}) sharedInformerFactory := informers.NewSharedInformerFactory(clientSet, 0) - nodeInformer := sharedInformerFactory.Core().V1().Nodes() - podInformer := sharedInformerFactory.Core().V1().Pods() + nodeLister := sharedInformerFactory.Core().V1().Nodes().Lister() + podInformer := sharedInformerFactory.Core().V1().Pods().Informer() getPodsAssignedToNode, err := podutil.BuildGetPodsAssignedToNodeFunc(podInformer) if err != nil { @@ -130,18 +130,18 @@ func initializeClient(t *testing.T) (clientset.Interface, informers.SharedInform sharedInformerFactory.Start(stopChannel) sharedInformerFactory.WaitForCacheSync(stopChannel) - waitForNodesReady(context.Background(), t, clientSet, nodeInformer) - return clientSet, sharedInformerFactory, nodeInformer, getPodsAssignedToNode, stopChannel + waitForNodesReady(context.Background(), t, clientSet, nodeLister) + return clientSet, sharedInformerFactory, nodeLister, getPodsAssignedToNode, stopChannel } -func waitForNodesReady(ctx context.Context, t *testing.T, clientSet clientset.Interface, nodeInformer coreinformers.NodeInformer) { +func waitForNodesReady(ctx context.Context, t *testing.T, clientSet clientset.Interface, nodeLister listersv1.NodeLister) { if err := wait.PollImmediate(5*time.Second, 30*time.Second, func() (bool, error) { nodeList, err := clientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) if err != nil { return false, err } - readyNodes, err := nodeutil.ReadyNodes(ctx, clientSet, nodeInformer, "") + readyNodes, err := nodeutil.ReadyNodes(ctx, clientSet, nodeLister, "") if err != nil { return false, err } @@ -160,7 +160,7 @@ func runPodLifetimePlugin( ctx context.Context, t *testing.T, clientset clientset.Interface, - nodeInformer coreinformers.NodeInformer, + nodeLister listersv1.NodeLister, namespaces *deschedulerapi.Namespaces, priorityClass string, priority *int32, @@ -174,7 +174,7 @@ func runPodLifetimePlugin( t.Fatalf("%v", err) } - nodes, err := nodeutil.ReadyNodes(ctx, clientset, nodeInformer, "") + nodes, err := nodeutil.ReadyNodes(ctx, clientset, nodeLister, "") if err != nil { t.Fatalf("%v", err) } @@ -930,7 +930,7 @@ func TestPodLabelSelector(t *testing.T) { func TestEvictAnnotation(t *testing.T) { ctx := context.Background() - clientSet, _, nodeInformer, getPodsAssignedToNode, stopCh := initializeClient(t) + clientSet, _, nodeLister, getPodsAssignedToNode, stopCh := initializeClient(t) defer close(stopCh) testNamespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "e2e-" + strings.ToLower(t.Name())}} @@ -975,7 +975,7 @@ func TestEvictAnnotation(t *testing.T) { t.Logf("Existing pods: %v", initialPodNames) t.Log("Running PodLifetime plugin") - runPodLifetimePlugin(ctx, t, clientSet, nodeInformer, nil, "", nil, false, nil, nil, getPodsAssignedToNode) + runPodLifetimePlugin(ctx, t, clientSet, nodeLister, nil, "", nil, false, nil, nil, getPodsAssignedToNode) if err := wait.PollImmediate(5*time.Second, time.Minute, func() (bool, error) { podList, err = clientSet.CoreV1().Pods(rc.Namespace).List(ctx, metav1.ListOptions{LabelSelector: labels.SelectorFromSet(rc.Spec.Template.Labels).String()}) @@ -1002,7 +1002,7 @@ func TestEvictAnnotation(t *testing.T) { func TestPodLifeTimeOldestEvicted(t *testing.T) { ctx := context.Background() - clientSet, _, nodeInformer, getPodsAssignedToNode, stopCh := initializeClient(t) + clientSet, _, nodeLister, getPodsAssignedToNode, stopCh := initializeClient(t) defer close(stopCh) testNamespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "e2e-" + strings.ToLower(t.Name())}} @@ -1041,7 +1041,7 @@ func TestPodLifeTimeOldestEvicted(t *testing.T) { t.Log("Running PodLifetime plugin with maxPodsToEvictPerNamespace=1 to ensure only the oldest pod is evicted") var maxPodsToEvictPerNamespace uint = 1 - runPodLifetimePlugin(ctx, t, clientSet, nodeInformer, nil, "", nil, false, &maxPodsToEvictPerNamespace, nil, getPodsAssignedToNode) + runPodLifetimePlugin(ctx, t, clientSet, nodeLister, nil, "", nil, false, &maxPodsToEvictPerNamespace, nil, getPodsAssignedToNode) t.Log("Finished PodLifetime plugin") t.Logf("Wait for terminating pod to disappear")