@@ -100,7 +100,7 @@ func (ca *clusterAccessor) createConnection(ctx context.Context) (*createConnect
100100 }
101101
102102 log .V (6 ).Info ("Creating cached client and cache" )
103- cachedClient , cache , err := createCachedClient (ctx , ca .config , restConfig , httpClient , mapper )
103+ cachedClient , cache , err := createCachedClient (ctx , ca .cacheCtx , ca . config , restConfig , httpClient , mapper )
104104 if err != nil {
105105 return nil , err
106106 }
@@ -212,23 +212,37 @@ func createUncachedClient(scheme *runtime.Scheme, config *rest.Config, httpClien
212212}
213213
214214// createCachedClient creates a cached client for the given cluster, based on the rest.Config.
215- func createCachedClient (ctx context.Context , clusterAccessorConfig * clusterAccessorConfig , config * rest.Config , httpClient * http.Client , mapper meta.RESTMapper ) (client.Client , * stoppableCache , error ) {
215+ func createCachedClient (ctx , cacheCtx context.Context , clusterAccessorConfig * clusterAccessorConfig , config * rest.Config , httpClient * http.Client , mapper meta.RESTMapper ) (client.Client , * stoppableCache , error ) {
216+ // This config will only be used for List and Watch calls of informers
217+ // because we don't want these requests to time out after the regular timeout
218+ // of Options.Client.Timeout (default 10s).
219+ // Lists of informers have no timeouts set.
220+ // Watches of informers are timing out per default after [5m, 2*5m].
221+ // https://github.com/kubernetes/client-go/blob/v0.32.0/tools/cache/reflector.go#L53-L55
222+ // We are setting 11m to set a timeout for List calls without influencing Watch calls.
223+ configWith11mTimeout := rest .CopyConfig (config )
224+ configWith11mTimeout .Timeout = 11 * time .Minute
225+ httpClientWith11mTimeout , err := rest .HTTPClientFor (configWith11mTimeout )
226+ if err != nil {
227+ return nil , nil , errors .Wrapf (err , "error creating cache: error creating HTTP client" )
228+ }
229+
216230 // Create the cache for the cluster.
217231 cacheOptions := cache.Options {
218- HTTPClient : httpClient ,
232+ HTTPClient : httpClientWith11mTimeout ,
219233 Scheme : clusterAccessorConfig .Scheme ,
220234 Mapper : mapper ,
221235 SyncPeriod : clusterAccessorConfig .Cache .SyncPeriod ,
222236 ByObject : clusterAccessorConfig .Cache .ByObject ,
223237 }
224- remoteCache , err := cache .New (config , cacheOptions )
238+ remoteCache , err := cache .New (configWith11mTimeout , cacheOptions )
225239 if err != nil {
226240 return nil , nil , errors .Wrapf (err , "error creating cache" )
227241 }
228242
229243 // Use a context that is independent of the passed in context, so the cache doesn't get stopped
230244 // when the passed in context is canceled.
231- cacheCtx , cacheCtxCancel := context .WithCancel (context . Background () )
245+ cacheCtx , cacheCtxCancel := context .WithCancel (cacheCtx )
232246
233247 // We need to be able to stop the cache's shared informers, so wrap this in a stoppableCache.
234248 cache := & stoppableCache {
0 commit comments