From 079655b42cb5c28e4701abc34a579f870dafb601 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 14 Dec 2022 00:27:27 +0200 Subject: [PATCH] nfd-master: add error checking for CRD controller creation --- pkg/nfd-master/nfd-api-controller.go | 10 ++++++---- pkg/nfd-master/nfd-master.go | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/nfd-master/nfd-api-controller.go b/pkg/nfd-master/nfd-api-controller.go index a2407efc2a..4a2acc46a8 100644 --- a/pkg/nfd-master/nfd-api-controller.go +++ b/pkg/nfd-master/nfd-api-controller.go @@ -37,7 +37,7 @@ type nfdController struct { stopChan chan struct{} } -func newNfdController(config *restclient.Config) *nfdController { +func newNfdController(config *restclient.Config) (*nfdController, error) { c := &nfdController{ stopChan: make(chan struct{}, 1), } @@ -46,7 +46,7 @@ func newNfdController(config *restclient.Config) *nfdController { informerFactory := nfdinformers.NewSharedInformerFactory(nfdClient, 5*time.Minute) ruleInformer := informerFactory.Nfd().V1alpha1().NodeFeatureRules() - _, _ = ruleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + if _, err := ruleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(object interface{}) { key, _ := cache.MetaNamespaceKeyFunc(object) klog.V(2).Infof("NodeFeatureRule %v added", key) @@ -59,14 +59,16 @@ func newNfdController(config *restclient.Config) *nfdController { key, _ := cache.MetaNamespaceKeyFunc(object) klog.V(2).Infof("NodeFeatureRule %v deleted", key) }, - }) + }); err != nil { + return nil, err + } informerFactory.Start(c.stopChan) utilruntime.Must(nfdv1alpha1.AddToScheme(nfdscheme.Scheme)) c.ruleLister = ruleInformer.Lister() - return c + return c, nil } func (c *nfdController) stop() { diff --git a/pkg/nfd-master/nfd-master.go b/pkg/nfd-master/nfd-master.go index 29c88bbd0b..db4f9f38e2 100644 --- a/pkg/nfd-master/nfd-master.go +++ b/pkg/nfd-master/nfd-master.go @@ -155,7 +155,10 @@ func (m *nfdMaster) Run() error { return err } klog.Info("starting nfd api controller") - m.nfdController = newNfdController(kubeconfig) + m.nfdController, err = newNfdController(kubeconfig) + if err != nil { + return fmt.Errorf("failed to initialize CRD controller: %w", err) + } } if !m.args.NoPublish {