From 45ebdf6dd387307652c2c9cacbbe4aa4ede87030 Mon Sep 17 00:00:00 2001 From: Omri Cohen <95744650+omric-runai@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:16:24 +0300 Subject: [PATCH] feat(NodeController): made node polling interval configurable (#256) * Added configurable polling interval Signed-off-by: Omri Cohen * CR comment - changed pollInterval to be the last argument for lvmnode Start Signed-off-by: Omri Cohen --------- Signed-off-by: Omri Cohen --- cmd/main.go | 4 ++++ pkg/driver/agent.go | 2 +- pkg/driver/config/config.go | 3 +++ pkg/mgmt/lvmnode/builder.go | 5 +++-- pkg/mgmt/lvmnode/start.go | 4 ++-- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 219a7ed5..03d481a6 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -130,6 +130,10 @@ func main() { "--wbps-per-gb=\"vg1-prefix:100,vg2-prefix:200\"", ) + cmd.PersistentFlags().IntVar( + &config.NodeControllerPollingInterval, "node-polling-interval", 60, "The interval, in seconds, between node polling.", + ) + err := cmd.Execute() if err != nil { _, _ = fmt.Fprintf(os.Stderr, "%s", err.Error()) diff --git a/pkg/driver/agent.go b/pkg/driver/agent.go index 9767da98..be4680a1 100644 --- a/pkg/driver/agent.go +++ b/pkg/driver/agent.go @@ -66,7 +66,7 @@ func NewNode(d *CSIDriver) csi.NodeServer { // start the lvm node resource watcher go func() { - err := lvmnode.Start(&ControllerMutex, stopCh) + err := lvmnode.Start(&ControllerMutex, stopCh, d.config.NodeControllerPollingInterval) if err != nil { klog.Fatalf("Failed to start LVM node controller: %s", err.Error()) } diff --git a/pkg/driver/config/config.go b/pkg/driver/config/config.go index 04a7a837..b8eb2995 100644 --- a/pkg/driver/config/config.go +++ b/pkg/driver/config/config.go @@ -85,6 +85,9 @@ type Config struct { // KubeAPIBurst is the burst to allow while talking with Kubernetes API server. KubeAPIBurst int + + // NodeControllerPollingInterval is the interval, in seconds, between node polling. + NodeControllerPollingInterval int } // Default returns a new instance of config diff --git a/pkg/mgmt/lvmnode/builder.go b/pkg/mgmt/lvmnode/builder.go index 2c8adb7e..9632a6c9 100644 --- a/pkg/mgmt/lvmnode/builder.go +++ b/pkg/mgmt/lvmnode/builder.go @@ -83,7 +83,8 @@ type NodeController struct { // This function returns controller object with all required keys set to watch over lvmnode object func newNodeController(kubeClient kubernetes.Interface, client dynamic.Interface, - dynInformer dynamicinformer.DynamicSharedInformerFactory, ownerRef metav1.OwnerReference) (*NodeController, error) { + dynInformer dynamicinformer.DynamicSharedInformerFactory, ownerRef metav1.OwnerReference, + pollInterval int) (*NodeController, error) { //Creating informer for lvm node resource nodeInformer := dynInformer.ForResource(noderesource).Informer() eventBroadcaster := record.NewBroadcaster() @@ -102,7 +103,7 @@ func newNodeController(kubeClient kubernetes.Interface, client dynamic.Interface Name: "Node", }), recorder: recorder, - pollInterval: 60 * time.Second, + pollInterval: time.Duration(pollInterval) * time.Second, ownerRef: ownerRef, } diff --git a/pkg/mgmt/lvmnode/start.go b/pkg/mgmt/lvmnode/start.go index 6a24cbd7..3b242d0f 100644 --- a/pkg/mgmt/lvmnode/start.go +++ b/pkg/mgmt/lvmnode/start.go @@ -35,7 +35,7 @@ import ( ) // Start starts the lvmnode controller. -func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}) error { +func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}, pollInterval int) error { // Get in cluster config cfg, err := k8sapi.Config().Get() @@ -84,7 +84,7 @@ func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}) error { // This lock is used to serialize the AddToScheme call of all controllers. controllerMtx.Lock() - controller, err := newNodeController(kubeClient, openebsClientNew, nodeInformerFactory, ownerRef) + controller, err := newNodeController(kubeClient, openebsClientNew, nodeInformerFactory, ownerRef, pollInterval) if err != nil { return errors.Wrap(err, "failed to create new lvm node controller") }