8000 Fix healthcheck ports · nginx/kubernetes-ingress@ed45743 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed45743

Browse files
committed
Fix healthcheck ports
1 parent 83b5fbc commit ed45743

10 files changed

+13
-22
lines changed

docs/content/configuration/transportserver-resource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Note: This feature is supported only in NGINX Plus.
168168
|``jitter`` | The time within which each health check will be randomly delayed. By default, there is no delay. | ``string`` | No |
169169
|``fails`` | The number of consecutive failed health checks of a particular upstream server after which this server will be considered unhealthy. The default is ``1``. | ``integer`` | No |
170170
|``passes`` | The number of consecutive passed health checks of a particular upstream server after which the server will be considered healthy. The default is ``1``. | ``integer`` | No |
171-
|``port`` | The port used for health check requests. By default, the port of the upstream is used. Note: in contrast with the port of the upstream, this port is not a service port, but a port of a pod. | ``integer`` | No |
171+
|``port`` | The port used for health check requests. By default, the [server port is used](https://nginx.org/en/docs/stream/ngx_stream_upstream_hc_module.html#health_check_port). Note: in contrast with the port of the upstream, this port is not a service port, but a port of a pod. | ``integer`` | No |
172172
|``match`` | Controls the data to send and the response to expect for the healthcheck. | [match](#upstreamhealthcheckmatch) | No |
173173
{{% /table %}}
174174

docs/content/configuration/virtualserver-and-virtualserverroute-resources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ Note: This feature is supported only in NGINX Plus.
367367
|``jitter`` | The time within which each health check will be randomly delayed. By default, there is no delay. | ``string`` | No |
368368
|``fails`` | The number of consecutive failed health checks of a particular upstream server after which this server will be considered unhealthy. The default is ``1``. | ``integer`` | No |
369369
|``passes`` | The number of consecutive passed health checks of a particular upstream server after which the server will be considered healthy. The default is ``1``. | ``integer`` | No |
370-
|``port`` | The port used for health check requests. By default, the port of the upstream is used. Note: in contrast with the port of the upstream, this port is not a service port, but a port of a pod. | ``integer`` | No |
370+
|``port`` | The port used for health check requests. By default, the [server port is used](https://nginx.org/en/docs/http/ngx_http_upstream_hc_module.html#health_check_port). Note: in contrast with the port of the upstream, this port is not a service port, but a port of a pod. | ``integer`` | No |
371371
|``tls`` | The TLS configuration used for health check requests. By default, the ``tls`` field of the upstream is used. | [upstream.tls](#upstreamtls) | No |
372372
|``connect-timeout`` | The timeout for establishing a connection with an upstream server. By default, the ``connect-timeout`` of the upstream is used. | ``string`` | No |
373373
|``read-timeout`` | The timeout for reading a response from an upstream server. By default, the ``read-timeout`` of the upstream is used. | ``string`` | No |

internal/configs/transportserver.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func generateTransportServerHealthCheck(upstreamName string, generatedUpstreamNa
144144
hc.Interval = generateTimeWithDefault(u.HealthCheck.Interval, hc.Interval)
145145
hc.Jitter = generateTimeWithDefault(u.HealthCheck.Jitter, hc.Jitter)
146146
hc.Timeout = generateTimeWithDefault(u.HealthCheck.Timeout, hc.Timeout)
147+
hc.Port = u.HealthCheck.Port
147148

148149
if u.HealthCheck.Fails > 0 {
149150
hc.Fails = u.HealthCheck.Fails
@@ -153,10 +154,6 @@ func generateTransportServerHealthCheck(upstreamName string, generatedUpstreamNa
153154
hc.Passes = u.HealthCheck.Passes
154155
}
155156

156-
if u.HealthCheck.Port > 0 {
157-
hc.Port = u.HealthCheck.Port
158-
}
159-
160157
if u.HealthCheck.Match != nil {
161158
name := "match_" + generatedUpstreamName
162159
match = generateHealthCheckMatch(u.HealthCheck.Match, name)
@@ -175,7 +172,6 @@ func generateTransportServerHealthCheckWithDefaults(up conf_v1alpha1.Upstream) *
175172
Enabled: false,
176173
Timeout: "5s",
177174
Jitter: "0s",
178-
Port: up.Port,
179175
Interval: "5s",
180176
Passes: 1,
181177
Fails: 1,

internal/configs/transportserver_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ func TestGenerateTransportServerHealthChecks(t *testing.T) {
642642
Enabled: true,
643643
Timeout: "5s",
644644
Jitter: "0s",
645-
Port: 90,
646645
Interval: "5s",
647646
Passes: 1,
648647
Fails: 1,
@@ -668,7 +667,6 @@ func TestGenerateTransportServerHealthChecks(t *testing.T) {
668667
Enabled: true,
669668
Timeout: "5s",
670669
Jitter: "0s",
671-
Port: 90,
672670
Interval: "5s",
673671
Passes: 1,
674672
Fails: 1,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ server {
5353
proxy_pass {{ $s.ProxyPass }};
5454

5555
{{ if $s.HealthCheck }}
56-
health_check interval={{ $s.HealthCheck.Interval }} port={{ $s.HealthCheck.Port }}
56+
health_check interval={{ $s.HealthCheck.Interval }} {{ if $s.HealthCheck.Port }} port={{ $s.HealthCheck.Port }}{{ end }}
5757
passes={{ $s.HealthCheck.Passes }} jitter={{ $s.HealthCheck.Jitter }} fails={{ $s.HealthCheck.Fails }}{{ if $s.UDP }} udp{{ end }}{{ if $s.HealthCheck.Match }} match={{ $s.HealthCheck.Match }}{{ end }};
5858
health_check_timeout {{ $s.HealthCheck.Timeout }};
5959
{{ end }}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ server {
248248
{{ else }}
249249
proxy_pass {{ $hc.ProxyPass }};
250250
{{ end }}
251-
health_check {{ if $hc.URI }}uri={{ $hc.URI }} {{ end }}port={{ $hc.Port }} interval={{ $hc.Interval }} jitter={{ $hc.Jitter }}
251+
health_check {{ if $hc.URI }}uri={{ $hc.URI }} {{ end }}{{ if $hc.Port }}port={{ $hc.Port }} {{ end }}interval={{ $hc.Interval }} jitter={{ $hc.Jitter }}
252252
fails={{ $hc.Fails }} passes={{ $hc.Passes }}{{ if $hc.Match }} match={{ $hc.Match }}{{ end }}
253253
{{ if $hc.Mandatory }} mandatory{{ if $hc.Persistent }} persistent{{ end }}{{ end }}
254254
{{ if $hc.GRPCPass }} type=grpc{{ if $hc.GRPCStatus }} grpc_status={{ $hc.GRPCStatus }}{{ end }}

internal/configs/virtualserver.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ func newHealthCheckWithDefaults(upstream conf_v1.Upstream, upstreamName string,
216216
Jitter: "0s",
217217
Fails: 1,
218218
Passes: 1,
219-
Port: int(upstream.Port),
220219
ProxyPass: fmt.Sprintf("%v://%v", generateProxyPassProtocol(upstream.TLS.Enable), upstreamName),
221220
ProxyConnectTimeout: generateTimeWithDefault(upstream.ProxyConnectTimeout, cfgParams.ProxyConnectTimeout),
222221
ProxyReadTimeout: generateTimeWithDefault(upstream.ProxyReadTimeout, cfgParams.ProxyReadTimeout),
@@ -1321,10 +1320,6 @@ func generateHealthCheck(
13211320
hc.Passes = upstream.HealthCheck.Passes
13221321
}
13231322

1324-
if upstream.HealthCheck.Port > 0 {
1325-
hc.Port = upstream.HealthCheck.Port
1326-
}
1327-
13281323
if upstream.HealthCheck.ConnectTimeout != "" {
13291324
hc.ProxyConnectTimeout = generateTime(upstream.HealthCheck.ConnectTimeout)
13301325
}
@@ -1349,6 +1344,8 @@ func generateHealthCheck(
13491344
hc.Match = generateStatusMatchName(upstreamName)
13501345
}
13511346

1347+
hc.Port = upstream.HealthCheck.Port
1348+
13521349
hc.Mandatory = upstream.HealthCheck.Mandatory
13531350

13541351
hc.Persistent = upstream.HealthCheck.Persistent

tests/suite/test_transport_server_tcp_load_balance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def test_tcp_passing_healthcheck_with_match(
494494

495495
match = f"match_ts_{transport_server_setup.namespace}_transport-server_tcp-app"
496496

497-
assert "health_check interval=5s port=3333" in result_conf
497+
assert "health_check interval=5s" in result_conf
498498
assert f"passes=1 jitter=0s fails=1 match={match}" in result_conf
499499
assert "health_check_timeout 3s;"
500500
assert 'send "health"' in result_conf
@@ -559,7 +559,7 @@ def test_tcp_failing_healthcheck_with_match(
559559

560560
match = f"match_ts_{transport_server_setup.namespace}_transport-server_tcp-app"
561561

562-
assert "health_check interval=5s port=3333" in result_conf
562+
assert "health_check interval=5s" in result_conf
563563
assert f"passes=1 jitter=0s fails=1 match={match}" in result_conf
564564
assert "health_check_timeout 3s"
565565
assert 'send "health"' in result_conf

tests/suite/test_transport_server_udp_load_balance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_udp_passing_healthcheck_with_match(
284284

285285
match = f"match_ts_{transport_server_setup.namespace}_transport-server_udp-app"
286286

287-
assert "health_check interval=5s port=3334" in result_conf
287+
assert "health_check interval=5s" in result_conf
288288
assert f"passes=1 jitter=0s fails=1 udp match={match}" in result_conf
289289
assert "health_check_timeout 3s;"
290290
assert 'send "health"' in result_conf
@@ -350,7 +350,7 @@ def test_udp_failing_healthcheck_with_match(
350350

351351
match = f"match_ts_{transport_server_setup.namespace}_transport-server_udp-app"
352352

353-
assert "health_check interval=5s port=3334" in result_conf
353+
assert "health_check interval=5s" in result_conf
354354
assert f"passes=1 jitter=0s fails=1 udp match={match}" in result_conf
355355
assert "health_check_timeout 3s;"
356356
assert 'send "health"' in result_conf

tests/suite/test_virtual_server_upstream_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def test_openapi_validation_flow(self, kube_apis, ingress_controller_prerequisit
302302
class TestOptionsSpecificForPlus:
303303
@pytest.mark.parametrize('options, expected_strings', [
304304
({"lb-method": "least_conn",
305-
"healthCheck": {"enable": True, "port": 8080, "mandatory": True, "persistent": True},
305+
"healthCheck": {"enable": True, "mandatory": True, "persistent": True},
306306
"slow-start": "3h",
307307
"queue": {"size": 100},
308308
"ntlm": True,
@@ -311,7 +311,7 @@ class TestOptionsSpecificForPlus:
311311
"path": "/some-valid/path",
312312
"expires": "max",
313313
"domain": "virtual-server-route.example.com", "httpOnly": True, "secure": True}},
314-
["health_check uri=/ port=8080 interval=5s jitter=0s", "fails=1 passes=1", "mandatory persistent", ";",
314+
["health_check uri=/ interval=5s jitter=0s", "fails=1 passes=1", "mandatory persistent", ";",
315315
"slow_start=3h", "queue 100 timeout=60s;", "ntlm;",
316316
"sticky cookie TestCookie expires=max domain=virtual-server-route.example.com httponly secure path=/some-valid/path;"]),
317317
({"lb-method": "least_conn",

0 commit comments

Comments
 (0)
0