Skip to content

Commit 2433e7a

Browse files
Merge pull request #125661 from mjudeikis/mjudeikis/poststarthookctx.stopch.cleanup
Clean deprecated context.StopCh Kubernetes-commit: bb350f711174670443e23aa3616606870a471bd7
2 parents d4566e5 + 62b6dfb commit 2433e7a

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ require (
1616
go.opentelemetry.io/otel/sdk v1.28.0
1717
go.opentelemetry.io/otel/trace v1.28.0
1818
golang.org/x/net v0.26.0
19-
k8s.io/api v0.0.0-20240720022854-7d5e5eaf3aef
19+
k8s.io/api v0.0.0-20240722223049-b689d905290f
2020
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe
21-
k8s.io/apiserver v0.0.0-20240720104541-d681845e4f6a
22-
k8s.io/client-go v0.0.0-20240720223250-82af755eff54
21+
k8s.io/apiserver v0.0.0-20240723030233-2b2a4b0fa8e4
22+
k8s.io/client-go v0.0.0-20240723023642-bad8f77ca6ef
2323
k8s.io/code-generator v0.0.0-20240720023521-ec3cc888df4c
24-
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25
24+
k8s.io/component-base v0.0.0-20240722183709-6cc953a9d440
2525
k8s.io/klog/v2 v2.130.1
2626
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
2727
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,18 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
278278
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
279279
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
280280
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
281-
k8s.io/api v0.0.0-20240720022854-7d5e5eaf3aef h1:srEy4lds3ddDhT+cxFy68Uvt3GVRTo3fwnw+Us/Nqqs=
282-
k8s.io/api v0.0.0-20240720022854-7d5e5eaf3aef/go.mod h1:SvpyE6bmVBf1ly5BaD4y6yym4ZpHrV2pa8tTRjcglaA=
281+
k8s.io/api v0.0.0-20240722223049-b689d905290f h1:wtqzslJEcheiQ7hXjw1yGfqUyMCb7G4j72aL64Bzpbo=
282+
k8s.io/api v0.0.0-20240722223049-b689d905290f/go.mod h1:ytlEzqC2wOTwYET71W7+J+k7O2V7vrDuzmNLBSpgT+k=
283283
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe h1:V9MwpYUwbKlfLKVrhpVuKWiat/LBIhm1pGB9/xdHm5Q=
284284
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
285-
k8s.io/apiserver v0.0.0-20240720104541-d681845e4f6a h1:Hcn+rrkkCCMuRxtWTpGdVZhrkfKiQkZI+peIJIRuqnM=
286-
k8s.io/apiserver v0.0.0-20240720104541-d681845e4f6a/go.mod h1:UFdCOgZ0UgBzrSbF5rc3eVHS4OhIdbnIFYEITre8ZT8=
287-
k8s.io/client-go v0.0.0-20240720223250-82af755eff54 h1:BQ6OUPmYQm6GUJsPJrV4ouPTusfkZvo08u7uxXZEK4A=
288-
k8s.io/client-go v0.0.0-20240720223250-82af755eff54/go.mod h1:GaT6DD2rtHnEnFV8iJ38Y8SemkQQI9E00pYBv8+d0Xc=
285+
k8s.io/apiserver v0.0.0-20240723030233-2b2a4b0fa8e4 h1:7nrffLiDUbMAXLKzBvyU8rwLHw5WpCw2AjhDO5IZYRs=
286+
k8s.io/apiserver v0.0.0-20240723030233-2b2a4b0fa8e4/go.mod h1:R1HYbPCD+ClvTmzeLBYaS4aktC3entK1o4hyD+WemtA=
287+
k8s.io/client-go v0.0.0-20240723023642-bad8f77ca6ef h1:+munBmXPvgGM5AFzdZh7Xe7S2LJ9udXYRfBDfm+0Eac=
288+
k8s.io/client-go v0.0.0-20240723023642-bad8f77ca6ef/go.mod h1:L1rDFyPUkmS0j6WXGYh5v/iWsfIFYH+LWnFOT1LCsf4=
289289
k8s.io/code-generator v0.0.0-20240720023521-ec3cc888df4c h1:oiNPH9Y/YrQfxo8eTW/w71aBrSyr9MX/wGBKTwDSZsc=
290290
k8s.io/code-generator v0.0.0-20240720023521-ec3cc888df4c/go.mod h1:TVAwbna2B36D+IsWJ5oHqKZKSU8ZBtxeiMTb7uKM6Z0=
291-
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25 h1:9SIVS17h6glmGM2G4ILkpQRUYc/zZ7y15gD2uaby0rM=
292-
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25/go.mod h1:YYWVx/ele54LQcShCdQpmsIqiHgZ+KjWY7WGMzTjKGk=
291+
k8s.io/component-base v0.0.0-20240722183709-6cc953a9d440 h1:14X+5sRQRsul6tLxIKTP0/DotvWlMd9DFCgMqHP1hZY=
292+
k8s.io/component-base v0.0.0-20240722183709-6cc953a9d440/go.mod h1:dj2Pl05aLcVMZi2NXcwv+M/WdUVPEkisFPjDze7rbSk=
293293
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo=
294294
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8=
295295
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=

pkg/apiserver/apiserver.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -297,25 +297,14 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
297297
}
298298
// We are passing the context to ProxyCerts.RunOnce as it needs to implement RunOnce(ctx) however the
299299
// 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 {
302301
return nil, err
303302
}
304303
aggregatorProxyCerts.AddListener(apiserviceRegistrationController)
305304
s.proxyCurrentCertKeyContent = aggregatorProxyCerts.CurrentCertKeyContent
306305

