E583 Add max connections config to TransportServer · nginx/kubernetes-ingress@36fabaf · GitHub
[go: up one dir, main page]

Skip to content

Commit 36fabaf

Browse files
committed
Add max connections config to TransportServer
1 parent 88d6b7c commit 36fabaf

File tree

16 files changed

+248
-28
lines changed

16 files changed

+248
-28
lines changed

deployments/common/crds/k8s.nginx.org_transportservers.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ spec:
115115
type: integer
116116
timeout:
117117
type: string
118+
maxConns:
119+
type: integer
118120
maxFails:
119121
type: integer
120122
name:

deployments/helm-chart/crds/k8s.nginx.org_transportservers.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ spec:
115115
type: integer
116116
timeout:
117117
type: string
118+
maxConns:
119+
type: integer
118120
maxFails:
119121
type: integer
120122
name:

docs-web/configuration/transportserver-resource.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ name: secure-app
172172
service: secure-app
173173
port: 8443
174174
maxFails: 3
175+
maxConns: 100
175176
failTimeout: 30s
176177
```
177178

@@ -199,6 +200,10 @@ failTimeout: 30s
199200
- Sets the `number <https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#max_fails>`_ of unsuccessful attempts to communicate with the server that should happen in the duration set by the failTimeout parameter to consider the server unavailable. The default ``1``.
200201
- ``int``
201202
- No
203+
* - ``maxConns``
204+
- Sets the `number <https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#max_conns>`_ of maximum connections to the proxied server. Default value is zero, meaning there is no limit. The default is ``0``.
205+
- ``int``
206+
- No
202207
* - ``failTimeout``
203208
- Sets the `time <https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#fail_timeout>`_ during which the specified number of unsuccessful attempts to communicate with the server should happen to consider the server unavailable and the period of time the server will be considered unavailable. The default is ``10s``.
204209
- ``string``

