@@ -163,9 +163,7 @@ func (c *Controller) Start(ctx context.Context) error {
163
163
for _ , watch := range c .startWatches {
164
164
c .Log .Info ("Starting EventSource" , "source" , watch .src )
165
165
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 {
169
167
return err
170
168
}
171
169
}
@@ -179,15 +177,21 @@ func (c *Controller) Start(ctx context.Context) error {
179
177
continue
180
178
}
181
179
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
+ }
185
192
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 {
191
195
return err
192
196
}
193
197
}
0 commit comments