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