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:
commit
e0c477090b
1 changed files with 10 additions and 10 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue