fully remove StopCh

Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt>

Kubernetes-commit: fd76176811654c409cd6799de4a174bcb051a90d
This commit is contained in:
Mangirdas Judeikis 2024-09-13 12:08:57 +03:00 committed by Kubernetes Publisher
parent 9d850afe6f
commit 3e52ced45d
4 changed files with 12 additions and 19 deletions

View File

@ -886,8 +886,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
genericApiServerHookName := "generic-apiserver-start-informers"
if c.SharedInformerFactory != nil {
if !s.isPostStartHookRegistered(genericApiServerHookName) {
err := s.AddPostStartHook(genericApiServerHookName, func(context PostStartHookContext) error {
c.SharedInformerFactory.Start(context.StopCh)
err := s.AddPostStartHook(genericApiServerHookName, func(hookContext PostStartHookContext) error {
c.SharedInformerFactory.Start(hookContext.Done())
return nil
})
if err != nil {
@ -904,8 +904,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
const priorityAndFairnessConfigConsumerHookName = "priority-and-fairness-config-consumer"
if s.isPostStartHookRegistered(priorityAndFairnessConfigConsumerHookName) {
} else if c.FlowControl != nil {
err := s.AddPostStartHook(priorityAndFairnessConfigConsumerHookName, func(context PostStartHookContext) error {
go c.FlowControl.Run(context.StopCh)
err := s.AddPostStartHook(priorityAndFairnessConfigConsumerHookName, func(hookContext PostStartHookContext) error {
go c.FlowControl.Run(hookContext.Done())
return nil
})
if err != nil {
@ -920,8 +920,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
if c.FlowControl != nil {
const priorityAndFairnessFilterHookName = "priority-and-fairness-filter"
if !s.isPostStartHookRegistered(priorityAndFairnessFilterHookName) {
err := s.AddPostStartHook(priorityAndFairnessFilterHookName, func(context PostStartHookContext) error {
genericfilters.StartPriorityAndFairnessWatermarkMaintenance(context.StopCh)
err := s.AddPostStartHook(priorityAndFairnessFilterHookName, func(hookContext PostStartHookContext) error {
genericfilters.StartPriorityAndFairnessWatermarkMaintenance(hookContext.Done())
return nil
})
if err != nil {
@ -931,8 +931,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
} else {
const maxInFlightFilterHookName = "max-in-flight-filter"
if !s.isPostStartHookRegistered(maxInFlightFilterHookName) {
err := s.AddPostStartHook(maxInFlightFilterHookName, func(context PostStartHookContext) error {
genericfilters.StartMaxInFlightWatermarkMaintenance(context.StopCh)
err := s.AddPostStartHook(maxInFlightFilterHookName, func(hookContext PostStartHookContext) error {
genericfilters.StartMaxInFlightWatermarkMaintenance(hookContext.Done())
return nil
})
if err != nil {
@ -945,8 +945,8 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
if c.StorageObjectCountTracker != nil {
const storageObjectCountTrackerHookName = "storage-object-count-tracker-hook"
if !s.isPostStartHookRegistered(storageObjectCountTrackerHookName) {
if err := s.AddPostStartHook(storageObjectCountTrackerHookName, func(context PostStartHookContext) error {
go c.StorageObjectCountTracker.RunUntil(context.StopCh)
if err := s.AddPostStartHook(storageObjectCountTrackerHookName, func(hookContext PostStartHookContext) error {
go c.StorageObjectCountTracker.RunUntil(hookContext.Done())
return nil
}); err != nil {
return nil, err

View File

@ -49,11 +49,6 @@ type PreShutdownHookFunc func() error
type PostStartHookContext struct {
// LoopbackClientConfig is a config for a privileged loopback connection to the API server
LoopbackClientConfig *restclient.Config
// StopCh is the channel that will be closed when the server stops.
//
// Deprecated: use the PostStartHookContext itself instead, it contains a context that
// gets cancelled when the server stops. StopCh keeps getting provided for existing code.
StopCh <-chan struct{}
// Context gets cancelled when the server stops.
context.Context
}
@ -165,7 +160,6 @@ func (s *GenericAPIServer) RunPostStartHooks(ctx context.Context) {
context := PostStartHookContext{
LoopbackClientConfig: s.LoopbackClientConfig,
StopCh: ctx.Done(),
Context: ctx,
}

View File

@ -157,9 +157,9 @@ func (a *AdmissionOptions) ApplyTo(
initializersChain := admission.PluginInitializers{genericInitializer}
initializersChain = append(initializersChain, pluginInitializers...)
admissionPostStartHook := func(context server.PostStartHookContext) error {
admissionPostStartHook := func(hookContext server.PostStartHookContext) error {
discoveryRESTMapper.Reset()
go utilwait.Until(discoveryRESTMapper.Reset, 30*time.Second, context.StopCh)
go utilwait.Until(discoveryRESTMapper.Reset, 30*time.Second, hookContext.Done())
return nil
}

View File

@ -76,7 +76,6 @@ func TestStorageReadinessHookTimeout(t *testing.T) {
ctx := context.Background()
hookCtx := PostStartHookContext{
LoopbackClientConfig: nil,
StopCh: ctx.Done(),
Context: ctx,
}
if err := h.Hook(hookCtx); err != nil {