Skip to content

Commit

Permalink
Make shutdown grace periods to more reasonable defaults
Browse files Browse the repository at this point in the history
Note that post-shutdown-grace-period doesn't seem to contribute to graceful shutdown,
see #8095 for discussion.
  • Loading branch information
motoki317 committed Nov 28, 2024
1 parent 25f5d09 commit 3fe18f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ Takes the form "<host>:port". If not provided, no admission controller is starte

statusUpdateInterval = flags.Int("status-update-interval", status.UpdateInterval, "Time interval in seconds in which the status should check if an update is required. Default is 60 seconds")

shutdownGracePeriod = flags.Int("shutdown-grace-period", 0, "Seconds to wait after receiving the shutdown signal, before stopping the nginx process.")
shutdownGracePeriod = flags.Int("shutdown-grace-period", 10, "Seconds to wait after receiving the shutdown signal, before stopping the nginx process.")

postShutdownGracePeriod = flags.Int("post-shutdown-grace-period", 10, "Seconds to wait after the nginx process has stopped before controller exits.")
postShutdownGracePeriod = flags.Int("post-shutdown-grace-period", 0, `[IN DEPRECATION] Seconds to wait after the nginx process has stopped before controller exits.
Note that increasing this value doesn't seem to contribute to graceful shutdown of the ingress controller.
If you would like to configure period for accepting requests before shutting down, use 'shutdown-grace-period' instead.'`)

deepInspector = flags.Bool("deep-inspect", true, "Enables ingress object security deep inspector")

Expand Down
10 changes: 6 additions & 4 deletions pkg/util/process/sigterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ limitations under the License.
package process

import (
klog "k8s.io/klog/v2"
"os"
"os/signal"
"syscall"
"time"

klog "k8s.io/klog/v2"
)

type exiter func(code int)
Expand All @@ -41,8 +40,11 @@ func HandleSigterm(ngx Controller, delay int, exit exiter) {
exitCode = 1
}

klog.Infof("Handled quit, delaying controller exit for %d seconds", delay)
time.Sleep(time.Duration(delay) * time.Second)
if delay > 0 {
klog.Warning("[DEPRECATED] Delaying controller exit for %d seconds", delay)
klog.Warning("[DEPRECATED] 'post-shutdown-grace-period' does not have any effect for graceful shutdown - use 'shutdown-grace-period' flag instead.")
time.Sleep(time.Duration(delay) * time.Second)
}

klog.InfoS("Exiting", "code", exitCode)
exit(exitCode)
Expand Down

0 comments on commit 3fe18f1

Please sign in to comment.