diff --git a/docs/configmap-and-annotations.md b/docs/configmap-and-annotations.md index 43fc7aaf69..d91fcaa913 100644 --- a/docs/configmap-and-annotations.md +++ b/docs/configmap-and-annotations.md @@ -166,6 +166,7 @@ spec: | `nginx.org/websocket-services` | N/A | Enables WebSocket for services. | N/A | [WebSocket support](../examples/websocket). | | `nginx.org/max-fails` | `max-fails` | Sets the value of the [max_fails](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_fails) parameter of the `server` directive. | `1` | | | `nginx.org/max-conns` | N\A | Sets the value of the [max_conns](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_conns) parameter of the `server` directive. | `0` | | +| `nginx.org/upstream-zone-size` | `upstream-zone-size` | Sets the size of the shared memory [zone](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#zone) for upstreams. For NGINX, the special value `0` disables the shared memory zones. | `256K` | | | `nginx.org/fail-timeout` | `fail-timeout` | Sets the value of the [fail_timeout](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#fail_timeout) parameter of the `server` directive. | `10s` | | | `nginx.com/sticky-cookie-services` | N/A | Configures session persistence. | N/A | [Session Persistence](../examples/session-persistence). | | `nginx.org/keepalive` | `keepalive` | Sets the value of the [keepalive](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive) directive. Note that `proxy_set_header Connection "";` is added to the generated configuration when the value > 0. | `0` | | diff --git a/internal/configs/annotations.go b/internal/configs/annotations.go index df99e07837..25a3e58c9d 100644 --- a/internal/configs/annotations.go +++ b/internal/configs/annotations.go @@ -45,6 +45,7 @@ var minionInheritanceList = map[string]bool{ "nginx.org/proxy-buffers": true, "nginx.org/proxy-buffer-size": true, "nginx.org/proxy-max-temp-file-size": true, + "nginx.org/upstream-zone-size": true, "nginx.org/location-snippets": true, "nginx.org/lb-method": true, "nginx.org/keepalive": true, @@ -247,6 +248,10 @@ func parseAnnotations(ingEx *IngressEx, baseCfgParams *ConfigParams, isPlus bool cfgParams.ProxyBufferSize = proxyBufferSize } + if upstreamZoneSize, exists := ingEx.Ingress.Annotations["nginx.org/upstream-zone-size"]; exists { + cfgParams.UpstreamZoneSize = upstreamZoneSize + } + if proxyMaxTempFileSize, exists := ingEx.Ingress.Annotations["nginx.org/proxy-max-temp-file-size"]; exists { cfgParams.ProxyMaxTempFileSize = proxyMaxTempFileSize } diff --git a/internal/configs/config_params.go b/internal/configs/config_params.go index 953781acbd..c39f2da811 100644 --- a/internal/configs/config_params.go +++ b/internal/configs/config_params.go @@ -29,6 +29,7 @@ type ConfigParams struct { ProxyProtocol bool ProxyHideHeaders []string ProxyPassHeaders []string + UpstreamZoneSize string HSTS bool HSTSBehindProxy bool HSTSMaxAge int64 @@ -109,6 +110,7 @@ func NewDefaultConfigParams() *ConfigParams { SSLPorts: []int{443}, MaxFails: 1, MaxConns: 0, + UpstreamZoneSize: "256k", FailTimeout: "10s", LBMethod: "random two least_conn", MainErrorLogLevel: "notice", diff --git a/internal/configs/configmaps.go b/internal/configs/configmaps.go index 02cbbee5a7..920a78ef1f 100644 --- a/internal/configs/configmaps.go +++ b/internal/configs/configmaps.go @@ -307,6 +307,10 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool) *ConfigParams { } } + if upstreamZoneSize, exists := cfgm.Data["upstream-zone-size"]; exists { + cfgParams.UpstreamZoneSize = upstreamZoneSize + } + if failTimeout, exists := cfgm.Data["fail-timeout"]; exists { cfgParams.FailTimeout = failTimeout } diff --git a/internal/configs/ingress.go b/internal/configs/ingress.go index 00ac2fba1d..6fef682098 100644 --- a/internal/configs/ingress.go +++ b/internal/configs/ingress.go @@ -301,6 +301,7 @@ func createUpstream(ingEx *IngressEx, name string, backend *extensions.IngressBa } ups.LBMethod = cfg.LBMethod + ups.UpstreamZoneSize = cfg.UpstreamZoneSize return ups } diff --git a/internal/configs/ingress_test.go b/internal/configs/ingress_test.go index ac957be713..d09630e07f 100644 --- a/internal/configs/ingress_test.go +++ b/internal/configs/ingress_test.go @@ -125,6 +125,7 @@ func createExpectedConfigForCafeIngressEx() version1.IngressNginxConfig { coffeeUpstream := version1.Upstream{ Name: "default-cafe-ingress-cafe.example.com-coffee-svc-80", LBMethod: "random two least_conn", + UpstreamZoneSize: "256k", UpstreamServers: []version1.UpstreamServer{ { Address: "10.0.0.1", @@ -137,6 +138,7 @@ func createExpectedConfigForCafeIngressEx() version1.IngressNginxConfig { teaUpstream := version1.Upstream{ Name: "default-cafe-ingress-cafe.example.com-tea-svc-80", LBMethod: "random two least_conn", + UpstreamZoneSize: "256k", UpstreamServers: []version1.UpstreamServer{ { Address: "10.0.0.2", @@ -476,6 +478,7 @@ func createExpectedConfigForMergeableCafeIngress() version1.IngressNginxConfig { coffeeUpstream := version1.Upstream{ Name: "default-cafe-ingress-coffee-minion-cafe.example.com-coffee-svc-80", LBMethod: "random two least_conn", + UpstreamZoneSize: "256k", UpstreamServers: []version1.UpstreamServer{ { Address: "10.0.0.1", @@ -488,6 +491,7 @@ func createExpectedConfigForMergeableCafeIngress() version1.IngressNginxConfig { teaUpstream := version1.Upstream{ Name: "default-cafe-ingress-tea-minion-cafe.example.com-tea-svc-80", LBMethod: "random two least_conn", + UpstreamZoneSize: "256k", UpstreamServers: []version1.UpstreamServer{ { Address: "10.0.0.2", diff --git a/internal/configs/version1/config.go b/internal/configs/version1/config.go index 84091218d7..994796e649 100644 --- a/internal/configs/version1/config.go +++ b/internal/configs/version1/config.go @@ -23,6 +23,7 @@ type Upstream struct { LBMethod string Queue int64 QueueTimeout int64 + UpstreamZoneSize string } // UpstreamServer describes a server in an NGINX upstream. @@ -169,6 +170,7 @@ type MainConfig struct { func NewUpstreamWithDefaultServer(name string) Upstream { return Upstream{ Name: name, + UpstreamZoneSize: "256k", UpstreamServers: []UpstreamServer{ { Address: "127.0.0.1", diff --git a/internal/configs/version1/nginx.ingress.tmpl b/internal/configs/version1/nginx.ingress.tmpl index d8ba9ff021..c34e977634 100644 --- a/internal/configs/version1/nginx.ingress.tmpl +++ b/internal/configs/version1/nginx.ingress.tmpl @@ -2,6 +2,7 @@ {{range $upstream := .Upstreams}} upstream {{$upstream.Name}} { + {{if ne $upstream.UpstreamZoneSize "0"}}zone {{$upstream.Name}} {{$upstream.UpstreamZoneSize}};{{end}} {{if $upstream.LBMethod }}{{$upstream.LBMethod}};{{end}} {{range $server := $upstream.UpstreamServers}} server {{$server.Address}}:{{$server.Port}} max_fails={{$server.MaxFails}} fail_timeout={{$server.FailTimeout}} max_conns={{$server.MaxConns}};{{end}} diff --git a/internal/configs/version1/templates_test.go b/internal/configs/version1/templates_test.go index 5e4958129e..6b04e821d4 100644 --- a/internal/configs/version1/templates_test.go +++ b/internal/configs/version1/templates_test.go @@ -13,6 +13,7 @@ const nginxPlusMainTmpl = "nginx-plus.tmpl" var testUps = Upstream{ Name: "test", + UpstreamZoneSize: "256k", UpstreamServers: []UpstreamServer{ { Address: "127.0.0.1",