@@ -58,6 +58,13 @@ const (
58
58
//
59
59
// To mitigate this, we use a TTL and check a pool again once added slices expire.
60
60
defaultMutationCacheTTL = time .Minute
61
+
62
+ // defaultSyncDelay defines how long to wait between receiving the most recent
63
+ // informer event and syncing again. This is long enough that the informer cache
64
+ // should be up-to-date (matter mostly for deletes because an out-dated cache
65
+ // causes redundant delete API calls) and not too long that a human mistake
66
+ // doesn't get fixed while that human is waiting for it.
67
+ defaultSyncDelay = 30 * time .Second
61
68
)
62
69
63
70
// Controller synchronizes information about resources of one driver with
@@ -74,6 +81,7 @@ type Controller struct {
74
81
queue workqueue.TypedRateLimitingInterface [string ]
75
82
sliceStore cache.MutationCache
76
83
mutationCacheTTL time.Duration
84
+ syncDelay time.Duration
77
85
78
86
// Must use atomic access...
79
87
numCreates int64
@@ -194,6 +202,15 @@ type Options struct {
194
202
// MutationCacheTTL can be used to change the default TTL of one minute.
195
203
// See source code for details.
196
204
MutationCacheTTL * time.Duration
205
+
206
+ // SyncDelay defines how long to wait between receiving the most recent
207
+ // informer event and syncing again. The default is 30 seconds.
208
+ //
209
+ // This is long enough that the informer cache should be up-to-date
210
+ // (matter mostly for deletes because an out-dated cache causes
211
+ // redundant delete API calls) and not too long that a human mistake
212
+ // doesn't get fixed while that human is waiting for it.
213
+ SyncDelay * time.Duration
197
214
}
198
215
199
216
// Stop cancels all background activity and blocks until the controller has stopped.
@@ -267,17 +284,15 @@ func newController(ctx context.Context, options Options) (*Controller, error) {
267
284
owner : options .Owner .DeepCopy (),
268
285
queue : options .Queue ,
269
286
resources : options .Resources ,
270
- mutationCacheTTL : defaultMutationCacheTTL ,
287
+ mutationCacheTTL : ptr .Deref (options .MutationCacheTTL , defaultMutationCacheTTL ),
288
+ syncDelay : ptr .Deref (options .SyncDelay , defaultSyncDelay ),
271
289
}
272
290
if c .queue == nil {
273
291
c .queue = workqueue .NewTypedRateLimitingQueueWithConfig (
274
292
workqueue .DefaultTypedControllerRateLimiter [string ](),
275
293
workqueue.TypedRateLimitingQueueConfig [string ]{Name : "node_resource_slices" },
276
294
)
277
295
}
278
- if options .MutationCacheTTL != nil {
279
- c .mutationCacheTTL = * options .MutationCacheTTL
280
- }
281
296
if err := c .initInformer (ctx ); err != nil {
282
297
return nil , err
283
298
}
@@ -321,7 +336,7 @@ func (c *Controller) initInformer(ctx context.Context) error {
321
336
return
322
337
}
323
338
logger .V (5 ).Info ("ResourceSlice add" , "slice" , klog .KObj (slice ))
324
- c .queue .Add (slice .Spec .Pool .Name )
339
+ c .queue .AddAfter (slice .Spec .Pool .Name , c . syncDelay )
325
340
},
326
341
UpdateFunc : func (old , new any ) {
327
342
oldSlice , ok := old .(* resourceapi.ResourceSlice )
@@ -337,8 +352,8 @@ func (c *Controller) initInformer(ctx context.Context) error {
337
352
} else {
338
353
logger .V (5 ).Info ("ResourceSlice update" , "slice" , klog .KObj (newSlice ))
339
354
}
340
- c .queue .Add (oldSlice .Spec .Pool .Name )
341
- c .queue .Add (newSlice .Spec .Pool .Name )
355
+ c .queue .AddAfter (oldSlice .Spec .Pool .Name , c . syncDelay )
356
+ c .queue .AddAfter (newSlice .Spec .Pool .Name , c . syncDelay )
342
357
},
343
358
DeleteFunc : func (obj any ) {
344
359
if tombstone , ok := obj .(cache.DeletedFinalStateUnknown ); ok {
@@ -349,7 +364,7 @@ func (c *Controller) initInformer(ctx context.Context) error {
349
364
return
350
365
}
351
366
logger .V (5 ).Info ("ResourceSlice delete" , "slice" , klog .KObj (slice ))
352
- c .queue .Add (slice .Spec .Pool .Name )
367
+ c .queue .AddAfter (slice .Spec .Pool .Name , c . syncDelay )
353
368
},
354
369
})
355
370
if err != nil {
@@ -674,7 +689,7 @@ func (c *Controller) syncPool(ctx context.Context, poolName string) error {
674
689
case err == nil :
675
690
atomic .AddInt64 (& c .numDeletes , 1 )
676
691
case apierrors .IsNotFound (err ):
677
- // okay
692
+ logger . V ( 5 ). Info ( "Resource slice was already deleted earlier" , "slice" , klog . KObj ( slice ))
678
693
default :
679
694
return fmt .Errorf ("delete resource slice: %w" , err )
680
695
}
0 commit comments