Skip to content

Commit

Permalink
Merge pull request #125661 from mjudeikis/mjudeikis/poststarthookctx.…
Browse files Browse the repository at this point in the history
…stopch.cleanup

Clean deprecated context.StopCh

Kubernetes-commit: bb350f711174670443e23aa3616606870a471bd7
  • Loading branch information
k8s-publishing-bot committed Jul 23, 2024
2 parents d4566e5 + 62b6dfb commit 2433e7a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ require (
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
golang.org/x/net v0.26.0
k8s.io/api v0.0.0-20240720022854-7d5e5eaf3aef
k8s.io/api v0.0.0-20240722223049-b689d905290f
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe
k8s.io/apiserver v0.0.0-20240720104541-d681845e4f6a
k8s.io/client-go v0.0.0-20240720223250-82af755eff54
k8s.io/apiserver v0.0.0-20240723030233-2b2a4b0fa8e4
k8s.io/client-go v0.0.0-20240723023642-bad8f77ca6ef
k8s.io/code-generator v0.0.0-20240720023521-ec3cc888df4c
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25
k8s.io/component-base v0.0.0-20240722183709-6cc953a9d440
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,18 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20240720022854-7d5e5eaf3aef h1:srEy4lds3ddDhT+cxFy68Uvt3GVRTo3fwnw+Us/Nqqs=
k8s.io/api v0.0.0-20240720022854-7d5e5eaf3aef/go.mod h1:SvpyE6bmVBf1ly5BaD4y6yym4ZpHrV2pa8tTRjcglaA=
k8s.io/api v0.0.0-20240722223049-b689d905290f h1:wtqzslJEcheiQ7hXjw1yGfqUyMCb7G4j72aL64Bzpbo=
k8s.io/api v0.0.0-20240722223049-b689d905290f/go.mod h1:ytlEzqC2wOTwYET71W7+J+k7O2V7vrDuzmNLBSpgT+k=
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe h1:V9MwpYUwbKlfLKVrhpVuKWiat/LBIhm1pGB9/xdHm5Q=
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apiserver v0.0.0-20240720104541-d681845e4f6a h1:Hcn+rrkkCCMuRxtWTpGdVZhrkfKiQkZI+peIJIRuqnM=
k8s.io/apiserver v0.0.0-20240720104541-d681845e4f6a/go.mod h1:UFdCOgZ0UgBzrSbF5rc3eVHS4OhIdbnIFYEITre8ZT8=
k8s.io/client-go v0.0.0-20240720223250-82af755eff54 h1:BQ6OUPmYQm6GUJsPJrV4ouPTusfkZvo08u7uxXZEK4A=
k8s.io/client-go v0.0.0-20240720223250-82af755eff54/go.mod h1:GaT6DD2rtHnEnFV8iJ38Y8SemkQQI9E00pYBv8+d0Xc=
k8s.io/apiserver v0.0.0-20240723030233-2b2a4b0fa8e4 h1:7nrffLiDUbMAXLKzBvyU8rwLHw5WpCw2AjhDO5IZYRs=
k8s.io/apiserver v0.0.0-20240723030233-2b2a4b0fa8e4/go.mod h1:R1HYbPCD+ClvTmzeLBYaS4aktC3entK1o4hyD+WemtA=
k8s.io/client-go v0.0.0-20240723023642-bad8f77ca6ef h1:+munBmXPvgGM5AFzdZh7Xe7S2LJ9udXYRfBDfm+0Eac=
k8s.io/client-go v0.0.0-20240723023642-bad8f77ca6ef/go.mod h1:L1rDFyPUkmS0j6WXGYh5v/iWsfIFYH+LWnFOT1LCsf4=
k8s.io/code-generator v0.0.0-20240720023521-ec3cc888df4c h1:oiNPH9Y/YrQfxo8eTW/w71aBrSyr9MX/wGBKTwDSZsc=
k8s.io/code-generator v0.0.0-20240720023521-ec3cc888df4c/go.mod h1:TVAwbna2B36D+IsWJ5oHqKZKSU8ZBtxeiMTb7uKM6Z0=
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25 h1:9SIVS17h6glmGM2G4ILkpQRUYc/zZ7y15gD2uaby0rM=
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25/go.mod h1:YYWVx/ele54LQcShCdQpmsIqiHgZ+KjWY7WGMzTjKGk=
k8s.io/component-base v0.0.0-20240722183709-6cc953a9d440 h1:14X+5sRQRsul6tLxIKTP0/DotvWlMd9DFCgMqHP1hZY=
k8s.io/component-base v0.0.0-20240722183709-6cc953a9d440/go.mod h1:dj2Pl05aLcVMZi2NXcwv+M/WdUVPEkisFPjDze7rbSk=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
Expand Down
35 changes: 12 additions & 23 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,14 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
}
// We are passing the context to ProxyCerts.RunOnce as it needs to implement RunOnce(ctx) however the
// context is not used at all. So passing a empty context shouldn't be a problem
ctx := context.TODO()
if err := aggregatorProxyCerts.RunOnce(ctx); err != nil {
if err := aggregatorProxyCerts.RunOnce(context.Background()); err != nil {
return nil, err
}
aggregatorProxyCerts.AddListener(apiserviceRegistrationController)
s.proxyCurrentCertKeyContent = aggregatorProxyCerts.CurrentCertKeyContent

s.GenericAPIServer.AddPostStartHookOrDie("aggregator-reload-proxy-client-cert", func(postStartHookContext genericapiserver.PostStartHookContext) error {
// generate a context from stopCh. This is to avoid modifying files which are relying on apiserver
// TODO: See if we can pass ctx to the current method
ctx, cancel := context.WithCancel(context.Background())
go func() {
select {
case <-postStartHookContext.StopCh:
cancel() // stopCh closed, so cancel our context
case <-ctx.Done():
}
}()
go aggregatorProxyCerts.Run(ctx, 1)
go aggregatorProxyCerts.Run(postStartHookContext, 1)
return nil
})
}
Expand Down Expand Up @@ -373,9 +362,9 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
}

s.GenericAPIServer.AddPostStartHookOrDie("apiservice-registration-controller", func(context genericapiserver.PostStartHookContext) error {
go apiserviceRegistrationController.Run(context.StopCh, apiServiceRegistrationControllerInitiated)
go apiserviceRegistrationController.Run(context.Done(), apiServiceRegistrationControllerInitiated)
select {
case <-context.StopCh:
case <-context.Done():
case <-apiServiceRegistrationControllerInitiated:
}

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

select {
case <-context.StopCh:
case <-context.Done():
return nil
// Context cancelled, should abort/clean goroutines
case <-discoverySyncedCh:
Expand Down Expand Up @@ -440,7 +429,7 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
return false, err
}
return true, nil
}, hookContext.StopCh); err != nil {
}, hookContext.Done()); err != nil {
return fmt.Errorf("failed to wait for apiserver-identity lease %s to be created: %v",
s.GenericAPIServer.APIServerID, err)
}
Expand All @@ -456,14 +445,14 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
// to register all built-in resources when the generic apiservers install APIs.
s.GenericAPIServer.StorageVersionManager.UpdateStorageVersions(hookContext.LoopbackClientConfig, s.GenericAPIServer.APIServerID)
return false, nil
}, hookContext.StopCh)
}, hookContext.Done())
// Once the storage version updater finishes the first round of update,
// the PostStartHook will return to unblock /healthz. The handler chain
// won't block write requests anymore. Check every second since it's not
// expensive.
wait.PollImmediateUntil(1*time.Second, func() (bool, error) {
return s.GenericAPIServer.StorageVersionManager.Completed(), nil
}, hookContext.StopCh)
}, hookContext.Done())
return nil
})
}
Expand All @@ -477,14 +466,14 @@ func (s *APIAggregator) PrepareRun() (preparedAPIAggregator, error) {
// add post start hook before generic PrepareRun in order to be before /healthz installation
if s.openAPIConfig != nil {
s.GenericAPIServer.AddPostStartHookOrDie("apiservice-openapi-controller", func(context genericapiserver.PostStartHookContext) error {
go s.openAPIAggregationController.Run(context.StopCh)
go s.openAPIAggregationController.Run(context.Done())
return nil
})
}

if s.openAPIV3Config != nil {
s.GenericAPIServer.AddPostStartHookOrDie("apiservice-openapiv3-controller", func(context genericapiserver.PostStartHookContext) error {
go s.openAPIV3AggregationController.Run(context.StopCh)
go s.openAPIV3AggregationController.Run(context.Done())
return nil
})
}
Expand Down

0 comments on commit 2433e7a

Please sign in to comment.