From d9e7d1eabcc1ca689c2b396c2832b3495faae00f Mon Sep 17 00:00:00 2001 From: Max Laverse Date: Tue, 29 Aug 2017 11:49:18 +0200 Subject: [PATCH] Add support for 'worker-shutdown-timeout' --- controllers/nginx/configuration.md | 4 +++- controllers/nginx/pkg/config/config.go | 5 +++++ controllers/nginx/pkg/template/configmap_test.go | 2 ++ controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/controllers/nginx/configuration.md b/controllers/nginx/configuration.md index 1dd04921e7..30a96078de 100644 --- a/controllers/nginx/configuration.md +++ b/controllers/nginx/configuration.md @@ -187,7 +187,7 @@ the whole body or only its part is written to a temporary file. By default, buff This is 8K on x86, other 32-bit platforms, and x86-64. It is usually 16K on other 64-bit platforms. This annotation is applied to each location provided in the ingress rule. -*Note:* The annotation value must be given in a valid format otherwise the +*Note:* The annotation value must be given in a valid format otherwise the For example to set the client-body-buffer-size the following can be done: * `ingress.kubernetes.io/client-body-buffer-size: "1000"` # 1000 bytes * `ingress.kubernetes.io/client-body-buffer-size: 1k` # 1 kilobyte @@ -467,6 +467,8 @@ The default mime type list to compress is: `application/atom+xml application/jav **worker-processes:** Sets the number of [worker processes](http://nginx.org/en/docs/ngx_core_module.html#worker_processes). The default of "auto" means number of available CPU cores. +**worker-shutdown-timeout:** Sets a timeout for Nginx to [wait for worker to gracefully shutdown](http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout). The default is "10s". + **limit-conn-zone-variable:** Sets parameters for a shared memory zone that will keep states for various keys of [limit_conn_zone](http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html#limit_conn_zone). The default of "$binary_remote_addr" variable’s size is always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses. **proxy-set-headers:** Sets custom headers from a configmap before sending traffic to backends. See [example](https://github.com/kubernetes/ingress/tree/master/examples/customization/custom-headers/nginx) diff --git a/controllers/nginx/pkg/config/config.go b/controllers/nginx/pkg/config/config.go index 8b02483ac3..4e1b5373a2 100644 --- a/controllers/nginx/pkg/config/config.go +++ b/controllers/nginx/pkg/config/config.go @@ -315,6 +315,10 @@ type Configuration struct { // http://nginx.org/en/docs/ngx_core_module.html#worker_processes WorkerProcesses string `json:"worker-processes,omitempty"` + // Defines a timeout for a graceful shutdown of worker processes + // http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout + WorkerShutdownTimeout string `json:"worker-shutdown-timeout,omitempty"` + // Defines the load balancing algorithm to use. The deault is round-robin LoadBalanceAlgorithm string `json:"load-balance,omitempty"` @@ -397,6 +401,7 @@ func NewDefault() Configuration { SSLSessionTimeout: sslSessionTimeout, UseGzip: true, WorkerProcesses: strconv.Itoa(runtime.NumCPU()), + WorkerShutdownTimeout: "10s", LoadBalanceAlgorithm: defaultLoadBalancerAlgorithm, VtsStatusZoneSize: "10m", VariablesHashBucketSize: 64, diff --git a/controllers/nginx/pkg/template/configmap_test.go b/controllers/nginx/pkg/template/configmap_test.go index 6561974e18..59bddbc56f 100644 --- a/controllers/nginx/pkg/template/configmap_test.go +++ b/controllers/nginx/pkg/template/configmap_test.go @@ -46,6 +46,7 @@ func TestMergeConfigMapToStruct(t *testing.T) { "gzip-types": "text/html", "proxy-real-ip-cidr": "1.1.1.1/8,2.2.2.2/24", "bind-address": "1.1.1.1,2.2.2.2,3.3.3,2001:db8:a0b:12f0::1,3731:54:65fe:2::a7,33:33:33::33::33", + "worker-shutdown-timeout": "99s", } def := config.NewDefault() def.CustomHTTPErrors = []int{300, 400} @@ -61,6 +62,7 @@ func TestMergeConfigMapToStruct(t *testing.T) { def.ProxyRealIPCIDR = []string{"1.1.1.1/8", "2.2.2.2/24"} def.BindAddressIpv4 = []string{"1.1.1.1", "2.2.2.2"} def.BindAddressIpv6 = []string{"[2001:db8:a0b:12f0::1]", "[3731:54:65fe:2::a7]"} + def.WorkerShutdownTimeout = "99s" to := ReadConfig(conf) if diff := pretty.Compare(to, def); diff != "" { diff --git a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl index bfac4706a7..29d3c53d7a 100644 --- a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl +++ b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl @@ -16,7 +16,7 @@ worker_rlimit_nofile {{ .MaxOpenFiles }}; {{/* http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout */}} {{/* avoid waiting too long during a reload */}} -worker_shutdown_timeout 10s; +worker_shutdown_timeout {{ $cfg.WorkerShutdownTimeout }} ; events { multi_accept on;