From 21f524582eb43a45efaf1b2c925e02f3d1992a96 Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Mon, 14 Nov 2022 18:49:42 +0100 Subject: [PATCH] mgr/cephadm: fix haproxy monitoring endpoint Fixes: https://tracker.ceph.com/issues/58021 Signed-off-by: Redouane Kachach (cherry picked from commit 9636d9467f7bbcbda31da7809065000c49326dca) Conflicts: src/pybind/mgr/cephadm/tests/test_services.py --- src/pybind/mgr/cephadm/services/ingress.py | 5 +++- .../templates/services/ingress/haproxy.cfg.j2 | 2 +- src/pybind/mgr/cephadm/tests/test_services.py | 24 +++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/pybind/mgr/cephadm/services/ingress.py b/src/pybind/mgr/cephadm/services/ingress.py index 01c51303fa5..f6d647f10cd 100644 --- a/src/pybind/mgr/cephadm/services/ingress.py +++ b/src/pybind/mgr/cephadm/services/ingress.py @@ -164,6 +164,7 @@ class IngressService(CephService): } for d in daemons if d.ports ] + host_ip = daemon_spec.ip or self.mgr.inventory.get_addr(daemon_spec.host) haproxy_conf = self.mgr.template.render( 'services/ingress/haproxy.cfg.j2', { @@ -176,6 +177,7 @@ class IngressService(CephService): 'ip': "*" if spec.virtual_ips_list else str(spec.virtual_ip).split('/')[0] or daemon_spec.ip or '*', 'frontend_port': daemon_spec.ports[0] if daemon_spec.ports else spec.frontend_port, 'monitor_port': daemon_spec.ports[1] if daemon_spec.ports else spec.monitor_port, + 'local_host_ip': host_ip } ) config_files = { @@ -277,7 +279,8 @@ class IngressService(CephService): if d.daemon_type == 'haproxy': assert d.ports port = d.ports[1] # monitoring port - script = f'/usr/bin/curl {build_url(scheme="http", host=d.ip or "localhost", port=port)}/health' + host_ip = d.ip or self.mgr.inventory.get_addr(d.hostname) + script = f'/usr/bin/curl {build_url(scheme="http", host=host_ip, port=port)}/health' assert script states = [] diff --git a/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 b/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 index 6d64c636345..a529798e739 100644 --- a/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 +++ b/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 @@ -48,7 +48,7 @@ defaults frontend stats mode http bind {{ ip }}:{{ monitor_port }} - bind localhost:{{ monitor_port }} + bind {{ local_host_ip }}:{{ monitor_port }} stats enable stats uri /stats stats refresh 10s diff --git a/src/pybind/mgr/cephadm/tests/test_services.py b/src/pybind/mgr/cephadm/tests/test_services.py index d51ac047cb0..6b4c65babf6 100644 --- a/src/pybind/mgr/cephadm/tests/test_services.py +++ b/src/pybind/mgr/cephadm/tests/test_services.py @@ -1105,7 +1105,7 @@ class TestIngressService: 'frontend stats\n' ' mode http\n' ' bind 192.168.122.100:9049\n' - ' bind localhost:9049\n' + ' bind host1:9049\n' ' stats enable\n' ' stats uri /stats\n' ' stats refresh 10s\n' @@ -1155,7 +1155,7 @@ class TestIngressService: def test_ingress_config(self, _run_cephadm, cephadm_module: CephadmOrchestrator): _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) - with with_host(cephadm_module, 'test'): + with with_host(cephadm_module, 'test', addr='1.2.3.7'): cephadm_module.cache.update_host_networks('test', { '1.2.3.0/24': { 'if0': ['1.2.3.4'] @@ -1187,7 +1187,7 @@ class TestIngressService: 'keepalived.conf': '# This file is generated by cephadm.\n' 'vrrp_script check_backend {\n ' - 'script "/usr/bin/curl http://localhost:8999/health"\n ' + 'script "/usr/bin/curl http://1.2.3.7:8999/health"\n ' 'weight -20\n ' 'interval 2\n ' 'rise 2\n ' @@ -1253,7 +1253,7 @@ class TestIngressService: '\nfrontend stats\n ' 'mode http\n ' 'bind 1.2.3.4:8999\n ' - 'bind localhost:8999\n ' + 'bind 1.2.3.7:8999\n ' 'stats enable\n ' 'stats uri /stats\n ' 'stats refresh 10s\n ' @@ -1268,7 +1268,7 @@ class TestIngressService: 'balance static-rr\n ' 'option httpchk HEAD / HTTP/1.0\n ' 'server ' - + haproxy_generated_conf[1][0] + ' 1::4:80 check weight 100\n' + + haproxy_generated_conf[1][0] + ' 1.2.3.7:80 check weight 100\n' } } @@ -1310,7 +1310,7 @@ class TestIngressService: 'keepalived.conf': '# This file is generated by cephadm.\n' 'vrrp_script check_backend {\n ' - 'script "/usr/bin/curl http://localhost:8999/health"\n ' + 'script "/usr/bin/curl http://[1::4]:8999/health"\n ' 'weight -20\n ' 'interval 2\n ' 'rise 2\n ' @@ -1376,7 +1376,7 @@ class TestIngressService: '\nfrontend stats\n ' 'mode http\n ' 'bind 1.2.3.4:8999\n ' - 'bind localhost:8999\n ' + 'bind 1::4:8999\n ' 'stats enable\n ' 'stats uri /stats\n ' 'stats refresh 10s\n ' @@ -1403,7 +1403,7 @@ class TestIngressService: def test_ingress_config_multi_vips(self, _run_cephadm, cephadm_module: CephadmOrchestrator): _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) - with with_host(cephadm_module, 'test'): + with with_host(cephadm_module, 'test', addr='1.2.3.7'): cephadm_module.cache.update_host_networks('test', { '1.2.3.0/24': { 'if0': ['1.2.3.1'] @@ -1436,7 +1436,7 @@ class TestIngressService: 'keepalived.conf': '# This file is generated by cephadm.\n' 'vrrp_script check_backend {\n ' - 'script "/usr/bin/curl http://localhost:8999/health"\n ' + 'script "/usr/bin/curl http://1.2.3.7:8999/health"\n ' 'weight -20\n ' 'interval 2\n ' 'rise 2\n ' @@ -1502,7 +1502,7 @@ class TestIngressService: '\nfrontend stats\n ' 'mode http\n ' 'bind *:8999\n ' - 'bind localhost:8999\n ' + 'bind 1.2.3.7:8999\n ' 'stats enable\n ' 'stats uri /stats\n ' 'stats refresh 10s\n ' @@ -1517,7 +1517,7 @@ class TestIngressService: 'balance static-rr\n ' 'option httpchk HEAD / HTTP/1.0\n ' 'server ' - + haproxy_generated_conf[1][0] + ' 1::4:80 check weight 100\n' + + haproxy_generated_conf[1][0] + ' 1.2.3.7:80 check weight 100\n' } } @@ -1570,7 +1570,7 @@ class TestIngressService: 'keepalived.conf': '# This file is generated by cephadm.\n' 'vrrp_script check_backend {\n ' - 'script "/usr/bin/curl http://localhost:8999/health"\n ' + 'script "/usr/bin/curl http://1.2.3.1:8999/health"\n ' 'weight -20\n ' 'interval 2\n ' 'rise 2\n ' -- 2.47.3