From cff58f93faa033ef0579f77f62f21dd4c7cce5ea Mon Sep 17 00:00:00 2001 From: AhmedGrati Date: Sat, 15 Apr 2023 16:11:59 +0100 Subject: [PATCH] feat: add master resync period configurability 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 --- cmd/nfd-master/main.go | 3 +++ .../templates/master.yaml | 3 +++ .../helm/node-feature-discovery/values.yaml | 1 + .../reference/master-commandline-reference.md | 13 +++++++++++++ pkg/nfd-master/nfd-api-controller.go | 19 ++++++++++++------- pkg/nfd-master/nfd-master.go | 6 +++++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/cmd/nfd-master/main.go b/cmd/nfd-master/main.go index 340ffcf09e..ffd16a40df 100644 --- a/cmd/nfd-master/main.go +++ b/cmd/nfd-master/main.go @@ -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.DurationVar(&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{}, diff --git a/deployment/helm/node-feature-discovery/templates/master.yaml b/deployment/helm/node-feature-discovery/templates/master.yaml index 943b5ba1bf..96b0ce1689 100644 --- a/deployment/helm/node-feature-discovery/templates/master.yaml +++ b/deployment/helm/node-feature-discovery/templates/master.yaml @@ -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" diff --git a/deployment/helm/node-feature-discovery/values.yaml b/deployment/helm/node-feature-discovery/values.yaml index fc98f4e928..1632e13f76 100644 --- a/deployment/helm/node-feature-discovery/values.yaml +++ b/deployment/helm/node-feature-discovery/values.yaml @@ -25,6 +25,7 @@ master: port: 8080 instance: featureApi: + resyncPeriod: denyLabelNs: [] extraLabelNs: [] resourceLabels: [] diff --git a/docs/reference/master-commandline-reference.md b/docs/reference/master-commandline-reference.md index c1260e989c..8aaddaca47 100644 --- a/docs/reference/master-commandline-reference.md +++ b/docs/reference/master-commandline-reference.md @@ -376,3 +376,16 @@ 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 +and it's expressed in minutes. + +Default: 60 minutes. + +Example: + +```bash +nfd-master -resync-period=50 +``` diff --git a/pkg/nfd-master/nfd-api-controller.go b/pkg/nfd-master/nfd-api-controller.go index 807f72b483..7ebcdbb417 100644 --- a/pkg/nfd-master/nfd-api-controller.go +++ b/pkg/nfd-master/nfd-api-controller.go @@ -41,7 +41,12 @@ type nfdController struct { updateOneNodeChan chan string } -func newNfdController(config *restclient.Config, disableNodeFeature bool) (*nfdController, error) { +type NfdApiControllerOptions struct { + disableNodeFeature bool + resyncPeriod time.Duration +} + +func newNfdController(config *restclient.Config, nfdApiControllerOptions NfdApiControllerOptions) (*nfdController, error) { c := &nfdController{ stopChan: make(chan struct{}, 1), updateAllNodesChan: make(chan struct{}, 1), @@ -49,11 +54,11 @@ func newNfdController(config *restclient.Config, disableNodeFeature bool) (*nfdC } nfdClient := nfdclientset.NewForConfigOrDie(config) - - informerFactory := nfdinformers.NewSharedInformerFactory(nfdClient, 1*time.Hour) + resyncDuration := 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{}) { @@ -83,7 +88,7 @@ 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 @@ -91,7 +96,7 @@ func newNfdController(config *restclient.Config, disableNodeFeature bool) (*nfdC 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 @@ -99,7 +104,7 @@ func newNfdController(config *restclient.Config, disableNodeFeature bool) (*nfdC 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 diff --git a/pkg/nfd-master/nfd-master.go b/pkg/nfd-master/nfd-master.go index 811ad576d9..947b05ad0c 100644 --- a/pkg/nfd-master/nfd-master.go +++ b/pkg/nfd-master/nfd-master.go @@ -96,6 +96,7 @@ type Args struct { Prune bool VerifyNodeName bool Options string + ResyncPeriod time.Duration Overrides ConfigOverrideArgs } @@ -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) }