1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Merge pull request #1311 from marquiz/devel/refactor-gc-5

topology-gc: simplify listing of node objects
This commit is contained in:
Kubernetes Prow Robot 2023-08-21 11:40:05 -07:00 committed by GitHub
commit e0c477090b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,7 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
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/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
@ -115,15 +116,14 @@ func (n *topologyGC) deleteNodeHandler(object interface{}) {
// garbageCollect removes all stale API objects // garbageCollect removes all stale API objects
func (n *topologyGC) garbageCollect() { func (n *topologyGC) garbageCollect() {
klog.InfoS("performing garbage collection") klog.InfoS("performing garbage collection")
objects := n.factory.Core().V1().Nodes().Informer().GetIndexer().List() nodes, err := n.factory.Core().V1().Nodes().Lister().List(labels.Everything())
nodes := sets.NewString() if err != nil {
for _, object := range objects { klog.ErrorS(err, "failed to list Node objects")
key, err := cache.MetaNamespaceKeyFunc(object) return
if err != nil { }
klog.ErrorS(err, "failed to create key", "object", object) nodeNames := sets.NewString()
continue for _, node := range nodes {
} nodeNames.Insert(node.Name)
nodes.Insert(key)
} }
nrts, err := n.topoClient.TopologyV1alpha2().NodeResourceTopologies().List(context.TODO(), metav1.ListOptions{}) nrts, err := n.topoClient.TopologyV1alpha2().NodeResourceTopologies().List(context.TODO(), metav1.ListOptions{})
@ -138,7 +138,7 @@ func (n *topologyGC) garbageCollect() {
klog.ErrorS(err, "failed to create key", "noderesourcetopology", klog.KObj(&nrt)) klog.ErrorS(err, "failed to create key", "noderesourcetopology", klog.KObj(&nrt))
continue continue
} }
if !nodes.Has(key) { if !nodeNames.Has(key) {
n.deleteNRT(key) n.deleteNRT(key)
} }
} }