From b3d15c61a271c18c5526d8907347a8d3ed731e86 Mon Sep 17 00:00:00 2001 From: Dean Coakley Date: Thu, 11 Jul 2019 12:35:22 +0100 Subject: [PATCH 1/2] Add active connections support for vs/vsr --- docs/virtualserver-and-virtualserverroute.md | 38 +++--- internal/configs/version2/config.go | 1 + .../version2/nginx-plus.virtualserver.tmpl | 2 +- .../configs/version2/nginx.virtualserver.tmpl | 2 +- internal/configs/version2/templates_test.go | 1 + internal/configs/virtualserver.go | 2 + internal/configs/virtualserver_test.go | 34 ++--- pkg/apis/configuration/v1alpha1/types.go | 1 + .../v1alpha1/zz_generated.deepcopy.go | 5 + .../configuration/validation/validation.go | 1 + .../validation/validation_test.go | 118 ++++++++++-------- 11 files changed, 118 insertions(+), 87 deletions(-) diff --git a/docs/virtualserver-and-virtualserverroute.md b/docs/virtualserver-and-virtualserverroute.md index 732ecc1643..e6b9dc6d94 100644 --- a/docs/virtualserver-and-virtualserverroute.md +++ b/docs/virtualserver-and-virtualserverroute.md @@ -7,24 +7,24 @@ This document is the reference documentation for the resources. To see additiona **Feature Status**: The VirtualServer and VirtualServerRoute resources are available as a preview feature: it is suitable for experimenting and testing; however, it must be used with caution in production environments. Additionally, while the feature is in preview, we might introduce some backward-incompatible changes to the resources specification in the next releases. ## Contents -- [VirtualServer and VirtualServerRoute Resources](#VirtualServer-and-VirtualServerRoute-Resources) - - [Contents](#Contents) - - [Prerequisites](#Prerequisites) - - [VirtualServer Specification](#VirtualServer-Specification) - - [VirtualServer.TLS](#VirtualServerTLS) - - [VirtualServer.Route](#VirtualServerRoute) - - [VirtualServerRoute Specification](#VirtualServerRoute-Specification) - - [VirtualServerRoute.Subroute](#VirtualServerRouteSubroute) - - [Common Parts of the VirtualServer and VirtualServerRoute](#Common-Parts-of-the-VirtualServer-and-VirtualServerRoute) - - [Upstream](#Upstream) - - [Upstream.TLS](#UpstreamTLS) - - [Split](#Split) - - [Rules](#Rules) - - [Condition](#Condition) - - [Match](#Match) - - [Using VirtualServer and VirtualServerRoute](#Using-VirtualServer-and-VirtualServerRoute) - - [Validation](#Validation) - - [Customization via ConfigMap](#Customization-via-ConfigMap) +- [VirtualServer and VirtualServerRoute Resources](#virtualserver-and-virtualserverroute-resources) + - [Contents](#contents) + - [Prerequisites](#prerequisites) + - [VirtualServer Specification](#virtualserver-specification) + - [VirtualServer.TLS](#virtualservertls) + - [VirtualServer.Route](#virtualserverroute) + - [VirtualServerRoute Specification](#virtualserverroute-specification) + - [VirtualServerRoute.Subroute](#virtualserverroutesubroute) + - [Common Parts of the VirtualServer and VirtualServerRoute](#common-parts-of-the-virtualserver-and-virtualserverroute) + - [Upstream](#upstream) + - [Upstream.TLS](#upstreamtls) + - [Split](#split) + - [Rules](#rules) + - [Condition](#condition) + - [Match](#match) + - [Using VirtualServer and VirtualServerRoute](#using-virtualserver-and-virtualserverroute) + - [Validation](#validation) + - [Customization via ConfigMap](#customization-via-configmap) ## Prerequisites @@ -180,6 +180,7 @@ port: 80 lb-method: round_robin fail-timeout: 10s max-fails: 1 +max-conns: 32 keepalive: 32 connect-timeout: 30s read-timeout: 30s @@ -199,6 +200,7 @@ tls: | `lb-method` | The load [balancing method](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-balancer/#choosing-a-load-balancing-method). To use the round-robin method, specify `round_robin`. The default is specified in the `lb-method` ConfigMap key. | `string` | No | | `fail-timeout` | The time during which the specified number of unsuccessful attempts to communicate with an upstream server should happen to consider the server unavailable. See the [fail_timeout](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#fail_timeout) parameter of the server directive. The default is set in the `fail-timeout` ConfigMap key. | `string` | No | | `max-fails` | The number of unsuccessful attempts to communicate with an upstream server that should happen in the duration set by the `fail-timeout` to consider the server unavailable. See the [max_fails](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_fails) parameter of the server directive. The default is set in the `max-fails` ConfgMap key. | `int` | No | +| `max-conns` | The maximum number of simultaneous active connections to an upstream server. See the [max_conns](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_conns) parameter of the server directive. By default there is no limit. Note: if keepalive connections are enabled, the total number of active and idle keepalive connections to an upstream server may exceed the `max_conns` value. | `int` | No | | `keepalive` | Configures the cache for connections to upstream servers. The value `0` disables the cache. See the [keepalive](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive) directive. The default is set in the `keepalive` ConfigMap key. | `int` | No | | `connect-timeout` | The timeout for establishing a connection with an upstream server. See the [proxy_connect_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout) directive. The default is specified in the `proxy-connect-timeout` ConfigMap key. | `string` | No | | `read-timeout` | The timeout for reading a response from an upstream server. See the [proxy_read_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout) directive. The default is specified in the `proxy-read-timeout` ConfigMap key. | `string` | No | diff --git a/internal/configs/version2/config.go b/internal/configs/version2/config.go index ad4c7aebb1..757d565e09 100644 --- a/internal/configs/version2/config.go +++ b/internal/configs/version2/config.go @@ -20,6 +20,7 @@ type Upstream struct { type UpstreamServer struct { Address string MaxFails int + MaxConns int FailTimeout string } diff --git a/internal/configs/version2/nginx-plus.virtualserver.tmpl b/internal/configs/version2/nginx-plus.virtualserver.tmpl index fcff628645..393785df63 100644 --- a/internal/configs/version2/nginx-plus.virtualserver.tmpl +++ b/internal/configs/version2/nginx-plus.virtualserver.tmpl @@ -5,7 +5,7 @@ upstream {{ $u.Name }} { {{ if $u.LBMethod }}{{ $u.LBMethod }};{{ end }} {{ range $s := $u.Servers }} - server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }}; + server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }} max_conns={{ $s.MaxConns }}; {{ end }} {{ if $u.Keepalive }} diff --git a/internal/configs/version2/nginx.virtualserver.tmpl b/internal/configs/version2/nginx.virtualserver.tmpl index fcff628645..393785df63 100644 --- a/internal/configs/version2/nginx.virtualserver.tmpl +++ b/internal/configs/version2/nginx.virtualserver.tmpl @@ -5,7 +5,7 @@ upstream {{ $u.Name }} { {{ if $u.LBMethod }}{{ $u.LBMethod }};{{ end }} {{ range $s := $u.Servers }} - server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }}; + server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }} max_conns={{ $s.MaxConns }}; {{ end }} {{ if $u.Keepalive }} diff --git a/internal/configs/version2/templates_test.go b/internal/configs/version2/templates_test.go index 87eb9c230f..be1619d8fd 100644 --- a/internal/configs/version2/templates_test.go +++ b/internal/configs/version2/templates_test.go @@ -14,6 +14,7 @@ var virtualServerCfg = VirtualServerConfig{ Address: "10.0.0.20:8001", MaxFails: 5, FailTimeout: "10s", + MaxConns: 31, }, }, LBMethod: "random", diff --git a/internal/configs/virtualserver.go b/internal/configs/virtualserver.go index 298bb7f3ab..885e6e1779 100644 --- a/internal/configs/virtualserver.go +++ b/internal/configs/virtualserver.go @@ -206,6 +206,7 @@ func generateUpstream(upstreamName string, upstream conf_v1alpha1.Upstream, endp Address: e, MaxFails: generateIntFromPointer(upstream.MaxFails, cfgParams.MaxFails), FailTimeout: generateString(upstream.FailTimeout, cfgParams.FailTimeout), + MaxConns: generateIntFromPointer(upstream.MaxConns, cfgParams.MaxConns), } upsServers = append(upsServers, s) } @@ -215,6 +216,7 @@ func generateUpstream(upstreamName string, upstream conf_v1alpha1.Upstream, endp Address: nginx502Server, MaxFails: generateIntFromPointer(upstream.MaxFails, cfgParams.MaxFails), FailTimeout: generateString(upstream.FailTimeout, cfgParams.FailTimeout), + MaxConns: generateIntFromPointer(upstream.MaxConns, cfgParams.MaxConns), } upsServers = append(upsServers, s) } diff --git a/internal/configs/virtualserver_test.go b/internal/configs/virtualserver_test.go index 93c7dc3395..cbf18df8c7 100644 --- a/internal/configs/virtualserver_test.go +++ b/internal/configs/virtualserver_test.go @@ -187,10 +187,10 @@ func TestGenerateVirtualServerConfig(t *testing.T) { }, }, Endpoints: map[string][]string{ - "default/tea-svc:80": []string{ + "default/tea-svc:80": { "10.0.0.20:80", }, - "default/coffee-svc:80": []string{ + "default/coffee-svc:80": { "10.0.0.30:80", }, }, @@ -332,16 +332,16 @@ func TestGenerateVirtualServerConfigForVirtualServerWithSplits(t *testing.T) { }, }, Endpoints: map[string][]string{ - "default/tea-svc-v1:80": []string{ + "default/tea-svc-v1:80": { "10.0.0.20:80", }, - "default/tea-svc-v2:80": []string{ + "default/tea-svc-v2:80": { "10.0.0.21:80", }, - "default/coffee-svc-v1:80": []string{ + "default/coffee-svc-v1:80": { "10.0.0.30:80", }, - "default/coffee-svc-v2:80": []string{ + "default/coffee-svc-v2:80": { "10.0.0.31:80", }, }, @@ -554,16 +554,16 @@ func TestGenerateVirtualServerConfigForVirtualServerWithRules(t *testing.T) { }, }, Endpoints: map[string][]string{ - "default/tea-svc-v1:80": []string{ + "default/tea-svc-v1:80": { "10.0.0.20:80", }, - "default/tea-svc-v2:80": []string{ + "default/tea-svc-v2:80": { "10.0.0.21:80", }, - "default/coffee-svc-v1:80": []string{ + "default/coffee-svc-v1:80": { "10.0.0.30:80", }, - "default/coffee-svc-v2:80": []string{ + "default/coffee-svc-v2:80": { "10.0.0.31:80", }, }, @@ -771,6 +771,7 @@ func TestGenerateUpstream(t *testing.T) { cfgParams := ConfigParams{ LBMethod: "random", MaxFails: 1, + MaxConns: 0, FailTimeout: "10s", Keepalive: 21, } @@ -781,6 +782,7 @@ func TestGenerateUpstream(t *testing.T) { { Address: "192.168.10.10:8080", MaxFails: 1, + MaxConns: 0, FailTimeout: "10s", }, }, @@ -1102,11 +1104,11 @@ func TestCreateUpstreamServersForPlus(t *testing.T) { }, }, Endpoints: map[string][]string{ - "default/tea-svc:80": []string{ + "default/tea-svc:80": { "10.0.0.20:80", }, - "default/test-svc:80": []string{}, - "default/coffee-svc:80": []string{ + "default/test-svc:80": {}, + "default/coffee-svc:80": { "10.0.0.30:80", }, }, @@ -1137,11 +1139,11 @@ func TestCreateUpstreamServersForPlus(t *testing.T) { } expected := map[string][]string{ - "vs_default_cafe_tea": []string{ + "vs_default_cafe_tea": { "10.0.0.20:80", }, - "vs_default_cafe_test": []string{}, - "vs_default_cafe_vsr_default_coffee_coffee": []string{ + "vs_default_cafe_test": {}, + "vs_default_cafe_vsr_default_coffee_coffee": { "10.0.0.30:80", }, } diff --git a/pkg/apis/configuration/v1alpha1/types.go b/pkg/apis/configuration/v1alpha1/types.go index d1237e8c2e..908347a0f6 100644 --- a/pkg/apis/configuration/v1alpha1/types.go +++ b/pkg/apis/configuration/v1alpha1/types.go @@ -31,6 +31,7 @@ type Upstream struct { LBMethod string `json:"lb-method"` FailTimeout string `json:"fail-timeout"` MaxFails *int `json:"max-fails"` + MaxConns *int `json:"max-conns"` Keepalive *int `json:"keepalive"` ProxyConnectTimeout string `json:"connect-timeout"` ProxyReadTimeout string `json:"read-timeout"` diff --git a/pkg/apis/configuration/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/configuration/v1alpha1/zz_generated.deepcopy.go index fbce6db46f..a03bc8e1bf 100644 --- a/pkg/apis/configuration/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/configuration/v1alpha1/zz_generated.deepcopy.go @@ -139,6 +139,11 @@ func (in *Upstream) DeepCopyInto(out *Upstream) { *out = new(int) **out = **in } + if in.MaxConns != nil { + in, out := &in.MaxConns, &out.MaxConns + *out = new(int) + **out = **in + } if in.Keepalive != nil { in, out := &in.Keepalive, &out.Keepalive *out = new(int) diff --git a/pkg/apis/configuration/validation/validation.go b/pkg/apis/configuration/validation/validation.go index 47cb7bfeb2..eb2d2a8fca 100644 --- a/pkg/apis/configuration/validation/validation.go +++ b/pkg/apis/configuration/validation/validation.go @@ -149,6 +149,7 @@ func validateUpstreams(upstreams []v1alpha1.Upstream, fieldPath *field.Path, isP allErrs = append(allErrs, validateUpstreamLBMethod(u.LBMethod, idxPath.Child("lb-method"), isPlus)...) allErrs = append(allErrs, validateTime(u.FailTimeout, idxPath.Child("fail-timeout"))...) allErrs = append(allErrs, validatePositiveIntOrZero(u.MaxFails, idxPath.Child("max-fails"))...) + allErrs = append(allErrs, validatePositiveIntOrZero(u.MaxConns, idxPath.Child("max-conns"))...) allErrs = append(allErrs, validatePositiveIntOrZero(u.Keepalive, idxPath.Child("keepalive"))...) for _, msg := range validation.IsValidPortNum(int(u.Port)) { diff --git a/pkg/apis/configuration/validation/validation_test.go b/pkg/apis/configuration/validation/validation_test.go index 626e20100b..d50cc683a4 100644 --- a/pkg/apis/configuration/validation/validation_test.go +++ b/pkg/apis/configuration/validation/validation_test.go @@ -10,7 +10,6 @@ import ( ) func TestValidateVirtualServer(t *testing.T) { - var keepalive = 32 virtualServer := v1alpha1.VirtualServer{ ObjectMeta: meta_v1.ObjectMeta{ Name: "cafe", @@ -27,7 +26,9 @@ func TestValidateVirtualServer(t *testing.T) { Service: "service-1", LBMethod: "random", Port: 80, - Keepalive: &keepalive, + MaxFails: createPointerFromInt(8), + MaxConns: createPointerFromInt(16), + Keepalive: createPointerFromInt(32), }, { Name: "second", @@ -139,6 +140,7 @@ func TestValidateUpstreams(t *testing.T) { ProxyNextUpstream: "error timeout", ProxyNextUpstreamTimeout: "10s", ProxyNextUpstreamTries: 5, + MaxConns: createPointerFromInt(16), }, { Name: "upstream2", @@ -150,8 +152,8 @@ func TestValidateUpstreams(t *testing.T) { }, }, expectedUpstreamNames: map[string]sets.Empty{ - "upstream1": sets.Empty{}, - "upstream2": sets.Empty{}, + "upstream1": {}, + "upstream2": {}, }, msg: "2 valid upstreams", }, @@ -200,7 +202,7 @@ func TestValidateUpstreamsFails(t *testing.T) { }, }, expectedUpstreamNames: map[string]sets.Empty{ - "upstream1": sets.Empty{}, + "upstream1": {}, }, msg: "invalid service", }, @@ -216,7 +218,7 @@ func TestValidateUpstreamsFails(t *testing.T) { }, }, expectedUpstreamNames: map[string]sets.Empty{ - "upstream1": sets.Empty{}, + "upstream1": {}, }, msg: "invalid port", }, @@ -240,7 +242,7 @@ func TestValidateUpstreamsFails(t *testing.T) { }, }, expectedUpstreamNames: map[string]sets.Empty{ - "upstream1": sets.Empty{}, + "upstream1": {}, }, msg: "duplicated upstreams", }, @@ -292,6 +294,20 @@ func TestValidateUpstreamsFails(t *testing.T) { }, msg: "invalid upstream tries value", }, + { + upstreams: []v1alpha1.Upstream{ + { + Name: "upstream1", + Service: "test-1", + Port: 80, + MaxConns: createPointerFromInt(-1), + }, + }, + expectedUpstreamNames: map[string]sets.Empty{ + "upstream1": {}, + }, + msg: "negative value for MaxConns", + }, } isPlus := false @@ -390,7 +406,7 @@ func TestValidateVirtualServerRoutes(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, }, msg: "valid route", }, @@ -422,8 +438,8 @@ func TestValidateVirtualServerRoutesFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, msg: "duplicated paths", }, @@ -462,7 +478,7 @@ func TestValidateRoute(t *testing.T) { Upstream: "test", }, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, }, isRouteFieldForbidden: false, msg: "valid route with upstream", @@ -482,8 +498,8 @@ func TestValidateRoute(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, isRouteFieldForbidden: false, msg: "valid upstream with splits", @@ -509,8 +525,8 @@ func TestValidateRoute(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, isRouteFieldForbidden: false, msg: "valid upstream with rules", @@ -548,7 +564,7 @@ func TestValidateRouteFails(t *testing.T) { Upstream: "test", }, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, }, isRouteFieldForbidden: false, msg: "empty path", @@ -587,9 +603,9 @@ func TestValidateRouteFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test": {}, + "test-1": {}, + "test-2": {}, }, isRouteFieldForbidden: false, msg: "both upstream and splits exist", @@ -616,9 +632,9 @@ func TestValidateRouteFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test": {}, + "test-1": {}, + "test-2": {}, }, isRouteFieldForbidden: false, msg: "both upstream and rules exist", @@ -654,8 +670,8 @@ func TestValidateRouteFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, isRouteFieldForbidden: false, msg: "both splits and rules exist", @@ -709,7 +725,7 @@ func TestValidateRouteField(t *testing.T) { func TestValdateReferencedUpstream(t *testing.T) { upstream := "test" upstreamNames := map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, } allErrs := validateReferencedUpstream(upstream, field.NewPath("upstream"), upstreamNames) @@ -792,8 +808,8 @@ func TestValidateSplits(t *testing.T) { }, } upstreamNames := map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, } allErrs := validateSplits(splits, field.NewPath("splits"), upstreamNames) @@ -816,7 +832,7 @@ func TestValidateSplitsFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, + "test-1": {}, }, msg: "only one split", }, @@ -832,8 +848,8 @@ func TestValidateSplitsFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, msg: "invalid weight", }, @@ -849,8 +865,8 @@ func TestValidateSplitsFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, msg: "invalid total weight", }, @@ -866,8 +882,8 @@ func TestValidateSplitsFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, msg: "invalid upstream", }, @@ -883,8 +899,8 @@ func TestValidateSplitsFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, msg: "non-existing upstream", }, @@ -917,8 +933,8 @@ func TestValidateRules(t *testing.T) { } upstreamNames := map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, } allErrs := validateRules(&rules, field.NewPath("rules"), upstreamNames) @@ -947,8 +963,8 @@ func TestValidateRulesFails(t *testing.T) { DefaultUpstream: "test-2", }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, msg: "no conditions", }, @@ -963,7 +979,7 @@ func TestValidateRulesFails(t *testing.T) { DefaultUpstream: "test-2", }, upstreamNames: map[string]sets.Empty{ - "test-2": sets.Empty{}, + "test-2": {}, }, msg: "no matches", }, @@ -985,7 +1001,7 @@ func TestValidateRulesFails(t *testing.T) { DefaultUpstream: "", }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, + "test-1": {}, }, msg: "no default upstream", }, @@ -1008,8 +1024,8 @@ func TestValidateRulesFails(t *testing.T) { DefaultUpstream: "test", }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test": sets.Empty{}, + "test-1": {}, + "test": {}, }, msg: "invalid values in a match", }, @@ -1203,7 +1219,7 @@ func TestValidateMatch(t *testing.T) { } conditionsCount := 2 upstreamNames := map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, } allErrs := validateMatch(match, field.NewPath("match"), conditionsCount, upstreamNames) @@ -1226,7 +1242,7 @@ func TestValidateMatchFails(t *testing.T) { }, conditionsCount: 1, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, }, msg: "invalid number of values", }, @@ -1239,7 +1255,7 @@ func TestValidateMatchFails(t *testing.T) { }, conditionsCount: 1, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, }, msg: "invalid value", }, @@ -1416,7 +1432,7 @@ func TestValidateVirtualServerRouteSubroutes(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test": sets.Empty{}, + "test": {}, }, pathPrefix: "/", msg: "valid route", @@ -1450,8 +1466,8 @@ func TestValidateVirtualServerRouteSubroutesFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, - "test-2": sets.Empty{}, + "test-1": {}, + "test-2": {}, }, pathPrefix: "/", msg: "duplicated paths", @@ -1475,7 +1491,7 @@ func TestValidateVirtualServerRouteSubroutesFails(t *testing.T) { }, }, upstreamNames: map[string]sets.Empty{ - "test-1": sets.Empty{}, + "test-1": {}, }, pathPrefix: "/abc", msg: "invalid prefix", From 871eb4e8cea5d5ca6ace594a5150dcbbb464dc0d Mon Sep 17 00:00:00 2001 From: Dean Coakley Date: Wed, 24 Jul 2019 18:05:54 +0100 Subject: [PATCH 2/2] Fix VsrUpstreamOptions and VsrConfigmap tests --- tests/suite/test_v_s_route_upstream_options.py | 12 ++++++------ tests/suite/test_virtual_server_configmap_keys.py | 2 +- tests/suite/test_virtual_server_upstream_options.py | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/suite/test_v_s_route_upstream_options.py b/tests/suite/test_v_s_route_upstream_options.py index 71790f937c..5daf8d57b0 100644 --- a/tests/suite/test_v_s_route_upstream_options.py +++ b/tests/suite/test_v_s_route_upstream_options.py @@ -67,7 +67,7 @@ def test_nginx_config_upstreams_defaults(self, kube_apis, ingress_controller_pre assert "proxy_read_timeout 60s;" in config assert "proxy_send_timeout 60s;" in config - assert "max_fails=1 fail_timeout=10s;" in config + assert "max_fails=1 fail_timeout=10s max_conns=0;" in config assert "keepalive" not in config assert 'proxy_set_header Connection "";' not in config @@ -77,7 +77,7 @@ def test_nginx_config_upstreams_defaults(self, kube_apis, ingress_controller_pre "fail-timeout": "13s", "connect-timeout": "55s", "read-timeout": "1s", "send-timeout": "1h", "keepalive": 54}, ["least_conn;", "max_fails=8 ", - "fail_timeout=13s;", "proxy_connect_timeout 55s;", "proxy_read_timeout 1s;", "proxy_send_timeout 1h;", + "fail_timeout=13s ", "max_conns=0;", "proxy_connect_timeout 55s;", "proxy_read_timeout 1s;", "proxy_send_timeout 1h;", "keepalive 54;", 'proxy_set_header Connection "";']), ({"lb-method": "ip_hash", "connect-timeout": "75", "read-timeout": "15", "send-timeout": "1h"}, ["ip_hash;", "proxy_connect_timeout 75;", "proxy_read_timeout 15;", "proxy_send_timeout 1h;"]), @@ -131,11 +131,11 @@ def test_when_option_in_v_s_r_only(self, kube_apis, @pytest.mark.parametrize('config_map_file, expected_strings, unexpected_strings', [ (f"{TEST_DATA}/virtual-server-route-upstream-options/configmap-with-keys.yaml", - ["max_fails=3 ", "fail_timeout=33s;", + ["max_fails=3 ", "fail_timeout=33s ", "max_conns=0;", "proxy_connect_timeout 44s;", "proxy_read_timeout 22s;", "proxy_send_timeout 55s;", "keepalive 1024;", 'proxy_set_header Connection "";'], ["ip_hash;", "least_conn;", "random ", "hash", "least_time ", - "max_fails=1 ", "fail_timeout=10s;", + "max_fails=1 ", "fail_timeout=10s ", "max_conns=1s;", "proxy_connect_timeout 60s;", "proxy_read_timeout 60s;", "proxy_send_timeout 60s;"]), ]) def test_when_option_in_config_map_only(self, kube_apis, @@ -186,10 +186,10 @@ def test_when_option_in_config_map_only(self, kube_apis, "fail-timeout": "1m", "connect-timeout": "1m", "read-timeout": "77s", "send-timeout": "23s", "keepalive": 48}, ["least_conn;", "max_fails=12 ", - "fail_timeout=1m;", "proxy_connect_timeout 1m;", "proxy_read_timeout 77s;", "proxy_send_timeout 23s;", + "fail_timeout=1m ", "max_conns=0;", "proxy_connect_timeout 1m;", "proxy_read_timeout 77s;", "proxy_send_timeout 23s;", "keepalive 48;", 'proxy_set_header Connection "";'], ["ip_hash;", "random ", "hash", "least_time ", "max_fails=1 ", - "fail_timeout=10s;", "proxy_connect_timeout 44s;", "proxy_read_timeout 22s;", "proxy_send_timeout 55s;", + "fail_timeout=10s ", "max_conns=1s;", "proxy_connect_timeout 44s;", "proxy_read_timeout 22s;", "proxy_send_timeout 55s;", "keepalive 1024;"]) ]) def test_v_s_r_overrides_config_map(self, kube_apis, diff --git a/tests/suite/test_virtual_server_configmap_keys.py b/tests/suite/test_virtual_server_configmap_keys.py index a71757c30a..7cfb4893bf 100644 --- a/tests/suite/test_virtual_server_configmap_keys.py +++ b/tests/suite/test_virtual_server_configmap_keys.py @@ -40,7 +40,7 @@ def assert_keys_without_validation(config, expected_values): assert f"real_ip_header {expected_values['real-ip-header']};" in config assert f"{expected_values['location-snippets']}" in config assert f"{expected_values['server-snippets']}" in config - assert f"fail_timeout={expected_values['fail-timeout']};" in config + assert f"fail_timeout={expected_values['fail-timeout']}" in config assert f"proxy_send_timeout {expected_values['proxy-send-timeout']};" in config diff --git a/tests/suite/test_virtual_server_upstream_options.py b/tests/suite/test_virtual_server_upstream_options.py index 4210a5102e..e1f899df97 100644 --- a/tests/suite/test_virtual_server_upstream_options.py +++ b/tests/suite/test_virtual_server_upstream_options.py @@ -71,7 +71,7 @@ def test_nginx_config_defaults(self, kube_apis, ingress_controller_prerequisites assert "proxy_read_timeout 60s;" in config assert "proxy_send_timeout 60s;" in config - assert "max_fails=1 fail_timeout=10s;" in config + assert "max_fails=1 fail_timeout=10s max_conns=0;" in config assert "keepalive" not in config assert 'proxy_set_header Connection "";' not in config @@ -81,7 +81,7 @@ def test_nginx_config_defaults(self, kube_apis, ingress_controller_prerequisites "fail-timeout": "13s", "connect-timeout": "55s", "read-timeout": "1s", "send-timeout": "1h", "keepalive": 54}, ["least_conn;", "max_fails=8 ", - "fail_timeout=13s;", "proxy_connect_timeout 55s;", "proxy_read_timeout 1s;", "proxy_send_timeout 1h;", + "fail_timeout=13s ", "max_conns=0;", "proxy_connect_timeout 55s;", "proxy_read_timeout 1s;", "proxy_send_timeout 1h;", "keepalive 54;", 'proxy_set_header Connection "";']), ({"lb-method": "ip_hash", "connect-timeout": "75", "read-timeout": "15", "send-timeout": "1h"}, ["ip_hash;", "proxy_connect_timeout 75;", "proxy_read_timeout 15;", "proxy_send_timeout 1h;"]), @@ -121,11 +121,11 @@ def test_when_option_in_v_s_only(self, kube_apis, ingress_controller_prerequisit @pytest.mark.parametrize('config_map_file, expected_strings, unexpected_strings', [ (f"{TEST_DATA}/virtual-server-upstream-options/configmap-with-keys.yaml", - ["max_fails=3 ", "fail_timeout=33s;", + ["max_fails=3 ", "fail_timeout=33s ", "max_conns=0;", "proxy_connect_timeout 44s;", "proxy_read_timeout 22s;", "proxy_send_timeout 55s;", "keepalive 1024;", 'proxy_set_header Connection "";'], ["ip_hash;", "least_conn;", "random ", "hash", "least_time ", - "max_fails=1 ", "fail_timeout=10s;", + "max_fails=1 ", "fail_timeout=10s ", "max_conns=1s;", "proxy_connect_timeout 60s;", "proxy_read_timeout 60s;", "proxy_send_timeout 60s;"]), ]) def test_when_option_in_config_map_only(self, kube_apis, ingress_controller_prerequisites, @@ -166,10 +166,10 @@ def test_when_option_in_config_map_only(self, kube_apis, ingress_controller_prer "fail-timeout": "1m", "connect-timeout": "1m", "read-timeout": "77s", "send-timeout": "23s", "keepalive": 48}, ["least_conn;", "max_fails=12 ", - "fail_timeout=1m;", "proxy_connect_timeout 1m;", "proxy_read_timeout 77s;", "proxy_send_timeout 23s;", + "fail_timeout=1m ", "max_conns=0;", "proxy_connect_timeout 1m;", "proxy_read_timeout 77s;", "proxy_send_timeout 23s;", "keepalive 48;", 'proxy_set_header Connection "";'], ["ip_hash;", "random ", "hash", "least_time ", "max_fails=1 ", - "fail_timeout=10s;", "proxy_connect_timeout 44s;", "proxy_read_timeout 22s;", "proxy_send_timeout 55s;", + "fail_timeout=10s ", "max_conns=33s;", "proxy_connect_timeout 44s;", "proxy_read_timeout 22s;", "proxy_send_timeout 55s;", "keepalive 1024;"]) ]) def test_v_s_overrides_config_map(self, kube_apis, ingress_controller_prerequisites,