Skip to content

Commit

Permalink
feat(NodeController): made node polling interval configurable (#256)
Browse files Browse the repository at this point in the history
* Added configurable polling interval

Signed-off-by: Omri Cohen <[email protected]>

* CR comment - changed pollInterval to be the last argument for lvmnode Start

Signed-off-by: Omri Cohen <[email protected]>

---------

Signed-off-by: Omri Cohen <[email protected]>
  • Loading branch information
omric-runai authored Sep 8, 2023
1 parent 400159d commit 45ebdf6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/mgmt/lvmnode/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/mgmt/lvmnode/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 45ebdf6

Please sign in to comment.