Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuring upstream zone sizes in VS/VSR #659

Merged
merged 10 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/configmap-and-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | |
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version1/nginx-plus.ingress.tmpl
Original file line number Diff line number Diff line change
@@ -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}}
Expand Down
9 changes: 5 additions & 4 deletions internal/configs/version2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version2/nginx-plus.virtualserver.tmpl
Original file line number Diff line number Diff line change
@@ -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 }}

Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version2/nginx.virtualserver.tmpl
Original file line number Diff line number Diff line change
@@ -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 }}

Expand Down
7 changes: 5 additions & 2 deletions internal/configs/version2/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ var virtualServerCfg = VirtualServerConfig{
MaxConns: 31,
},
},
LBMethod: "random",
Keepalive: 32,
LBMethod: "random",
Keepalive: 32,
UpstreamZoneSize: "256k",
},
{
Name: "coffee-v1",
Expand All @@ -29,6 +30,7 @@ var virtualServerCfg = VirtualServerConfig{
FailTimeout: "10s",
},
},
UpstreamZoneSize: "256k",
},
{
Name: "coffee-v2",
Expand All @@ -39,6 +41,7 @@ var virtualServerCfg = VirtualServerConfig{
FailTimeout: "10s",
},
},
UpstreamZoneSize: "256k",
},
},
SplitClients: []SplitClient{
Expand Down
9 changes: 5 additions & 4 deletions internal/configs/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
16 changes: 9 additions & 7 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down