Allow to configure delay before controller exits (#8143)

* Allow to configure delay before controller exits

Signed-off-by: Aditya Kamath <theunrealgeek@gmail.com>

* Address comments

Signed-off-by: Aditya Kamath <theunrealgeek@gmail.com>
This commit is contained in:
Aditya Kamath 2022-01-17 15:24:49 -08:00 committed by GitHub
parent 4badf20173
commit 2aa34202c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 6 deletions

View file

@ -155,14 +155,14 @@ func main() {
go startHTTPServer(conf.HealthCheckHost, conf.ListenPorts.Health, mux)
go ngx.Start()
handleSigterm(ngx, func(code int) {
handleSigterm(ngx, conf.PostShutdownGracePeriod, func(code int) {
os.Exit(code)
})
}
type exiter func(code int)
func handleSigterm(ngx *controller.NGINXController, exit exiter) {
func handleSigterm(ngx *controller.NGINXController, delay int, exit exiter) {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGTERM)
<-signalChan
@ -174,8 +174,8 @@ func handleSigterm(ngx *controller.NGINXController, exit exiter) {
exitCode = 1
}
klog.InfoS("Handled quit, awaiting Pod deletion")
time.Sleep(10 * time.Second)
klog.Infof("Handled quit, delaying controller exit for %d seconds", delay)
time.Sleep(time.Duration(delay) * time.Second)
klog.InfoS("Exiting", "code", exitCode)
exit(exitCode)