8000 Add passive health checks to transportServer · nginx/kubernetes-ingress@ef1985f · GitHub
[go: up one dir, main page]

Skip to content

Commit ef1985f

Browse files
committed
Add passive health checks to transportServer
1 parent af045fe commit ef1985f

File tree

13 files changed

+81
-26
lines changed

13 files changed

+81
-26
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ spec:
7777
description: Upstream defines an upstream.
7878
type: object
7979
properties:
80+
failTimeout:
81+
type: string
82+
maxFails:
83+
type: integer
8084
name:
8185
type: string
8286
port:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ spec:
7878
description: Upstream defines an upstream.
7979
type: object
8080
properties:
81+
failTimeout:
82+
type: string
83+
maxFails:
84+
type: integer
8185
name:
8286
type: string
8387
port:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ spec:
7777
description: Upstream defines an upstream.
7878
type: object
7979
properties:
80+
failTimeout:
81+
type: string
82+
maxFails:
83+
type: integer
8084
name:
8185
type: string
8286
port:

deployments/helm-chart/values.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,17 @@ controller:
154154

155155
globalConfiguration:
156156
## Creates the GlobalConfiguration custom resource. Requires controller.enableCustomResources.
157-
create: false
157+
create: true
158158

159159
## The spec of the GlobalConfiguration for defining the global configuration parameters of the Ingress Controller.
160-
spec: {}
161-
# listeners:
162-
# - name: dns-udp
163-
# port: 5353
164-
# protocol: UDP
165-
# - name: dns-tcp
166-
# port: 5353
167-
# protocol: TCP
160+
spec:
161+
listeners:
162+
- name: dns-udp
163+
port: 5353
164+
protocol: UDP
165+
- name: dns-tcp
166+
port: 5353
167+
protocol: TCP
168168

169169
## Enable custom NGINX configuration snippets in VirtualServer and VirtualServerRoute resources.
170170
enableSnippets: false

docs-web/configuration/transportserver-resource.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ The upstream defines a destination for the TransportServer. For example:
157157
name: secure-app
158158
service: secure-app
159159
port: 8443
160+
maxFails: 3
161+
failTimeout: 30s
160162
```
161163

162164
```eval_rst
@@ -179,6 +181,15 @@ port: 8443
179181
- The port of the service. If the service doesn't define that port, NGINX will assume the service has zero endpoints and close client connections/ignore datagrams. The port must fall into the range ``1..65535``.
180182
- ``int``
181183
- Yes
184+
* - ``maxFails``
185+
- Sets the number 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``.
186+
- ``int``
187+
- No
188+
* - ``failTimeout``
189+
- Sets the time 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``.
190+
- ``string``
191+
- No
192+
182193
```
183194

184195
### UpstreamParameters

internal/configs/transportserver.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ func generateStreamUpstreams(transportServerEx *TransportServerEx, upstreamNamer
103103
endpointsKey := GenerateEndpointsKey(transportServerEx.TransportServer.Namespace, u.Service, nil, uint16(u.Port))
104104
endpoints := transportServerEx.Endpoints[endpointsKey]
105105

106-
ups := generateStreamUpstream(name, endpoints, isPlus)
106+
maxFails := generateIntFromPointer(u.MaxFails, 1)
107+
failTimeout := generateString(u.FailTimeout, "10s")
108+
109+
ups := generateStreamUpstream(name, maxFails, failTimeout, endpoints, isPlus)
107110

108111
ups.UpstreamLabels.Service = u.Service
109112
ups.UpstreamLabels.ResourceType = "transportserver"
@@ -116,20 +119,24 @@ func generateStreamUpstreams(transportServerEx *TransportServerEx, upstreamNamer
116119
return upstreams
117120
}
118121

119-
func generateStreamUpstream(upstreamName string, endpoints []string, isPlus bool) version2.StreamUpstream {
122+
func generateStreamUpstream(upstreamName string, maxFails int, failTimeout string, endpoints []string, isPlus bool) version2.StreamUpstream {
120123
var upsServers []version2.StreamUpstreamServer
121124

122125
for _, e := range endpoints {
123126
s := version2.StreamUpstreamServer{
124-
Address: e,
127+
Address: e,
128+
MaxFails: maxFails,
129+
FailTimeout: failTimeout,
125130
}
126131

127132
upsServers = append(upsServers, s)
128133
}
129134

130135
if !isPlus && len(endpoints) == 0 {
131136
upsServers = append(upsServers, version2.StreamUpstreamServer{
132-
Address: nginxNonExistingUnixSocket,
137+
Address: nginxNonExistingUnixSocket,
138+
MaxFails: maxFails,
139+
FailTimeout: failTimeout,
133140
})
134141
}
135142

internal/configs/transportserver_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ func TestGenerateTransportServerConfigForTCP(t *testing.T) {
7575
},
7676
Upstreams: []conf_v1alpha1.Upstream{
7777
{
78-
Name: "tcp-app",
79-
Service: "tcp-app-svc",
80-
Port: 5001,
78+
Name: "tcp-app",
79+
Service: "tcp-app-svc",
80+
Port: 5001,
81+
MaxFails: intPointer(3),
82+
FailTimeout: "40s",
8183
},
8284
},
8385
UpstreamParameters: &conf_v1alpha1.UpstreamParameters{
@@ -107,7 +109,9 @@ func TestGenerateTransportServerConfigForTCP(t *testing.T) {
107109
Name: "ts_default_tcp-server_tcp-app",
108110
Servers: []version2.StreamUpstreamServer{
109111
{
110-
Address: "10.0.0.20:5001",
112+
Address: "10.0.0.20:5001",
113+
MaxFails: 3,
114+
FailTimeout: "40s",
111115
},
112116
},
113117
UpstreamLabels: version2.UpstreamLabels{
@@ -186,7 +190,9 @@ func TestGenerateTransportServerConfigForTLSPasstrhough(t *testing.T) {
186190
Name: "ts_default_tcp-server_tcp-app",
187191
Servers: []version2.StreamUpstreamServer{
188192
{
189-
Address: "10.0.0.20:5001",
193+
Address: "10.0.0.20:5001",
194+
MaxFails: 1,
195+
FailTimeout: "10s",
190196
},
191197
},
192198
UpstreamLabels: version2.UpstreamLabels{
@@ -271,7 +277,9 @@ func TestGenerateTransportServerConfigForUDP(t *testing.T) {
271277
Name: "ts_default_udp-server_udp-app",
272278
Servers: []version2.StreamUpstreamServer{
273279
{
274-
Address: "10.0.0.20:5001",
280+
Address: "10.0.0.20:5001",
281+
MaxFails: 1,
282+
FailTimeout: "10s",
275283
},
276284
},
277285
UpstreamLabels: version2.UpstreamLabels{
@@ -336,3 +344,7 @@ func TestGenerateUnixSocket(t *testing.T) {
336344
t.Errorf("generateUnixSocket() returned %q but expected %q", result, expected)
337345
}
338346
}
347+
348+
func intPointer(value int) *int {
349+
return &value
350+
}

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 }};
8+
server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }};
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 }};
8+
server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }};
99
{{ end }}
1010
}
1111
{{ end }}

internal/configs/version2/stream.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ type StreamUpstream struct {
1515

1616
// StreamUpstreamServer defines a stream upstream server.
1717
type StreamUpstreamServer struct {
18-
Address string
18+
Address string
19+
MaxFails int
20+
FailTimeout string
1921
}
2022

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

0 commit comments

Comments
 (0)
0