307306
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)
319308
return nil
320309
})
321310
}
@@ -373,9 +362,9 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
373362
}
374363

375364
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)
377366
select {
378-
case <-context.StopCh:
367+
case <-context.Done():
379368
case <-apiServiceRegistrationControllerInitiated:
380369
}
381370

@@ -394,7 +383,7 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
394383
// Discovery aggregation depends on the apiservice registration controller
395384
// having the full list of APIServices already synced
396385
select {
397-
case <-context.StopCh:
386+
case <-context.Done():
398387
return nil
399388
// Context cancelled, should abort/clean goroutines
400389
case <-apiServiceRegistrationControllerInitiated:
@@ -405,10 +394,10 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
405394
// When discovery is ready, all APIServices will be present, with APIServices
406395
// that have not successfully synced discovery to be present but marked as Stale.
407396
discoverySyncedCh := make(chan struct{})
408-
go s.discoveryAggregationController.Run(context.StopCh, discoverySyncedCh)
397+
go s.discoveryAggregationController.Run(context.Done(), discoverySyncedCh)
409398

410399
select {
411-
case <-context.StopCh:
400+
case <-context.Done():
412401
return nil
413402
// Context cancelled, should abort/clean goroutines
414403
case <-discoverySyncedCh:
@@ -440,7 +429,7 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
440429
return false, err
441430
}
442431
return true, nil
443-
}, hookContext.StopCh); err != nil {
432+
}, hookContext.Done()); err != nil {
444433
return fmt.Errorf("failed to wait for apiserver-identity lease %s to be created: %v",
445434
s.GenericAPIServer.APIServerID, err)
446435
}
@@ -456,14 +445,14 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
456445
// to register all built-in resources when the generic apiservers install APIs.
457446
s.GenericAPIServer.StorageVersionManager.UpdateStorageVersions(hookContext.LoopbackClientConfig, s.GenericAPIServer.APIServerID)
458447
return false, nil
459-
}, hookContext.StopCh)
448+
}, hookContext.Done())
460449
// Once the storage version updater finishes the first round of update,
461450
// the PostStartHook will return to unblock /healthz. The handler chain
462451
// won't block write requests anymore. Check every second since it's not
463452
// expensive.
464453
wait.PollImmediateUntil(1*time.Second, func() (bool, error) {
465454
return s.GenericAPIServer.StorageVersionManager.Completed(), nil
466-
}, hookContext.StopCh)
455+
}, hookContext.Done())
467456
return nil
468457
})
469458
}
@@ -477,14 +466,14 @@ func (s *APIAggregator) PrepareRun() (preparedAPIAggregator, error) {
477466
// add post start hook before generic PrepareRun in order to be before /healthz installation
478467
if s.openAPIConfig != nil {
479468
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())
481470
return nil
482471
})
483472
}
484473

485474
if s.openAPIV3Config != nil {
486475
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())
488477
return nil
489478
})
490479
}

0 commit comments

Comments
 (0)