Skip to content

Commit 07750c3

Browse files
committed
feat: introduce additional flag for health check with proxy protocol
1 parent 59a10e8 commit 07750c3

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

jobs/haproxy/spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ properties:
577577
ha_proxy.disable_health_check_proxy:
578578
description: "Disables the use of the PROXY protocol for health checks. Only applies if `ha_proxy.accept_proxy` is enabled."
579579
default: false
580+
ha_proxy.enable_additional_health_check_proxy:
581+
description: "Enable the additional health check listener with use of the PROXY protocol"
582+
default: false
580583
ha_proxy.binding_ip:
581584
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."
582585
default: ""

jobs/haproxy/templates/haproxy.config.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ listen health_check_http_url
385385
acl http-routers_down nbsrv(<%= backends.first[:name] %>) eq 0
386386
monitor fail if http-routers_down
387387

388-
<%- if p("ha_proxy.expect_proxy_cidrs", []).size > 0 -%>
388+
<%- if p("ha_proxy.expect_proxy_cidrs", []).size > 0 || p("ha_proxy.enable_additional_health_check_proxy") -%>
389389
listen health_check_http_url_proxy_protocol
390390
bind :<%= p("ha_proxy.health_check_port") + 1 %> accept-proxy
391391
mode http
@@ -1101,7 +1101,7 @@ listen health_check_http_tcp-<%= tcp_proxy["name"] %>
11011101
acl tcp-<%= tcp_proxy["name"] %>-routers_down nbsrv(tcp-<%= tcp_proxy["name"] %>) eq 0
11021102
monitor fail if tcp-<%= tcp_proxy["name"] %>-routers_down
11031103

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

spec/haproxy/templates/haproxy_config/healthcheck_listener_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
context 'when ha_proxy.enable_health_check_http is true' do
1111
let(:healthcheck_listener) { haproxy_conf['listen health_check_http_url'] }
12+
let(:healthcheck_listener_proxy_protocol) { haproxy_conf['listen health_check_http_url_proxy_protocol'] }
1213

1314
let(:properties) do
1415
{
@@ -84,6 +85,35 @@
8485
expect(healthcheck_listener).not_to include('tcp-request connection expect-proxy layer4 unless LOCALHOST')
8586
end
8687
end
88+
89+
context 'when ha_proxy.enable_additional_health_check_proxy is also true' do
90+
let(:properties) do
91+
{
92+
'enable_health_check_http' => true,
93+
'accept_proxy' => true,
94+
'enable_additional_health_check_proxy' => true
95+
}
96+
end
97+
98+
it 'sets expect-proxy for the healthcheck' do
99+
expect(healthcheck_listener).to include('tcp-request connection expect-proxy layer4 unless LOCALHOST')
100+
expect(healthcheck_listener_proxy_protocol).to include('bind :8081 accept-proxy')
101+
end
102+
end
103+
104+
context 'when ha_proxy.enable_additional_health_check_proxy is false but accept_proxy true' do
105+
let(:properties) do
106+
{
107+
'enable_health_check_http' => true,
108+
'accept_proxy' => true
109+
}
110+
end
111+
112+
it 'sets expect-proxy for the healthcheck' do
113+
expect(healthcheck_listener).to include('tcp-request connection expect-proxy layer4 unless LOCALHOST')
114+
expect(haproxy_conf).not_to have_key('listen health_check_http_url_proxy_protocol')
115+
end
116+
end
87117
end
88118
end
89119
end

0 commit comments

Comments
 (0)