Skip to content

Commit 3075f3d

Browse files
committed
Listen on additional health check port only if it is configured via flag
1 parent 49ff4e5 commit 3075f3d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

jobs/haproxy/spec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ properties:
579579
default: false
580580
ha_proxy.enable_additional_health_check_proxy:
581581
description: "Enable the additional health check listener with use of the PROXY protocol"
582-
default: false
583582
ha_proxy.binding_ip:
584583
description: "If there are multiple ethernet interfaces, specify which one to bind. Set to `::` to bind to all IPv6 interfaces (no IPv4). IPv6 must be enabled on the HAProxy VM in the deployment manifest."
585584
default: ""
@@ -602,7 +601,7 @@ properties:
602601
- 172.168.4.1/32
603602
- 10.2.0.0/16
604603
ha_proxy.expect_proxy_cidrs:
605-
description: "List of CIDRs to enable proxy protocol for. This enables forwarding of the client source IP for hyperscalers not supporting IP dual stack (v4 & v6). This property is mutually exclusive with the accept_proxy."
604+
description: "List of CIDRs to enable proxy protocol for. This enables the forwarding of the client source IP for hyperscalers that do not support IP dual stack (v4 & v6). This property is mutually exclusive with the accept_proxy. For backward compatibility, if the list is not empty, HAProxy will listen on an additional health check port (health_check_port + 1) with proxy protocol enabled, by implicitly setting enable_additional_health_check_proxy to true if not set explicitly."
606605
default: ~
607606
example:
608607
expect_proxy_cidrs:

jobs/haproxy/templates/haproxy.config.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ end
271271
if backend_ssl != "" && (enable_http2 || backend_match_http_protocol)
272272
backends += [{ name: "http-routers-http2", backend_ssl: backend_ssl, alpn: "alpn h2,http/1.1 " }]
273273
end
274+
275+
# to keep backward compatibility enable_additional_health_check_proxy if expect_proxy_cidrs is not empty.
276+
enable_additional_health_check_proxy = p("ha_proxy.enable_additional_health_check_proxy", p("ha_proxy.expect_proxy_cidrs", []).size > 0)
277+
274278
-%>
275279

276280
global
@@ -385,7 +389,7 @@ listen health_check_http_url
385389
acl http-routers_down nbsrv(<%= backends.first[:name] %>) eq 0
386390
monitor fail if http-routers_down
387391

388-
<%- if p("ha_proxy.expect_proxy_cidrs", []).size > 0 || p("ha_proxy.enable_additional_health_check_proxy") -%>
392+
<%- if enable_additional_health_check_proxy -%>
389393
listen health_check_http_url_proxy_protocol
390394
bind :<%= p("ha_proxy.health_check_port") + 1 %> accept-proxy
391395
mode http
@@ -1101,7 +1105,7 @@ listen health_check_http_tcp-<%= tcp_proxy["name"] %>
11011105
acl tcp-<%= tcp_proxy["name"] %>-routers_down nbsrv(tcp-<%= tcp_proxy["name"] %>) eq 0
11021106
monitor fail if tcp-<%= tcp_proxy["name"] %>-routers_down
11031107

1104-
<%- if p("ha_proxy.expect_proxy_cidrs", []).size > 0 || p("ha_proxy.enable_additional_health_check_proxy") -%>
1108+
<%- if enable_additional_health_check_proxy -%>
11051109
listen health_check_http_tcp-<%= tcp_proxy["name"] %>_proxy_protocol
11061110
bind :<%= tcp_proxy["health_check_http"] + 1 %> accept-proxy
11071111
mode http

spec/haproxy/templates/haproxy_config/healthcheck_listener_spec.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,27 @@
9595
}
9696
end
9797

98-
it 'sets expect-proxy for the healthcheck' do
98+
it 'sets expect-proxy for the healthchecks on ports 8080 and 8081' do
99+
expect(healthcheck_listener).to include('bind :8080')
99100
expect(healthcheck_listener).to include('tcp-request connection expect-proxy layer4 unless LOCALHOST')
100101
expect(healthcheck_listener_proxy_protocol).to include('bind :8081 accept-proxy')
101102
end
102103
end
103104

105+
context 'when expect_proxy_cidrs is not empty due to backward compatibility' do
106+
let(:properties) do
107+
{
108+
'enable_health_check_http' => true,
109+
'expect_proxy_cidrs' => ['10.5.6.7/27']
110+
}
111+
end
112+
113+
it 'sets expect-proxy for the healthcheck on port 8081' do
114+
expect(healthcheck_listener).to include('bind :8080')
115+
expect(healthcheck_listener_proxy_protocol).to include('bind :8081 accept-proxy')
116+
end
117+
end
118+
104119
context 'when ha_proxy.enable_additional_health_check_proxy is false but accept_proxy true' do
105120
let(:properties) do
106121
{

0 commit comments

Comments
 (0)