Skip to content

Commit 035e272

Browse files
authored
Merge pull request kubernetes#127341 from mjudeikis/mjudeikis/deprecate.ch.fully
Fully deprecate StopCh
2 parents 5ffb052 + fd76176 commit 035e272

File tree

5 files changed

+24
-31
lines changed

5 files changed

+24
-31
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/apiserver.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,37 +219,37 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
219219
crdHandler,
220220
)
221221

222-
s.GenericAPIServer.AddPostStartHookOrDie("start-apiextensions-informers", func(context genericapiserver.PostStartHookContext) error {
223-
s.Informers.Start(context.Done())
222+
s.GenericAPIServer.AddPostStartHookOrDie("start-apiextensions-informers", func(hookContext genericapiserver.PostStartHookContext) error {
223+
s.Informers.Start(hookContext.Done())
224224
return nil
225225
})
226-
s.GenericAPIServer.AddPostStartHookOrDie("start-apiextensions-controllers", func(context genericapiserver.PostStartHookContext) error {
226+
s.GenericAPIServer.AddPostStartHookOrDie("start-apiextensions-controllers", func(hookContext genericapiserver.PostStartHookContext) error {
227227
// OpenAPIVersionedService and StaticOpenAPISpec are populated in generic apiserver PrepareRun().
228228
// Together they serve the /openapi/v2 endpoint on a generic apiserver. A generic apiserver may
229229
// choose to not enable OpenAPI by having null openAPIConfig, and thus OpenAPIVersionedService
230230
// and StaticOpenAPISpec are both null. In that case we don't run the CRD OpenAPI controller.
231231
if s.GenericAPIServer.StaticOpenAPISpec != nil {
232232
if s.GenericAPIServer.OpenAPIVersionedService != nil {
233233
openapiController := openapicontroller.NewController(s.Informers.Apiextensions().V1().CustomResourceDefinitions())
234-
go openapiController.Run(s.GenericAPIServer.StaticOpenAPISpec, s.GenericAPIServer.OpenAPIVersionedService, context.Done())
234+
go openapiController.Run(s.GenericAPIServer.StaticOpenAPISpec, s.GenericAPIServer.OpenAPIVersionedService, hookContext.Done())
235235
}
236236

237237
if s.GenericAPIServer.OpenAPIV3VersionedService != nil {
238238
openapiv3Controller := openapiv3controller.NewController(s.Informers.Apiextensions().V1().CustomResourceDefinitions())
239-
go openapiv3Controller.Run(s.GenericAPIServer.OpenAPIV3VersionedService, context.Done())
239+
go openapiv3Controller.Run(s.GenericAPIServer.OpenAPIV3VersionedService, hookContext.Done())
240240
}
241241
}
242242

243-
go namingController.Run(context.Done())
244-
go establishingController.Run(context.Done())
245-
go nonStructuralSchemaController.Run(5, context.Done())
246-
go apiApprovalController.Run(5, context.Done())
247-
go finalizingController.Run(5, context.Done())
243+
go namingController.Run(hookContext.Done())
244+
go establishingController.Run(hookContext.Done())
245+
go nonStructuralSchemaController.Run(5, hookContext.Done())
246+
go apiApprovalController.Run(5, hookContext.Done())
247+
go finalizingController.Run(5, hookContext.Done())
248248

249249
discoverySyncedCh := make(chan struct{})
250-
go discoveryController.Run(context.StopCh, discoverySyncedCh)
250+
go discoveryController.Run(hookContext.Done(), discoverySyncedCh)
251251
select {
252-
case <-context.StopCh:
252+
case <-hookContext.Done():
253253
case <-discoverySyncedCh:
254254
}
255255

staging/src/k8s.io/apiserver/pkg/server/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
886886
genericApiServerHookName := "generic-apiserver-start-informers"
887887
if c.SharedInformerFactory != nil {
888888
if !s.isPostStartHookRegistered(genericApiServerHookName) {
889-
err := s.AddPostStartHook(genericApiServerHookName, func(context PostStartHookContext) error {
890-
c.SharedInformerFactory.Start(context.StopCh)
889+
err := s.AddPostStartHook(genericApiServerHookName, func(hookContext PostStartHookContext) error {
890+
c.SharedInformerFactory.Start(hookContext.Done())
891891
return nil
892892
})
893893
if err != nil {
@@ -904,8 +904,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
904904
const priorityAndFairnessConfigConsumerHookName = "priority-and-fairness-config-consumer"
905905
if s.isPostStartHookRegistered(priorityAndFairnessConfigConsumerHookName) {
906906
} else if c.FlowControl != nil {
907-
err := s.AddPostStartHook(priorityAndFairnessConfigConsumerHookName, func(context PostStartHookContext) error {
908-
go c.FlowControl.Run(context.StopCh)
907+
err := s.AddPostStartHook(priorityAndFairnessConfigConsumerHookName, func(hookContext PostStartHookContext) error {
908+
go c.FlowControl.Run(hookContext.Done())
909909
return nil
910910
})
911911
if err != nil {
@@ -920,8 +920,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
920920
if c.FlowControl != nil {
921921
const priorityAndFairnessFilterHookName = "priority-and-fairness-filter"
922922
if !s.isPostStartHookRegistered(priorityAndFairnessFilterHookName) {
923-
err := s.AddPostStartHook(priorityAndFairnessFilterHookName, func(context PostStartHookContext) error {
924-
genericfilters.StartPriorityAndFairnessWatermarkMaintenance(context.StopCh)
923+
err := s.AddPostStartHook(priorityAndFairnessFilterHookName, func(hookContext PostStartHookContext) error {
924+
genericfilters.StartPriorityAndFairnessWatermarkMaintenance(hookContext.Done())
925925
return nil
926926
})
927927
if err != nil {
@@ -931,8 +931,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
931931
} else {
932932
const maxInFlightFilterHookName = "max-in-flight-filter"
933933
if !s.isPostStartHookRegistered(maxInFlightFilterHookName) {
934-
err := s.AddPostStartHook(maxInFlightFilterHookName, func(context PostStartHookContext) error {
935-
genericfilters.StartMaxInFlightWatermarkMaintenance(context.StopCh)
934+
err := s.AddPostStartHook(maxInFlightFilterHookName, func(hookContext PostStartHookContext) error {
935+
genericfilters.StartMaxInFlightWatermarkMaintenance(hookContext.Done())
936936
return nil
937937
})
938938
if err != nil {
@@ -945,8 +945,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
945945
if c.StorageObjectCountTracker != nil {
946946
const storageObjectCountTrackerHookName = "storage-object-count-tracker-hook"
947947
if !s.isPostStartHookRegistered(storageObjectCountTrackerHookName) {
948-
if err := s.AddPostStartHook(storageObjectCountTrackerHookName, func(context PostStartHookContext) error {
949-
go c.StorageObjectCountTracker.RunUntil(context.StopCh)
948+
if err := s.AddPostStartHook(storageObjectCountTrackerHookName, func(hookContext PostStartHookContext) error {
949+
go c.StorageObjectCountTracker.RunUntil(hookContext.Done())
950950
return nil
951951
}); err != nil {
952952
return nil, err

staging/src/k8s.io/apiserver/pkg/server/hooks.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ type PreShutdownHookFunc func() error
4949
type PostStartHookContext struct {
5050
// LoopbackClientConfig is a config for a privileged loopback connection to the API server
5151
LoopbackClientConfig *restclient.Config
52-
// StopCh is the channel that will be closed when the server stops.
53-
//
54-
// Deprecated: use the PostStartHookContext itself instead, it contains a context that
55-
// gets cancelled when the server stops. StopCh keeps getting provided for existing code.
56-
StopCh <-chan struct{}
5752
// Context gets cancelled when the server stops.
5853
context.Context
5954
}
@@ -165,7 +160,6 @@ func (s *GenericAPIServer) RunPostStartHooks(ctx context.Context) {
165160

166161
context := PostStartHookContext{
167162
LoopbackClientConfig: s.LoopbackClientConfig,
168-
StopCh: ctx.Done(),
169163
Context: ctx,
170164
}
171165

staging/src/k8s.io/apiserver/pkg/server/options/admission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ func (a *AdmissionOptions) ApplyTo(
157157
initializersChain := admission.PluginInitializers{genericInitializer}
158158
initializersChain = append(initializersChain, pluginInitializers...)
159159

160-
admissionPostStartHook := func(context server.PostStartHookContext) error {
160+
admissionPostStartHook := func(hookContext server.PostStartHookContext) error {
161161
discoveryRESTMapper.Reset()
162-
go utilwait.Until(discoveryRESTMapper.Reset, 30*time.Second, context.StopCh)
162+
go utilwait.Until(discoveryRESTMapper.Reset, 30*time.Second, hookContext.Done())
163163
return nil
164164
}
165165

staging/src/k8s.io/apiserver/pkg/server/storage_readiness_hook_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func TestStorageReadinessHookTimeout(t *testing.T) {
7676
ctx := context.Background()
7777
hookCtx := PostStartHookContext{
7878
LoopbackClientConfig: nil,
79-
StopCh: ctx.Done(),
8079
Context: ctx,
8180
}
8281
if err := h.Hook(hookCtx); err != nil {

0 commit comments

Comments
 (0)