File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -233,12 +233,6 @@ func (c *Controller[request]) Start(ctx context.Context) error {
233
233
234
234
c .LogConstructor (nil ).Info ("Starting Controller" )
235
235
236
- // All the watches have been started, we can reset the local slice.
237
- //
238
- // We should never hold watches more than necessary, each watch source can hold a backing cache,
239
- // which won't be garbage collected if we hold a reference to it.
240
- c .startWatches = nil
241
-
242
236
// Launch workers to process resources
243
237
c .LogConstructor (nil ).Info ("Starting workers" , "worker count" , c .MaxConcurrentReconciles )
244
238
wg .Add (c .MaxConcurrentReconciles )
@@ -325,6 +319,12 @@ func (c *Controller[request]) startEventSources(ctx context.Context) error {
325
319
})
326
320
}
327
321
retErr = errGroup .Wait ()
322
+
323
+ // All the watches have been started, we can reset the local slice.
324
+ //
325
+ // We should never hold watches more than necessary, each watch source can hold a backing cache,
326
+ // which won't be garbage collected if we hold a reference to it.
327
+ c .startWatches = nil
328
328
})
329
329
330
330
return retErr
Original file line number Diff line number Diff line change @@ -503,7 +503,7 @@ var _ = Describe("controller", func() {
503
503
Expect (err .Error ()).To (ContainSubstring ("timed out waiting for source" ))
504
504
})
505
505
506
- It ("should only start sources once when called multiple times" , func () {
506
+ It ("should only start sources once when called multiple times concurrently " , func () {
507
507
ctx , cancel := context .WithCancel (context .Background ())
508
508
defer cancel ()
509
509
@@ -532,6 +532,23 @@ var _ = Describe("controller", func() {
532
532
wg .Wait ()
533
533
Expect (startCount .Load ()).To (Equal (int32 (1 )), "Source should only be started once even when called multiple times" )
534
534
})
535
+
536
+ It ("should reset c.startWatches to nil after returning" , func () {
537
+ ctx , cancel := context .WithCancel (context .Background ())
538
+ defer cancel ()
539
+
540
+ ctrl .CacheSyncTimeout = 1 * time .Millisecond
541
+
542
+ src := source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
543
+ return nil
544
+ })
545
+
546
+ ctrl .startWatches = []source.TypedSource [reconcile.Request ]{src }
547
+
548
+ err := ctrl .startEventSources (ctx )
549
+ Expect (err ).NotTo (HaveOccurred ())
550
+ Expect (ctrl .startWatches ).To (BeNil (), "startWatches should be reset to nil after returning" )
551
+ })
535
552
})
536
553
537
554
Describe ("Processing queue items from a Controller" , func () {
You can’t perform that action at this time.
0 commit comments