From 37e8c6c01de2ac4b47a27dd26c7625c3ddf3c0e9 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 27 Mar 2024 15:26:16 +0200 Subject: [PATCH] nfd-master: do nfd API scheme registration in an init function Prevents (rare) races on nfd-master reconfigurartion. Previously the scheme was registered at nfd API controller creation/startup time. This caused a race with some lister/informer goroutines of the previous (stoppped) controller still running and accessing (reading) the sceme while we were updating (writing) it. --- pkg/nfd-master/nfd-api-controller.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/nfd-master/nfd-api-controller.go b/pkg/nfd-master/nfd-api-controller.go index b1d734c750..af86b2b45c 100644 --- a/pkg/nfd-master/nfd-api-controller.go +++ b/pkg/nfd-master/nfd-api-controller.go @@ -49,6 +49,10 @@ type nfdApiControllerOptions struct { ResyncPeriod time.Duration } +func init() { + utilruntime.Must(nfdv1alpha1.AddToScheme(nfdscheme.Scheme)) +} + func newNfdController(config *restclient.Config, nfdApiControllerOptions nfdApiControllerOptions) (*nfdController, error) { c := &nfdController{ stopChan: make(chan struct{}, 1), @@ -118,7 +122,6 @@ func newNfdController(config *restclient.Config, nfdApiControllerOptions nfdApiC // Start informers informerFactory.Start(c.stopChan) - utilruntime.Must(nfdv1alpha1.AddToScheme(nfdscheme.Scheme)) return c, nil }