Skip to content

Commit 300a5f5

Browse files
authored
Merge pull request #1399 from marquiz/devel/gc-metrics
nfd-gc: simplify initialization
2 parents 899939b + f5c6ce2 commit 300a5f5

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

pkg/nfd-gc/nfd-gc.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"k8s.io/apimachinery/pkg/util/sets"
2929
"k8s.io/client-go/informers"
3030
"k8s.io/client-go/kubernetes"
31-
restclient "k8s.io/client-go/rest"
3231
"k8s.io/client-go/tools/cache"
3332
"k8s.io/klog/v2"
3433

@@ -50,10 +49,10 @@ type NfdGarbageCollector interface {
5049
}
5150

5251
type nfdGarbageCollector struct {
52+
args *Args
5353
stopChan chan struct{}
5454
nfdClient nfdclientset.Interface
5555
topoClient topologyclientset.Interface
56-
gcPeriod time.Duration
5756
factory informers.SharedInformerFactory
5857
}
5958

@@ -63,27 +62,14 @@ func New(args *Args) (NfdGarbageCollector, error) {
6362
return nil, err
6463
}
6564

66-
stop := make(chan struct{})
67-
68-
return newNfdGarbageCollector(kubeconfig, stop, args.GCPeriod)
69-
}
70-
71-
func newNfdGarbageCollector(config *restclient.Config, stop chan struct{}, gcPeriod time.Duration) (*nfdGarbageCollector, error) {
72-
helper := apihelper.K8sHelpers{Kubeconfig: config}
73-
cli, err := helper.GetTopologyClient()
74-
if err != nil {
75-
return nil, err
76-
}
77-
78-
clientset := kubernetes.NewForConfigOrDie(config)
79-
factory := informers.NewSharedInformerFactory(clientset, 5*time.Minute)
65+
clientset := kubernetes.NewForConfigOrDie(kubeconfig)
8066

8167
return &nfdGarbageCollector{
82-
topoClient: cli,
83-
nfdClient: nfdclientset.NewForConfigOrDie(config),
84-
stopChan: stop,
85-
gcPeriod: gcPeriod,
86-
factory: factory,
68+
args: args,
69+
stopChan: make(chan struct{}),
70+
topoClient: topologyclientset.NewForConfigOrDie(kubeconfig),
71+
nfdClient: nfdclientset.NewForConfigOrDie(kubeconfig),
72+
factory: informers.NewSharedInformerFactory(clientset, 5*time.Minute),
8773
}, nil
8874
}
8975

@@ -226,7 +212,7 @@ func (n *nfdGarbageCollector) Run() error {
226212
return err
227213
}
228214
// run periodic GC
229-
n.periodicGC(n.gcPeriod)
215+
n.periodicGC(n.args.GCPeriod)
230216

231217
return nil
232218
}

pkg/nfd-gc/nfd-gc_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestNRTGC(t *testing.T) {
7373
Convey("periodic GC should remove obsolete NRT", t, func() {
7474
gc := newMockGC([]string{"node1", "node2"}, []string{"node1", "node2"})
7575
// Override period to run fast
76-
gc.gcPeriod = 100 * time.Millisecond
76+
gc.args.GCPeriod = 100 * time.Millisecond
7777

7878
nrt := v1alpha2.NodeResourceTopology{
7979
ObjectMeta: metav1.ObjectMeta{
@@ -99,7 +99,9 @@ func newMockGC(nodes, nrts []string) *mockGC {
9999
nfdClient: fakenfdclientset.NewSimpleClientset(),
100100
topoClient: faketopologyv1alpha2.NewSimpleClientset(createFakeNRTs(nrts...)...),
101101
stopChan: make(chan struct{}, 1),
102-
gcPeriod: 10 * time.Minute,
102+
args: &Args{
103+
GCPeriod: 10 * time.Minute,
104+
},
103105
},
104106
k8sClient: k8sClient,
105107
}

0 commit comments

Comments
 (0)