diff --git a/docs/configmap-and-annotations.md b/docs/configmap-and-annotations.md index a97113ba07..1fb79f1ea5 100644 --- a/docs/configmap-and-annotations.md +++ b/docs/configmap-and-annotations.md @@ -164,6 +164,7 @@ spec: | `nginx.org/grpc-services` | N/A | Enables gRPC for services. Note: requires HTTP/2 (see `http2` ConfigMap key); only works for Ingresses with TLS termination enabled. | N/A | [GRPC Services Support](../examples/grpc-services).| | `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/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/annotations.go b/internal/configs/annotations.go index eb70529f56..b30ee34fbc 100644 --- a/internal/configs/annotations.go +++ b/internal/configs/annotations.go @@ -48,6 +48,7 @@ var minionInheritanceList = map[string]bool{ "nginx.org/lb-method": true, "nginx.org/keepalive": true, "nginx.org/max-fails": true, + "nginx.org/max-conns": true, "nginx.org/fail-timeout": true, } @@ -285,6 +286,14 @@ func parseAnnotations(ingEx *IngressEx, baseCfgParams *ConfigParams, isPlus bool } } + if maxConns, exists, err := GetMapKeyAsInt(ingEx.Ingress.Annotations, "nginx.org/max-conns", ingEx.Ingress); exists { + if err != nil { + glog.Error(err) + } else { + cfgParams.MaxConns = maxConns + } + } + if failTimeout, exists := ingEx.Ingress.Annotations["nginx.org/fail-timeout"]; exists { cfgParams.FailTimeout = failTimeout } diff --git a/internal/configs/config_params.go b/internal/configs/config_params.go index fa3fda4198..0c57f0bdf2 100644 --- a/internal/configs/config_params.go +++ b/internal/configs/config_params.go @@ -40,6 +40,7 @@ type ConfigParams struct { MainWorkerRlimitNofile string Keepalive int64 MaxFails int + MaxConns int FailTimeout string HealthCheckEnabled bool HealthCheckMandatory bool @@ -101,6 +102,7 @@ func NewDefaultConfigParams() *ConfigParams { Ports: []int{80}, SSLPorts: []int{443}, MaxFails: 1, + MaxConns: 0, FailTimeout: "10s", LBMethod: "random two least_conn", MainErrorLogLevel: "notice", diff --git a/internal/configs/ingress.go b/internal/configs/ingress.go index a87ad5b2fd..736a395132 100644 --- a/internal/configs/ingress.go +++ b/internal/configs/ingress.go @@ -289,6 +289,7 @@ func createUpstream(ingEx *IngressEx, name string, backend *extensions.IngressBa Address: addressport[0], Port: addressport[1], MaxFails: cfg.MaxFails, + MaxConns: cfg.MaxConns, FailTimeout: cfg.FailTimeout, SlowStart: cfg.SlowStart, Resolve: isExternalNameSvc, diff --git a/internal/configs/version1/config.go b/internal/configs/version1/config.go index 0d245f3eb5..23e02f62c3 100644 --- a/internal/configs/version1/config.go +++ b/internal/configs/version1/config.go @@ -30,6 +30,7 @@ type UpstreamServer struct { Address string Port string MaxFails int + MaxConns int FailTimeout string SlowStart string Resolve bool @@ -168,6 +169,7 @@ func NewUpstreamWithDefaultServer(name string) Upstream { Address: "127.0.0.1", Port: "8181", MaxFails: 1, + MaxConns: 0, FailTimeout: "10s", }, }, diff --git a/internal/configs/version1/nginx.ingress.tmpl b/internal/configs/version1/nginx.ingress.tmpl index 6a6aec19ec..f84d689704 100644 --- a/internal/configs/version1/nginx.ingress.tmpl +++ b/internal/configs/version1/nginx.ingress.tmpl @@ -3,7 +3,7 @@ upstream {{$upstream.Name}} { {{if $upstream.LBMethod }}{{$upstream.LBMethod}};{{end}} {{range $server := $upstream.UpstreamServers}} - server {{$server.Address}}:{{$server.Port}} max_fails={{$server.MaxFails}} fail_timeout={{$server.FailTimeout}};{{end}} + server {{$server.Address}}:{{$server.Port}} max_fails={{$server.MaxFails}} fail_timeout={{$server.FailTimeout}} max_conns={{$server.MaxConns}};{{end}} {{if $.Keepalive}}keepalive {{$.Keepalive}};{{end}} }{{end}} diff --git a/internal/configs/version1/templates_test.go b/internal/configs/version1/templates_test.go index d13b71dafe..e0b40dbe48 100644 --- a/internal/configs/version1/templates_test.go +++ b/internal/configs/version1/templates_test.go @@ -18,6 +18,7 @@ var testUps = Upstream{ Address: "127.0.0.1", Port: "8181", MaxFails: 0, + MaxConns: 0, FailTimeout: "1s", SlowStart: "5s", },