@@ -163,9 +163,7 @@ func (c *Controller) Start(ctx context.Context) error {
163163 for _ , watch := range c .startWatches {
164164 c .Log .Info ("Starting EventSource" , "source" , watch .src )
165165
166- watchStartCtx , cancel := context .WithTimeout (ctx , c .CacheSyncTimeout )
167- defer cancel ()
168- if err := watch .src .Start (watchStartCtx , watch .handler , c .Queue , watch .predicates ... ); err != nil {
166+ if err := watch .src .Start (ctx , watch .handler , c .Queue , watch .predicates ... ); err != nil {
169167 return err
170168 }
171169 }
@@ -179,15 +177,21 @@ func (c *Controller) Start(ctx context.Context) error {
179177 continue
180178 }
181179
182- // use a context with timeout for launching sources and syncing caches.
183- sourceStartCtx , cancel := context .WithTimeout (ctx , c .CacheSyncTimeout )
184- defer cancel ()
180+ if err := func () error {
181+ // use a context with timeout for launching sources and syncing caches.
182+ sourceStartCtx , cancel := context .WithTimeout (ctx , c .CacheSyncTimeout )
183+ defer cancel ()
184+
185+ // WaitForSync waits for a definitive timeout, and returns if there
186+ // is an error or a timeout
187+ if err := syncingSource .WaitForSync (sourceStartCtx ); err != nil {
188+ err := fmt .Errorf ("failed to wait for %s caches to sync: %w" , c .Name , err )
189+ c .Log .Error (err , "Could not wait for Cache to sync" )
190+ return err
191+ }
185192
186- // WaitForSync waits for a definitive timeout, and returns if there
187- // is an error or a timeout
188- if err := syncingSource .WaitForSync (sourceStartCtx ); err != nil {
189- err := fmt .Errorf ("failed to wait for %s caches to sync: %w" , c .Name , err )
190- c .Log .Error (err , "Could not wait for Cache to sync" )
193+ return nil
194+ }(); err != nil {
191195 return err
192196 }
193197 }
0 commit comments