@@ -297,25 +297,14 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
297
297
}
298
298
// We are passing the context to ProxyCerts.RunOnce as it needs to implement RunOnce(ctx) however the
299
299
// context is not used at all. So passing a empty context shouldn't be a problem
300
- ctx := context .TODO ()
301
- if err := aggregatorProxyCerts .RunOnce (ctx ); err != nil {
300
+ if err := aggregatorProxyCerts .RunOnce (context .Background ()); err != nil {
302
301
return nil , err
303
302
}
304
303
aggregatorProxyCerts .AddListener (apiserviceRegistrationController )
305
304
s .proxyCurrentCertKeyContent = aggregatorProxyCerts .CurrentCertKeyContent
306
305
307
306
s .GenericAPIServer .AddPostStartHookOrDie ("aggregator-reload-proxy-client-cert" , func (postStartHookContext genericapiserver.PostStartHookContext ) error {
308
- // generate a context from stopCh. This is to avoid modifying files which are relying on apiserver
309
- // TODO: See if we can pass ctx to the current method
310
- ctx , cancel := context .WithCancel (context .Background ())
311
- go func () {
312
- select {
313
- case <- postStartHookContext .StopCh :
314
- cancel () // stopCh closed, so cancel our context
315
- case <- ctx .Done ():
316
- }
317
- }()
318
- go aggregatorProxyCerts .Run (ctx , 1 )
307
+ go aggregatorProxyCerts .Run (postStartHookContext , 1 )
319
308
return nil
320
309
})
321
310
}
@@ -373,9 +362,9 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
373
362
}
374
363
375
364
s .GenericAPIServer .AddPostStartHookOrDie ("apiservice-registration-controller" , func (context genericapiserver.PostStartHookContext ) error {
376
- go apiserviceRegistrationController .Run (context .StopCh , apiServiceRegistrationControllerInitiated )
365
+ go apiserviceRegistrationController .Run (context .Done () , apiServiceRegistrationControllerInitiated )
377
366
select {
378
- case <- context .StopCh :
367
+ case <- context .Done () :
379
368
case <- apiServiceRegistrationControllerInitiated :
380
369
}
381
370
@@ -394,7 +383,7 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
394
383
// Discovery aggregation depends on the apiservice registration controller
395
384
// having the full list of APIServices already synced
396
385
select {
397
- case <- context .StopCh :
386
+ case <- context .Done () :
398
387
return nil
399
388
// Context cancelled, should abort/clean goroutines
400
389
case <- apiServiceRegistrationControllerInitiated :
@@ -405,10 +394,10 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
405
394
// When discovery is ready, all APIServices will be present, with APIServices
406
395
// that have not successfully synced discovery to be present but marked as Stale.
407
396
discoverySyncedCh := make (chan struct {})
408
- go s .discoveryAggregationController .Run (context .StopCh , discoverySyncedCh )
397
+ go s .discoveryAggregationController .Run (context .Done () , discoverySyncedCh )
409
398
410
399
select {
411
- case <- context .StopCh :
400
+ case <- context .Done () :
412
401
return nil
413
402
// Context cancelled, should abort/clean goroutines
414
403
case <- discoverySyncedCh :
@@ -440,7 +429,7 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
440
429
return false , err
441
430
}
442
431
return true , nil
443
- }, hookContext .StopCh ); err != nil {
432
+ }, hookContext .Done () ); err != nil {
444
433
return fmt .Errorf ("failed to wait for apiserver-identity lease %s to be created: %v" ,
445
434
s .GenericAPIServer .APIServerID , err )
446
435
}
@@ -456,14 +445,14 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
456
445
// to register all built-in resources when the generic apiservers install APIs.
457
446
s .GenericAPIServer .StorageVersionManager .UpdateStorageVersions (hookContext .LoopbackClientConfig , s .GenericAPIServer .APIServerID )
458
447
return false , nil
459
- }, hookContext .StopCh )
448
+ }, hookContext .Done () )
460
449
// Once the storage version updater finishes the first round of update,
461
450
// the PostStartHook will return to unblock /healthz. The handler chain
462
451
// won't block write requests anymore. Check every second since it's not
463
452
// expensive.
464
453
wait .PollImmediateUntil (1 * time .Second , func () (bool , error ) {
465
454
return s .GenericAPIServer .StorageVersionManager .Completed (), nil
466
- }, hookContext .StopCh )
455
+ }, hookContext .Done () )
467
456
return nil
468
457
})
469
458
}
@@ -477,14 +466,14 @@ func (s *APIAggregator) PrepareRun() (preparedAPIAggregator, error) {
477
466
// add post start hook before generic PrepareRun in order to be before /healthz installation
478
467
if s .openAPIConfig != nil {
479
468
s .GenericAPIServer .AddPostStartHookOrDie ("apiservice-openapi-controller" , func (context genericapiserver.PostStartHookContext ) error {
480
- go s .openAPIAggregationController .Run (context .StopCh )
469
+ go s .openAPIAggregationController .Run (context .Done () )
481
470
return nil
482
471
})
483
472
}
484
473
485
474
if s .openAPIV3Config != nil {
486
475
s .GenericAPIServer .AddPostStartHookOrDie ("apiservice-openapiv3-controller" , func (context genericapiserver.PostStartHookContext ) error {
487
- go s .openAPIV3AggregationController .Run (context .StopCh )
476
+ go s .openAPIV3AggregationController .Run (context .Done () )
488
477
return nil
489
478
})
490
479
}
0 commit comments