internal/configs/transportserver.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,15 @@ func generateStreamUpstream(upstream *conf_v1alpha1.Upstream, upstreamNamer *ups
172172

173173
name := upstreamNamer.GetNameForUpstream(upstream.Name)
174174
maxFails := generateIntFromPointer(upstream.MaxFails, 1)
175+
maxConns := generateIntFromPointer(upstream.MaxConns, 0)
175176
failTimeout := generateTimeWithDefault(upstream.FailTimeout, "10s")
176177

177178
for _, e := range endpoints {
178179
s := version2.StreamUpstreamServer{
179-
Address: e,
180-
MaxFails: maxFails,
181-
FailTimeout: failTimeout,
180+
Address: e,
181+
MaxFails: maxFails,
182+
FailTimeout: failTimeout,
183+
MaxConnections: maxConns,
182184
}
183185

184186
upsServers = append(upsServers, s)

internal/configs/transportserver_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,94 @@ func TestGenerateTransportServerConfigForTCP(t *testing.T) {
225225

226226
}
227227

228+
func TestGenerateTransportServerConfigForTCPMaxConnections(t *testing.T) {
229+
transportServerEx := TransportServerEx{
230+
TransportServer: &conf_v1alpha1.TransportServer{
231+
ObjectMeta: meta_v1.ObjectMeta{
232+
Name: "tcp-server",
233+
Namespace: "default",
234+
},
235+
Spec: conf_v1alpha1.TransportServerSpec{
236+
Listener: conf_v1alpha1.TransportServerListener{
237+
Name: "tcp-listener",
238+
Protocol: "TCP",
239+
},
240+
Upstreams: []conf_v1alpha1.Upstream{
241+
{
242+
Name: "tcp-app",
243+
Service: "tcp-app-svc",
244+
Port: 5001,
245+
MaxFails: intPointer(3),
246+
MaxConns: intPointer(3),
247+
FailTimeout: "40s",
248+
},
249+
},
250+
UpstreamParameters: &conf_v1alpha1.UpstreamParameters{
251+
ConnectTimeout: "30s",
252+
NextUpstream: false,
253+
},
254+
SessionParameters: &conf_v1alpha1.SessionParameters{
255+
Timeout: "50s",
256+
},
257+
Action: &conf_v1alpha1.Action{
258+
Pass: "tcp-app",
259+
},
260+
},
261+
},
262+
Endpoints: map[string][]string{
263+
"default/tcp-app-svc:5001": {
264+
"10.0.0.20:5001",
265+
},
266+
},
267+
}
268+
269+
listenerPort := 2020
270+
271+
expected := &version2.TransportServerConfig{
272+
Upstreams: []version2.StreamUpstream{
273+
{
274+
Name: "ts_default_tcp-server_tcp-app",
275+
Servers: []version2.StreamUpstreamServer{
276+
{
277+
Address: "10.0.0.20:5001",
278+
MaxFails: 3,
279+
FailTimeout: "40s",
280+
MaxConnections: 3,
281+
},
282+
},
283+
UpstreamLabels: version2.UpstreamLabels{
284+
ResourceName: "tcp-server",
285+
ResourceType: "transportserver",
286+
ResourceNamespace: "default",
287+
Service: "tcp-app-svc",
288+
},
289+
},
290+
},
291+
Server: version2.StreamServer{
292+
Port: 2020,
293+
UDP: false,
294+
StatusZone: "tcp-listener",
295+
ProxyPass: "ts_default_tcp-server_tcp-app",
296+
Name: "tcp-server",
297+
Namespace: "default",
298+
ProxyConnectTimeout: "30s",
299+
ProxyNextUpstream: false,
300+
ProxyNextUpstreamTries: 0,
301+
ProxyNextUpstreamTimeout: "0s",
302+
ProxyTimeout: "50s",
303+
HealthCheck: nil,
304+
ServerSnippets: []string{},
305+
},
306+
StreamSnippets: []string{},
307+
}
308+
309+
result := generateTransportServerConfig(&transportServerEx, listenerPort, true)
310+
if diff := cmp.Diff(expected, result); diff != "" {
311+
t.Errorf("generateTransportServerConfig() mismatch (-want +got):\n%s", diff)
312+
}
313+
314+
}
315+
228316
func TestGenerateTransportServerConfigForTLSPasstrhough(t *testing.T) {
229317
transportServerEx := TransportServerEx{
230318
TransportServer: &conf_v1alpha1.TransportServer{

internal/configs/version2/nginx-plus.transportserver.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ upstream {{ $u.Name }} {
55
random two least_conn;
66

77
{{ range $s := $u.Servers }}
8-
server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }};
8+
server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }} max_conns={{ $s.MaxConnections }};
99
{{ end }}
1010
}
1111
{{ end }}

internal/configs/version2/nginx.transportserver.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ upstream {{ $u.Name }} {
55
random two least_conn;
66

77
{{ range $s := $u.Servers }}
8-
server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }};
8+
server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }} max_conns={{ $s.MaxConnections }};
99
{{ end }}
1010
}
1111
{{ end }}

internal/configs/version2/stream.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ type StreamUpstream struct {
1616

1717
// StreamUpstreamServer defines a stream upstream server.
1818
type StreamUpstreamServer struct {
19-
Address string
20-
MaxFails int
21-
FailTimeout string
19+
Address string
20+
MaxFails int
21+
FailTimeout string
22+
MaxConnections int
2223
}
2324

2425
// StreamServer defines a server in the stream module.

pkg/apis/configuration/v1alpha1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type Upstream struct {
9090
Port int `json:"port"`
9191
FailTimeout string `json:"failTimeout"`
9292
MaxFails *int `json:"maxFails"`
93+
MaxConns *int `json:"maxConns"`
9394
HealthCheck *HealthCheck `json:"healthCheck"`
9495
}
9596

pkg/apis/configuration/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0