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:
parent
4badf20173
commit
2aa34202c1
5 changed files with 11 additions and 6 deletions
|
@ -197,6 +197,8 @@ 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")
|
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", 0, "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.")
|
||||||
)
|
)
|
||||||
|
|
||||||
flags.StringVar(&nginx.MaxmindMirror, "maxmind-mirror", "", `Maxmind mirror url (example: http://geoip.local/databases`)
|
flags.StringVar(&nginx.MaxmindMirror, "maxmind-mirror", "", `Maxmind mirror url (example: http://geoip.local/databases`)
|
||||||
|
@ -321,6 +323,7 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
||||||
PublishStatusAddress: *publishStatusAddress,
|
PublishStatusAddress: *publishStatusAddress,
|
||||||
UpdateStatusOnShutdown: *updateStatusOnShutdown,
|
UpdateStatusOnShutdown: *updateStatusOnShutdown,
|
||||||
ShutdownGracePeriod: *shutdownGracePeriod,
|
ShutdownGracePeriod: *shutdownGracePeriod,
|
||||||
|
PostShutdownGracePeriod: *postShutdownGracePeriod,
|
||||||
UseNodeInternalIP: *useNodeInternalIP,
|
UseNodeInternalIP: *useNodeInternalIP,
|
||||||
SyncRateLimit: *syncRateLimit,
|
SyncRateLimit: *syncRateLimit,
|
||||||
HealthCheckHost: *healthzHost,
|
HealthCheckHost: *healthzHost,
|
||||||
|
|
|
@ -155,14 +155,14 @@ func main() {
|
||||||
go startHTTPServer(conf.HealthCheckHost, conf.ListenPorts.Health, mux)
|
go startHTTPServer(conf.HealthCheckHost, conf.ListenPorts.Health, mux)
|
||||||
go ngx.Start()
|
go ngx.Start()
|
||||||
|
|
||||||
handleSigterm(ngx, func(code int) {
|
handleSigterm(ngx, conf.PostShutdownGracePeriod, func(code int) {
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type exiter func(code int)
|
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)
|
signalChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(signalChan, syscall.SIGTERM)
|
signal.Notify(signalChan, syscall.SIGTERM)
|
||||||
<-signalChan
|
<-signalChan
|
||||||
|
@ -174,8 +174,8 @@ func handleSigterm(ngx *controller.NGINXController, exit exiter) {
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.InfoS("Handled quit, awaiting Pod deletion")
|
klog.Infof("Handled quit, delaying controller exit for %d seconds", delay)
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(time.Duration(delay) * time.Second)
|
||||||
|
|
||||||
klog.InfoS("Exiting", "code", exitCode)
|
klog.InfoS("Exiting", "code", exitCode)
|
||||||
exit(exitCode)
|
exit(exitCode)
|
||||||
|
|
|
@ -105,7 +105,7 @@ func TestHandleSigterm(t *testing.T) {
|
||||||
|
|
||||||
ngx := controller.NewNGINXController(conf, nil)
|
ngx := controller.NewNGINXController(conf, nil)
|
||||||
|
|
||||||
go handleSigterm(ngx, func(code int) {
|
go handleSigterm(ngx, 10, func(code int) {
|
||||||
if code != 1 {
|
if code != 1 {
|
||||||
t.Errorf("Expected exit code 1 but %d received", code)
|
t.Errorf("Expected exit code 1 but %d received", code)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ They are set in the container spec of the `ingress-nginx-controller` Deployment
|
||||||
| `--maxmind-retries-count` | Number of attempts to download the GeoIP DB. (default 1) |
|
| `--maxmind-retries-count` | Number of attempts to download the GeoIP DB. (default 1) |
|
||||||
| `--maxmind-license-key` | Maxmind license key to download GeoLite2 Databases. https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases |
|
| `--maxmind-license-key` | Maxmind license key to download GeoLite2 Databases. https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases |
|
||||||
| `--metrics-per-host` | Export metrics per-host (default true) |
|
| `--metrics-per-host` | Export metrics per-host (default true) |
|
||||||
|
| `--post-shutdown-grace-period` | Additional delay in seconds before controller container exits. (default 10) |
|
||||||
| `--profiler-port` | Port to use for expose the ingress controller Go profiler when it is enabled. (default 10245) |
|
| `--profiler-port` | Port to use for expose the ingress controller Go profiler when it is enabled. (default 10245) |
|
||||||
| `--profiling` | Enable profiling via web interface host:port/debug/pprof/ (default true) |
|
| `--profiling` | Enable profiling via web interface host:port/debug/pprof/ (default true) |
|
||||||
| `--publish-service` | Service fronting the Ingress controller. Takes the form "namespace/name". When used together with update-status, the controller mirrors the address of this service's endpoints to the load-balancer status of all Ingress objects it satisfies. |
|
| `--publish-service` | Service fronting the Ingress controller. Takes the form "namespace/name". When used together with update-status, the controller mirrors the address of this service's endpoints to the load-balancer status of all Ingress objects it satisfies. |
|
||||||
|
|
|
@ -118,7 +118,8 @@ type Configuration struct {
|
||||||
|
|
||||||
MonitorMaxBatchSize int
|
MonitorMaxBatchSize int
|
||||||
|
|
||||||
ShutdownGracePeriod int
|
PostShutdownGracePeriod int
|
||||||
|
ShutdownGracePeriod int
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPublishService returns the Service used to set the load-balancer status of Ingresses.
|
// GetPublishService returns the Service used to set the load-balancer status of Ingresses.
|
||||||
|
|
Loading…
Reference in a new issue