66 "time"
77
88 "github.com/pubg/kube-image-deployer/interfaces"
9- "k8s.io/klog/v2"
109
1110 pkgRuntime "k8s.io/apimachinery/pkg/runtime"
1211 "k8s.io/apimachinery/pkg/util/runtime"
@@ -24,6 +23,7 @@ type Controller struct {
2423 informer cache.Controller
2524 imageNotifier interfaces.IImageNotifier
2625 applyStrategicMergePatch ApplyStrategicMergePatch
26+ logger interfaces.ILogger
2727
2828 syncedImages map [Image ]bool
2929 syncedImagesMutex sync.RWMutex
@@ -45,6 +45,7 @@ type ControllerOpt struct {
4545 ImageNotifier interfaces.IImageNotifier
4646 ApplyStrategicMergePatch ApplyStrategicMergePatch
4747 ControllerWatchKey string
48+ Logger interfaces.ILogger
4849}
4950
5051// NewController creates a new Controller.
@@ -58,6 +59,7 @@ func NewController(opt ControllerOpt) *Controller {
5859 imageNotifier : opt .ImageNotifier ,
5960 applyStrategicMergePatch : opt .ApplyStrategicMergePatch ,
6061 watchKey : opt .ControllerWatchKey ,
62+ logger : opt .Logger ,
6163 syncedImages : make (map [Image ]bool ),
6264 syncedImagesMutex : sync.RWMutex {},
6365 imageUpdateNotifyList : make ([]imageUpdateNotify , 0 ),
@@ -95,7 +97,7 @@ func (c *Controller) handleErr(err error, key interface{}) {
9597
9698 // This controller retries 5 times if something goes wrong. After that, it stops trying.
9799 if c .queue .NumRequeues (key ) < 5 {
98- klog . V ( 2 ) .Infof ("[%s] Error syncing %v: %v" , c .resource , key , err )
100+ c . logger .Infof ("[%s] Error syncing %v: %v" , c .resource , key , err )
99101
100102 // Re-enqueue the key rate limited. Based on the rate limiter on the
101103 // queue and the re-enqueue history, the key will be processed later again.
@@ -106,7 +108,7 @@ func (c *Controller) handleErr(err error, key interface{}) {
106108 c .queue .Forget (key )
107109 // Report to an external entity that, even after several retries, we could not successfully process this key
108110 runtime .HandleError (err )
109- klog . V ( 2 ) .Infof ("[%s] Dropping out of the queue: key:%q, err:%v" , c .resource , key , err )
111+ c . logger .Infof ("[%s] Dropping out of the queue: key:%q, err:%v" , c .resource , key , err )
110112}
111113
112114// Run begins watching and syncing.
@@ -115,7 +117,7 @@ func (c *Controller) Run(workers int, stopCh chan struct{}) {
115117
116118 // Let the workers stop when we are done
117119 defer c .queue .ShutDown ()
118- klog . V ( 2 ) .Infof ("[%s] Starting controller" , c .resource )
120+ c . logger .Infof ("[%s] Starting controller" , c .resource )
119121
120122 go c .informer .Run (stopCh )
121123
@@ -132,7 +134,7 @@ func (c *Controller) Run(workers int, stopCh chan struct{}) {
132134 go wait .Until (c .patchUpdateNotifyList , time .Second , stopCh )
133135
134136 <- stopCh
135- klog . V ( 2 ) .Infof ("[%s] Stopping controller" , c .resource )
137+ c . logger .Infof ("[%s] Stopping controller" , c .resource )
136138}
137139
138140func (c * Controller ) GetReresourceName () string {
0 commit comments