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
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}} {{$upstream.UpstreamZoneSize}};
{{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 }} {{ $u.UpstreamZoneSize }};

{{ 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