Skip to content

Commit

Permalink
Added configurable polling interval
Browse files Browse the repository at this point in the history
  • Loading branch information
omric-runai committed Sep 3, 2023
1 parent 400159d commit 3bc0c8c
Show file tree
Hide file tree
Showing 5 changed files with 12 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(d.config.NodeControllerPollingInterval, &ControllerMutex, stopCh)
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
4 changes: 2 additions & 2 deletions pkg/mgmt/lvmnode/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ 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 +102,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(pollInterval int, controllerMtx *sync.RWMutex, stopCh <-chan struct{}) 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 3bc0c8c

Please sign in to comment.