diff --git a/docs/configmap-and-annotations.md b/docs/configmap-and-annotations.md index d91fcaa913..bb1bcb74bc 100644 --- a/docs/configmap-and-annotations.md +++ b/docs/configmap-and-annotations.md @@ -166,7 +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/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. For NGINX Plus, shared memory zones are required and cannot be disabled. The special value 0 will be ignored. | `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/version1/nginx-plus.ingress.tmpl b/internal/configs/version1/nginx-plus.ingress.tmpl index 772e8751f3..005241c21d 100644 --- a/internal/configs/version1/nginx-plus.ingress.tmpl +++ b/internal/configs/version1/nginx-plus.ingress.tmpl @@ -1,7 +1,7 @@ # configuration for {{.Ingress.Namespace}}/{{.Ingress.Name}} {{range $upstream := .Upstreams}} upstream {{$upstream.Name}} { - zone {{$upstream.Name}} 256k; + zone {{$upstream.Name}} {{if ne $upstream.UpstreamZoneSize "0"}}{{$upstream.UpstreamZoneSize}}{{else}}256k{{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}} diff --git a/internal/configs/version2/config.go b/internal/configs/version2/config.go index 86506be4d6..b7ad0f86b4 100644 --- a/internal/configs/version2/config.go +++ b/internal/configs/version2/config.go @@ -11,10 +11,11 @@ type VirtualServerConfig struct { // Upstream defines an upstream. type Upstream struct { - Name string - Servers []UpstreamServer - LBMethod string - Keepalive int + Name string + Servers []UpstreamServer + LBMethod string + Keepalive int + UpstreamZoneSize string } // UpstreamServer defines an upstream server. diff --git a/internal/configs/version2/nginx-plus.virtualserver.tmpl b/internal/configs/version2/nginx-plus.virtualserver.tmpl index 564241b949..a7f55e2273 100644 --- a/internal/configs/version2/nginx-plus.virtualserver.tmpl +++ b/internal/configs/version2/nginx-plus.virtualserver.tmpl @@ -1,6 +1,6 @@ {{ range $u := .Upstreams }} upstream {{ $u.Name }} { - zone {{ $u.Name }} 256k; + zone {{ $u.Name }} {{ if ne $u.UpstreamZoneSize "0" }}{{ $u.UpstreamZoneSize }}{{ else }}256k{{ end }}; {{ if $u.LBMethod }}{{ $u.LBMethod }};{{ end }} diff --git a/internal/configs/version2/nginx.virtualserver.tmpl b/internal/configs/version2/nginx.virtualserver.tmpl index 0e26189a0e..6f9fe0fc27 100644 --- a/internal/configs/version2/nginx.virtualserver.tmpl +++ b/internal/configs/version2/nginx.virtualserver.tmpl @@ -1,6 +1,6 @@ {{ range $u := .Upstreams }} upstream {{ $u.Name }} { - zone {{ $u.Name }} 256k; + {{ if ne $u.UpstreamZoneSize "0" }}zone {{ $u.Name }} {{ $u.UpstreamZoneSize }};{{ end }} {{ if $u.LBMethod }}{{ $u.LBMethod }};{{ end }} diff --git a/internal/configs/version2/templates_test.go b/internal/configs/version2/templates_test.go index be1619d8fd..24ec37735c 100644 --- a/internal/configs/version2/templates_test.go +++ b/internal/configs/version2/templates_test.go @@ -17,8 +17,9 @@ var virtualServerCfg = VirtualServerConfig{ MaxConns: 31, }, }, - LBMethod: "random", - Keepalive: 32, + LBMethod: "random", + Keepalive: 32, + UpstreamZoneSize: "256k", }, { Name: "coffee-v1", @@ -29,6 +30,7 @@ var virtualServerCfg = VirtualServerConfig{ FailTimeout: "10s", }, }, + UpstreamZoneSize: "256k", }, { Name: "coffee-v2", @@ -39,6 +41,7 @@ var virtualServerCfg = VirtualServerConfig{ FailTimeout: "10s", }, }, + UpstreamZoneSize: "256k", }, }, SplitClients: []SplitClient{ diff --git a/internal/configs/virtualserver.go b/internal/configs/virtualserver.go index 586bbffbee..25e9e0834c 100644 --- a/internal/configs/virtualserver.go +++ b/internal/configs/virtualserver.go @@ -347,10 +347,11 @@ func generateUpstream(upstreamName string, upstream conf_v1alpha1.Upstream, isEx } return version2.Upstream{ - Name: upstreamName, - Servers: upsServers, - LBMethod: generateLBMethod(upstream.LBMethod, cfgParams.LBMethod), - Keepalive: generateIntFromPointer(upstream.Keepalive, cfgParams.Keepalive), + Name: upstreamName, + Servers: upsServers, + LBMethod: generateLBMethod(upstream.LBMethod, cfgParams.LBMethod), + Keepalive: generateIntFromPointer(upstream.Keepalive, cfgParams.Keepalive), + UpstreamZoneSize: cfgParams.UpstreamZoneSize, } } diff --git a/internal/configs/virtualserver_test.go b/internal/configs/virtualserver_test.go index ab9cb8a0de..9296a44cf9 100644 --- a/internal/configs/virtualserver_test.go +++ b/internal/configs/virtualserver_test.go @@ -772,11 +772,12 @@ func TestGenerateUpstream(t *testing.T) { "192.168.10.10:8080", } cfgParams := ConfigParams{ - LBMethod: "random", - MaxFails: 1, - MaxConns: 0, - FailTimeout: "10s", - Keepalive: 21, + LBMethod: "random", + MaxFails: 1, + MaxConns: 0, + FailTimeout: "10s", + Keepalive: 21, + UpstreamZoneSize: "256k", } expected := version2.Upstream{ @@ -789,8 +790,9 @@ func TestGenerateUpstream(t *testing.T) { FailTimeout: "10s", }, }, - LBMethod: "random", - Keepalive: 21, + LBMethod: "random", + Keepalive: 21, + UpstreamZoneSize: "256k", } result := generateUpstream(name, upstream, false, endpoints, &cfgParams)