Skip to content

Commit

Permalink
fix(logs): Changed ratelimiter in lvmvol controller (#195)
Browse files Browse the repository at this point in the history
Signed-off-by: Abhilash Shetty <[email protected]>
  • Loading branch information
abhilashshetty04 authored Jun 29, 2022
1 parent 2f947ef commit 38245bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkg/mgmt/lvmnode/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ 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 {
//Creating informer for lvm node resource
nodeInformer := dynInformer.ForResource(noderesource).Informer()
klog.Infof("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(klog.Infof)
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})

klog.Infof("Creating lvm node controller object")
nodeContrller := &NodeController{
kubeclientset: kubeClient,
Expand All @@ -100,6 +101,8 @@ func newNodeController(kubeClient kubernetes.Interface, client dynamic.Interface
pollInterval: 60 * time.Second,
ownerRef: ownerRef,
}

klog.Infof("Adding Event handler functions for lvm node controller")
nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: nodeContrller.addNode,
UpdateFunc: nodeContrller.updateNode,
Expand Down
9 changes: 5 additions & 4 deletions pkg/mgmt/snapshot/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,23 @@ func newSnapController(kubeClient kubernetes.Interface, client dynamic.Interface
dynInformer dynamicinformer.DynamicSharedInformerFactory) *SnapController {
//Creating informer for lvmsnapshot resource
snapInformer := dynInformer.ForResource(snapresource).Informer()
klog.Infoln("Using new rate limiter")
//This ratelimiter requeues failed items after 5 secs for first 12 attempts. Then objects are requeued after 30 secs.
rateLimiter := workqueue.NewItemFastSlowRateLimiter(5*time.Second, 30*time.Second, 12)

klog.Infof("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(klog.Infof)
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})

klog.Infof("Creating lvm snapshot controller object")
snapCtrller := &SnapController{
kubeclientset: kubeClient,
clientset: client,
snapLister: dynamiclister.New(snapInformer.GetIndexer(), snapresource),
snapSynced: snapInformer.HasSynced,
//workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Snap"),
workqueue: workqueue.NewNamedRateLimitingQueue(rateLimiter, "Snap"),
recorder: recorder,
workqueue: workqueue.NewNamedRateLimitingQueue(rateLimiter, "Snap"),
recorder: recorder,
}
klog.Infof("Adding Event handler functions for lvm snapshot controller")
snapInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down
10 changes: 8 additions & 2 deletions pkg/mgmt/volume/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package volume

import (
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -73,8 +75,11 @@ type VolController struct {
//This function returns controller object with all required keys set to watch over lvmvolume object
func newVolController(kubeClient kubernetes.Interface, client dynamic.Interface,
dynInformer dynamicinformer.DynamicSharedInformerFactory) *VolController {

//Creating informer for lvmvolume resource
volInformer := dynInformer.ForResource(volresource).Informer()
//This ratelimiter requeues failed items after 5 secs for first 12 attempts. Then objects are requeued after 30 secs.
rateLimiter := workqueue.NewItemFastSlowRateLimiter(5*time.Second, 30*time.Second, 12)

klog.Infof("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(klog.Infof)
Expand All @@ -87,9 +92,10 @@ func newVolController(kubeClient kubernetes.Interface, client dynamic.Interface,
clientset: client,
VolLister: dynamiclister.New(volInformer.GetIndexer(), volresource),
VolSynced: volInformer.HasSynced,
workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Vol"),
workqueue: workqueue.NewNamedRateLimitingQueue(rateLimiter, "Vol"),
recorder: recorder,
}

klog.Infof("Adding Event handler functions for lvm volume controller")
volInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: volCtrller.addVol,
Expand Down

0 comments on commit 38245bd

Please sign in to comment.