Skip to content

Commit

Permalink
feat: add master resync period configurability
Browse files Browse the repository at this point in the history
This PR adds a config option for setting the NFD API controller resync period.
The resync period is only activated when the NodeFeature API has been
enabled (with -enable-nodefeature-api).

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
  • Loading branch information
TessaIO committed Apr 15, 2023
1 parent 018cd33 commit 17c5e72
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cmd/nfd-master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func initFlags(flagset *flag.FlagSet) (*master.Args, *master.ConfigOverrideArgs)
flagset.StringVar(&args.Options, "options", "",
"Specify config options from command line. Config options are specified "+
"in the same format as in the config file (i.e. json or yaml). These options")
flagset.IntVar(&args.ResyncPeriod, "resync-period", 60,
"Specify the NFD API controller resync period, expressed in minutes."+
"It has an effect when the NodeFeature API has been enabled (with -enable-nodefeature-api).")

overrides := &master.ConfigOverrideArgs{
LabelWhiteList: &utils.RegexpVal{},
Expand Down
3 changes: 3 additions & 0 deletions deployment/helm/node-feature-discovery/templates/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ spec:
{{- if .Values.master.featureRulesController | kindIs "invalid" | not }}
- "-featurerules-controller={{ .Values.master.featureRulesController }}"
{{- end }}
{{- if .Values.master.resyncPeriod }}
- "-resync-period={{ .Values.master.resyncPeriod }}"
{{- end }}
{{- if .Values.tls.enable }}
- "-ca-file=/etc/kubernetes/node-feature-discovery/certs/ca.crt"
- "-key-file=/etc/kubernetes/node-feature-discovery/certs/tls.key"
Expand Down
1 change: 1 addition & 0 deletions deployment/helm/node-feature-discovery/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ master:
port: 8080
instance:
featureApi:
resyncPeriod:
denyLabelNs: []
extraLabelNs: []
resourceLabels: []
Expand Down
12 changes: 12 additions & 0 deletions docs/reference/master-commandline-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,15 @@ Default: 0
Comma-separated list of `pattern=N` settings for file-filtered logging.

Default: *empty*

### -resync-period

The `-resync-period` flag specifies the NFD API controller resync period, expressed in minutes.

Default: 60 minutes.

Example:

```bash
nfd-master -resync-period=50
```
19 changes: 12 additions & 7 deletions pkg/nfd-master/nfd-api-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ type nfdController struct {
updateOneNodeChan chan string
}

func newNfdController(config *restclient.Config, disableNodeFeature bool) (*nfdController, error) {
type NfdApiControllerOptions struct {
disableNodeFeature bool
resyncPeriod int
}

func newNfdController(config *restclient.Config, nfdApiControllerOptions NfdApiControllerOptions) (*nfdController, error) {
c := &nfdController{
stopChan: make(chan struct{}, 1),
updateAllNodesChan: make(chan struct{}, 1),
updateOneNodeChan: make(chan string),
}

nfdClient := nfdclientset.NewForConfigOrDie(config)

informerFactory := nfdinformers.NewSharedInformerFactory(nfdClient, 1*time.Hour)
resyncDuration := time.Duration(nfdApiControllerOptions.resyncPeriod) * time.Minute
informerFactory := nfdinformers.NewSharedInformerFactory(nfdClient, resyncDuration)

// Add informer for NodeFeature objects
if !disableNodeFeature {
if !nfdApiControllerOptions.disableNodeFeature {
featureInformer := informerFactory.Nfd().V1alpha1().NodeFeatures()
if _, err := featureInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -83,23 +88,23 @@ func newNfdController(config *restclient.Config, disableNodeFeature bool) (*nfdC
AddFunc: func(object interface{}) {
key, _ := cache.MetaNamespaceKeyFunc(object)
klog.V(2).Infof("NodeFeatureRule %v added", key)
if !disableNodeFeature {
if !nfdApiControllerOptions.disableNodeFeature {
c.updateAllNodes()
}
// else: rules will be processed only when gRPC requests are received
},
UpdateFunc: func(oldObject, newObject interface{}) {
key, _ := cache.MetaNamespaceKeyFunc(newObject)
klog.V(2).Infof("NodeFeatureRule %v updated", key)
if !disableNodeFeature {
if !nfdApiControllerOptions.disableNodeFeature {
c.updateAllNodes()
}
// else: rules will be processed only when gRPC requests are received
},
DeleteFunc: func(object interface{}) {
key, _ := cache.MetaNamespaceKeyFunc(object)
klog.V(2).Infof("NodeFeatureRule %v deleted", key)
if !disableNodeFeature {
if !nfdApiControllerOptions.disableNodeFeature {
c.updateAllNodes()
}
// else: rules will be processed only when gRPC requests are received
Expand Down
6 changes: 5 additions & 1 deletion pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type Args struct {
Prune bool
VerifyNodeName bool
Options string
ResyncPeriod int

Overrides ConfigOverrideArgs
}
Expand Down Expand Up @@ -195,7 +196,10 @@ func (m *nfdMaster) Run() error {
return err
}
klog.Info("starting nfd api controller")
m.nfdController, err = newNfdController(kubeconfig, !m.args.EnableNodeFeatureApi)
m.nfdController, err = newNfdController(kubeconfig, NfdApiControllerOptions{
disableNodeFeature: !m.args.EnableNodeFeatureApi,
resyncPeriod: m.args.ResyncPeriod,
})
if err != nil {
return fmt.Errorf("failed to initialize CRD controller: %w", err)
}
Expand Down

0 comments on commit 17c5e72

Please sign in to comment.