Skip to content

Commit

Permalink
nfd-master: do nfd API scheme registration in an init function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marquiz authored and k8s-infra-cherrypick-robot committed Mar 27, 2024
1 parent fc4d8bd commit 37e8c6c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/nfd-master/nfd-api-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 37e8c6c

Please sign in to comment.