Skip to content

Commit

Permalink
Merge pull request #1399 from marquiz/devel/gc-metrics
Browse files Browse the repository at this point in the history
nfd-gc: simplify initialization
  • Loading branch information
k8s-ci-robot authored Oct 9, 2023
2 parents 899939b + f5c6ce2 commit 300a5f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
30 changes: 8 additions & 22 deletions pkg/nfd-gc/nfd-gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"

Expand All @@ -50,10 +49,10 @@ type NfdGarbageCollector interface {
}

type nfdGarbageCollector struct {
args *Args
stopChan chan struct{}
nfdClient nfdclientset.Interface
topoClient topologyclientset.Interface
gcPeriod time.Duration
factory informers.SharedInformerFactory
}

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

stop := make(chan struct{})

return newNfdGarbageCollector(kubeconfig, stop, args.GCPeriod)
}

func newNfdGarbageCollector(config *restclient.Config, stop chan struct{}, gcPeriod time.Duration) (*nfdGarbageCollector, error) {
helper := apihelper.K8sHelpers{Kubeconfig: config}
cli, err := helper.GetTopologyClient()
if err != nil {
return nil, err
}

clientset := kubernetes.NewForConfigOrDie(config)
factory := informers.NewSharedInformerFactory(clientset, 5*time.Minute)
clientset := kubernetes.NewForConfigOrDie(kubeconfig)

return &nfdGarbageCollector{
topoClient: cli,
nfdClient: nfdclientset.NewForConfigOrDie(config),
stopChan: stop,
gcPeriod: gcPeriod,
factory: factory,
args: args,
stopChan: make(chan struct{}),
topoClient: topologyclientset.NewForConfigOrDie(kubeconfig),
nfdClient: nfdclientset.NewForConfigOrDie(kubeconfig),
factory: informers.NewSharedInformerFactory(clientset, 5*time.Minute),
}, nil
}

Expand Down Expand Up @@ -226,7 +212,7 @@ func (n *nfdGarbageCollector) Run() error {
return err
}
// run periodic GC
n.periodicGC(n.gcPeriod)
n.periodicGC(n.args.GCPeriod)

return nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/nfd-gc/nfd-gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestNRTGC(t *testing.T) {
Convey("periodic GC should remove obsolete NRT", t, func() {
gc := newMockGC([]string{"node1", "node2"}, []string{"node1", "node2"})
// Override period to run fast
gc.gcPeriod = 100 * time.Millisecond
gc.args.GCPeriod = 100 * time.Millisecond

nrt := v1alpha2.NodeResourceTopology{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -99,7 +99,9 @@ func newMockGC(nodes, nrts []string) *mockGC {
nfdClient: fakenfdclientset.NewSimpleClientset(),
topoClient: faketopologyv1alpha2.NewSimpleClientset(createFakeNRTs(nrts...)...),
stopChan: make(chan struct{}, 1),
gcPeriod: 10 * time.Minute,
args: &Args{
GCPeriod: 10 * time.Minute,
},
},
k8sClient: k8sClient,
}
Expand Down

0 comments on commit 300a5f5

Please sign in to comment.