@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
25
+ "k8s.io/klog/v2"
25
26
"k8s.io/utils/clock"
26
27
)
27
28
@@ -46,6 +47,10 @@ type DelayingQueueConfig = TypedDelayingQueueConfig[any]
46
47
47
48
// TypedDelayingQueueConfig specifies optional configurations to customize a DelayingInterface.
48
49
type TypedDelayingQueueConfig [T comparable ] struct {
50
+ // An optional logger. The name of the queue does *not* get added to it, this should
51
+ // be done by the caller if desired.
52
+ Logger * klog.Logger
53
+
49
54
// Name for the queue. If unnamed, the metrics will not be registered.
50
55
Name string
51
56
@@ -94,6 +99,10 @@ func TypedNewDelayingQueue[T comparable]() TypedDelayingInterface[T] {
94
99
// NewTypedDelayingQueueWithConfig constructs a new workqueue with options to
95
100
// customize different properties.
96
101
func NewTypedDelayingQueueWithConfig [T comparable ](config TypedDelayingQueueConfig [T ]) TypedDelayingInterface [T ] {
102
+ logger := klog .Background ()
103
+ if config .Logger != nil {
104
+ logger = * config .Logger
105
+ }
97
106
if config .Clock == nil {
98
107
config .Clock = clock.RealClock {}
99
108
}
@@ -106,7 +115,7 @@ func NewTypedDelayingQueueWithConfig[T comparable](config TypedDelayingQueueConf
106
115
})
107
116
}
108
117
109
- return newDelayingQueue (config .Clock , config .Queue , config .Name , config .MetricsProvider )
118
+ return newDelayingQueue (logger , config .Clock , config .Queue , config .Name , config .MetricsProvider )
110
119
}
111
120
112
121
// NewDelayingQueueWithCustomQueue constructs a new workqueue with ability to
@@ -135,7 +144,7 @@ func NewDelayingQueueWithCustomClock(clock clock.WithTicker, name string) Delayi
135
144
})
136
145
}
137
146
138
- func newDelayingQueue [T comparable ](clock clock.WithTicker , q TypedInterface [T ], name string , provider MetricsProvider ) * delayingType [T ] {
147
+ func newDelayingQueue [T comparable ](logger klog. Logger , clock clock.WithTicker , q TypedInterface [T ], name string , provider MetricsProvider ) * delayingType [T ] {
139
148
ret := & delayingType [T ]{
140
149
TypedInterface : q ,
141
150
clock : clock ,
@@ -145,7 +154,7 @@ func newDelayingQueue[T comparable](clock clock.WithTicker, q TypedInterface[T],
145
154
metrics : newRetryMetrics (name , provider ),
146
155
}
147
156
148
- go ret .waitingLoop ()
157
+ go ret .waitingLoop (logger )
149
158
return ret
150
159
}
151
160
@@ -264,8 +273,8 @@ func (q *delayingType[T]) AddAfter(item T, duration time.Duration) {
264
273
const maxWait = 10 * time .Second
265
274
266
275
// waitingLoop runs until the workqueue is shutdown and keeps a check on the list of items to be added.
267
- func (q * delayingType [T ]) waitingLoop () {
268
- defer utilruntime .HandleCrash ( )
276
+ func (q * delayingType [T ]) waitingLoop (logger klog. Logger ) {
277
+ defer utilruntime .HandleCrashWithLogger ( logger )
269
278
270
279
// Make a placeholder channel to use when there are no items in our list
271
280
never := make (<- chan time.Time )
0 commit comments