diff --git a/staging/src/k8s.io/apiserver/pkg/server/config.go b/staging/src/k8s.io/apiserver/pkg/server/config.go index cf33ee4b2a9..6d1734d115b 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/config.go +++ b/staging/src/k8s.io/apiserver/pkg/server/config.go @@ -96,6 +96,8 @@ type Config struct { EnableContentionProfiling bool EnableMetrics bool + DisabledPostStartHooks sets.String + // Version will enable the /version endpoint if non-nil Version *version.Info // AuditWriter is the destination for audit logs. If nil, they will not be written. @@ -203,6 +205,7 @@ func NewConfig(codecs serializer.CodecFactory) *Config { RequestContextMapper: apirequest.NewRequestContextMapper(), BuildHandlerChainFunc: DefaultBuildHandlerChain, LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix), + DisabledPostStartHooks: sets.NewString(), HealthzChecks: []healthz.HealthzChecker{healthz.PingHealthz}, EnableIndex: true, EnableDiscovery: true, @@ -415,8 +418,10 @@ func (c completedConfig) constructServer() (*GenericAPIServer, error) { swaggerConfig: c.SwaggerConfig, openAPIConfig: c.OpenAPIConfig, - postStartHooks: map[string]postStartHookEntry{}, - healthzChecks: c.HealthzChecks, + postStartHooks: map[string]postStartHookEntry{}, + disabledPostStartHooks: c.DisabledPostStartHooks, + + healthzChecks: c.HealthzChecks, } return s, nil diff --git a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go index 158b5295b3a..99af65b41f7 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go +++ b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go @@ -143,10 +143,11 @@ type GenericAPIServer struct { // PostStartHooks are each called after the server has started listening, in a separate go func for each // with no guarantee of ordering between them. The map key is a name used for error reporting. - // It may kill the process with a panic if it wishes to by returning an error - postStartHookLock sync.Mutex - postStartHooks map[string]postStartHookEntry - postStartHooksCalled bool + // It may kill the process with a panic if it wishes to by returning an error. + postStartHookLock sync.Mutex + postStartHooks map[string]postStartHookEntry + postStartHooksCalled bool + disabledPostStartHooks sets.String // healthz checks healthzLock sync.Mutex diff --git a/staging/src/k8s.io/apiserver/pkg/server/hooks.go b/staging/src/k8s.io/apiserver/pkg/server/hooks.go index 16e1cb5cc29..89ba6288a93 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/hooks.go +++ b/staging/src/k8s.io/apiserver/pkg/server/hooks.go @@ -65,6 +65,9 @@ func (s *GenericAPIServer) AddPostStartHook(name string, hook PostStartHookFunc) if hook == nil { return nil } + if s.disabledPostStartHooks.Has(name) { + return nil + } s.postStartHookLock.Lock() defer s.postStartHookLock.Unlock()