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

Add Active Connections support to vs/vsr #634

Merged
merged 2 commits into from
Jul 26, 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
38 changes: 20 additions & 18 deletions docs/virtualserver-and-virtualserverroute.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Upstream struct {
type UpstreamServer struct {
Address string
MaxFails int
MaxConns int
FailTimeout string
}

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
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version2/nginx.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version2/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var virtualServerCfg = VirtualServerConfig{
Address: "10.0.0.20:8001",
MaxFails: 5,
FailTimeout: "10s",
MaxConns: 31,
},
},
LBMethod: "random",
Expand Down
2 changes: 2 additions & 0 deletions internal/configs/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
34 changes: 18 additions & 16 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -771,6 +771,7 @@ func TestGenerateUpstream(t *testing.T) {
cfgParams := ConfigParams{
LBMethod: "random",
MaxFails: 1,
MaxConns: 0,
FailTimeout: "10s",
Keepalive: 21,
}
Expand All @@ -781,6 +782,7 @@ func TestGenerateUpstream(t *testing.T) {
{
Address: "192.168.10.10:8080",
MaxFails: 1,
MaxConns: 0,
FailTimeout: "10s",
},
},
Expand Down Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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",
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/configuration/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/configuration/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/configuration/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading