Skip to content

Commit

Permalink
fix: update the resync period flag feature
Browse files Browse the repository at this point in the history
Signed-off-by: AhmedGrati <[email protected]>
  • Loading branch information
TessaIO committed Apr 25, 2023
1 parent 54bd4c5 commit 0e86f79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/nfd-master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
args.Overrides.EnableTaints = overrides.EnableTaints
case "no-publish":
args.Overrides.NoPublish = overrides.NoPublish
case "-resync-period":
case "resync-period":
args.Overrides.ResyncPeriod = overrides.ResyncPeriod
}
})
Expand Down
4 changes: 3 additions & 1 deletion pkg/nfd-master/nfd-api-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
nfdscheme "sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned/scheme"
nfdinformers "sigs.k8s.io/node-feature-discovery/pkg/generated/informers/externalversions"
nfdlisters "sigs.k8s.io/node-feature-discovery/pkg/generated/listers/nfd/v1alpha1"
"sigs.k8s.io/node-feature-discovery/pkg/utils"
)

type nfdController struct {
Expand All @@ -54,6 +55,8 @@ func newNfdController(config *restclient.Config, nfdApiControllerOptions nfdApiC
}

nfdClient := nfdclientset.NewForConfigOrDie(config)
utils.KlogDump(2, "NFD API controller options:", " ", nfdApiControllerOptions)

informerFactory := nfdinformers.NewSharedInformerFactory(nfdClient, nfdApiControllerOptions.resyncPeriod)

// Add informer for NodeFeature objects
Expand Down Expand Up @@ -117,7 +120,6 @@ func newNfdController(config *restclient.Config, nfdApiControllerOptions nfdApiC
informerFactory.Start(c.stopChan)

utilruntime.Must(nfdv1alpha1.AddToScheme(nfdscheme.Scheme))

return c, nil
}

Expand Down
40 changes: 29 additions & 11 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ type Args struct {
Prune bool
VerifyNodeName bool
Options string
ResyncPeriod utils.DurationVal

Overrides ConfigOverrideArgs
}
Expand Down Expand Up @@ -163,7 +162,6 @@ func NewNfdMaster(args *Args) (NfdMaster, error) {
if args.ConfigFile != "" {
nfd.configFilePath = filepath.Clean(args.ConfigFile)
}

return nfd, nil
}

Expand Down Expand Up @@ -199,18 +197,10 @@ func (m *nfdMaster) Run() error {
}

if m.args.CrdController {
kubeconfig, err := m.getKubeconfig()
err := m.startNfdControllerApi()
if err != nil {
return err
}
klog.Info("starting nfd api controller")
m.nfdController, err = newNfdController(kubeconfig, nfdApiControllerOptions{
disableNodeFeature: !m.args.EnableNodeFeatureApi,
resyncPeriod: m.args.ResyncPeriod.Duration,
})
if err != nil {
return fmt.Errorf("failed to initialize CRD controller: %w", err)
}
}

// Create watcher for config file
Expand Down Expand Up @@ -249,6 +239,17 @@ func (m *nfdMaster) Run() error {
if err := m.configure(m.configFilePath, m.args.Options); err != nil {
return err
}

// restart NFD API controller
if m.nfdController != nil {
m.nfdController.stop()
}
if m.args.CrdController {
err := m.startNfdControllerApi()
if err != nil {
return nil
}
}
// Update all nodes when the configuration changes
if m.nfdController != nil {
m.nfdController.updateAllNodesChan <- struct{}{}
Expand Down Expand Up @@ -1152,6 +1153,7 @@ func (m *nfdMaster) configure(filepath string, overrides string) error {
}
m.apihelper = apihelper.K8sHelpers{Kubeconfig: kubeconfig}
}

// Pre-process DenyLabelNS into 2 lists: one for normal ns, and the other for wildcard ns
normalDeniedNs, wildcardDeniedNs := preProcessDeniedNamespaces(c.DenyLabelNs)
m.deniedNs.normal = normalDeniedNs
Expand Down Expand Up @@ -1219,3 +1221,19 @@ func (m *nfdMaster) instanceAnnotation(name string) string {
}
return m.args.Instance + "." + name
}

func (m *nfdMaster) startNfdControllerApi() error {
kubeconfig, err := m.getKubeconfig()
if err != nil {
return err
}
klog.Info("starting nfd api controller")
m.nfdController, err = newNfdController(kubeconfig, nfdApiControllerOptions{
disableNodeFeature: !m.args.EnableNodeFeatureApi,
resyncPeriod: m.config.ResyncPeriod.Duration,
})
if err != nil {
return fmt.Errorf("failed to initialize CRD controller: %w", err)
}
return nil
}

0 comments on commit 0e86f79

Please sign in to comment.