Skip to content

Commit

Permalink
UPSTREAM: <carry>: use lifeCycleSignals for isTerminating
Browse files Browse the repository at this point in the history
  • Loading branch information
tkashem authored and damemi committed Dec 6, 2021
1 parent b0c94df commit ebe594b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
8 changes: 0 additions & 8 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,6 @@ func buildGenericConfig(
lastErr error,
) {
genericConfig = genericapiserver.NewConfig(legacyscheme.Codecs)
genericConfig.IsTerminating = func() bool {
select {
case <-stopCh:
return true
default:
return false
}
}
genericConfig.MergedResourceConfig = controlplane.DefaultAPIResourceConfigSource()

if lastErr = s.GenericServerRunOptions.ApplyTo(genericConfig); lastErr != nil {
Expand Down
5 changes: 1 addition & 4 deletions staging/src/k8s.io/apiserver/pkg/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ type Config struct {

// StorageVersionManager holds the storage versions of the API resources installed by this server.
StorageVersionManager storageversion.Manager

// A func that returns whether the server is terminating. This can be nil.
IsTerminating func() bool
}

// EventSink allows to create events.
Expand Down Expand Up @@ -890,7 +887,7 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler {
if c.ShutdownSendRetryAfter {
handler = genericfilters.WithRetryAfter(handler, c.lifecycleSignals.AfterShutdownDelayDuration.Signaled())
}
handler = genericfilters.WithHTTPLogging(handler, c.IsTerminating)
handler = genericfilters.WithHTTPLogging(handler, c.newIsTerminatingFunc())
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerTracing) {
handler = genericapifilters.WithTracing(handler, c.TracerProvider)
}
Expand Down
39 changes: 39 additions & 0 deletions staging/src/k8s.io/apiserver/pkg/server/patch_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package server

// newIsTerminatingFunc returns a 'func() bool' that relies on the
// 'ShutdownInitiated' life cycle signal of answer if the apiserver
// has started the termination process.
func (c *Config) newIsTerminatingFunc() func() bool {
var shutdownCh <-chan struct{}
// TODO: a properly initialized Config object should always have lifecycleSignals
// initialized, but some config unit tests leave lifecycleSignals as nil.
// Fix the unit tests upstream and then we can remove this check.
if c.lifecycleSignals.ShutdownInitiated != nil {
shutdownCh = c.lifecycleSignals.ShutdownInitiated.Signaled()
}

return func() bool {
select {
case <-shutdownCh:
return true
default:
return false
}
}
}

0 comments on commit ebe594b

Please sign in to comment.