From a9d043380b4529c8aee7b6f05a035e7e73b6cc28 Mon Sep 17 00:00:00 2001 From: Kushal Deb Date: Fri, 14 Feb 2025 22:46:09 +0530 Subject: [PATCH] cephadm: ingress- Add v4v6 flag to HAProxy bind directive Signed-off-by: Kushal Deb --- src/pybind/mgr/cephadm/services/ingress.py | 3 ++ .../templates/services/ingress/haproxy.cfg.j2 | 4 +-- src/pybind/mgr/cephadm/tests/test_services.py | 28 ++++++++++++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/pybind/mgr/cephadm/services/ingress.py b/src/pybind/mgr/cephadm/services/ingress.py index 60fc586da85c6..13c76a85fc720 100644 --- a/src/pybind/mgr/cephadm/services/ingress.py +++ b/src/pybind/mgr/cephadm/services/ingress.py @@ -196,6 +196,8 @@ class IngressService(CephService): server_opts.append("send-proxy-v2") logger.debug("enabled default server opts: %r", server_opts) ip = '[::]' if spec.virtual_ips_list else str(spec.virtual_ip).split('/')[0] or daemon_spec.ip or '[::]' + v4v6_flag = "v4v6" if ip == "[::]" else "" + frontend_port = daemon_spec.ports[0] if daemon_spec.ports else spec.frontend_port if ip != '[::]' and frontend_port: daemon_spec.port_ips = {str(frontend_port): ip} @@ -214,6 +216,7 @@ class IngressService(CephService): 'local_host_ip': host_ip, 'default_server_opts': server_opts, 'health_check_interval': spec.health_check_interval or '2s', + 'v4v6_flag': v4v6_flag, } ) config_files = { 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 9a0309ab409d5..27c0a6d5c7147 100644 --- a/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 +++ b/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 @@ -58,9 +58,9 @@ frontend stats frontend frontend {% if spec.ssl_cert %} - bind {{ ip }}:{{ frontend_port }} ssl crt /var/lib/haproxy/haproxy.pem + bind {{ ip }}:{{ frontend_port }} ssl crt /var/lib/haproxy/haproxy.pem {{ v4v6_flag }} {% else %} - bind {{ ip }}:{{ frontend_port }} + bind {{ ip }}:{{ frontend_port }} {{ v4v6_flag }} {% endif %} default_backend backend diff --git a/src/pybind/mgr/cephadm/tests/test_services.py b/src/pybind/mgr/cephadm/tests/test_services.py index ebdbcc4991d04..7761a58128cfc 100644 --- a/src/pybind/mgr/cephadm/tests/test_services.py +++ b/src/pybind/mgr/cephadm/tests/test_services.py @@ -2447,7 +2447,11 @@ class TestIngressService: haproxy_generated_conf = service_registry.get_service('ingress').haproxy_generate_config( CephadmDaemonDeploySpec(host='host1', daemon_id='ingress', service_name=ispec.service_name())) - assert haproxy_generated_conf[0] == haproxy_expected_conf + haproxy_generated_conf = haproxy_generated_conf[0] + gen_config_lines = [line.rstrip() for line in haproxy_generated_conf['files']['haproxy.cfg'].splitlines()] + exp_config_line = [line.rstrip() for line in haproxy_expected_conf['files']['haproxy.cfg'].splitlines()] + + assert gen_config_lines == exp_config_line # swapping order now, should still pick out the one with the higher rank_generation # in this case both nfs are rank 0, so it should only take the one with rank_generation 1 a.k.a @@ -2458,10 +2462,13 @@ class TestIngressService: ] _get_daemons_by_service.return_value = nfs_daemons - haproxy_generated_conf = service_registry.get_service('ingress').haproxy_generate_config( + haproxy_generated_conf, _ = service_registry.get_service('ingress').haproxy_generate_config( CephadmDaemonDeploySpec(host='host1', daemon_id='ingress', service_name=ispec.service_name())) - assert haproxy_generated_conf[0] == haproxy_expected_conf + gen_config_lines = [line.rstrip() for line in haproxy_generated_conf['files']['haproxy.cfg'].splitlines()] + exp_config_lines = [line.rstrip() for line in haproxy_expected_conf['files']['haproxy.cfg'].splitlines()] + + assert gen_config_lines == exp_config_lines @patch("cephadm.serve.CephadmServe._run_cephadm") def test_ingress_config(self, _run_cephadm, cephadm_module: CephadmOrchestrator): @@ -2591,7 +2598,10 @@ class TestIngressService: } } - assert haproxy_generated_conf[0] == haproxy_expected_conf + gen_config_lines = [line.rstrip() for line in haproxy_generated_conf[0]['files']['haproxy.cfg'].splitlines()] + exp_config_lines = [line.rstrip() for line in haproxy_expected_conf['files']['haproxy.cfg'].splitlines()] + + assert gen_config_lines == exp_config_lines @patch("cephadm.serve.CephadmServe._run_cephadm") def test_ingress_config_ssl_rgw(self, _run_cephadm, cephadm_module: CephadmOrchestrator): @@ -2719,7 +2729,9 @@ class TestIngressService: } } - assert haproxy_generated_conf[0] == haproxy_expected_conf + gen_config_lines = [line.rstrip() for line in haproxy_generated_conf[0]['files']['haproxy.cfg'].splitlines()] + exp_config_lines = [line.rstrip() for line in haproxy_expected_conf['files']['haproxy.cfg'].splitlines()] + assert gen_config_lines == exp_config_lines @patch("cephadm.serve.CephadmServe._run_cephadm") def test_ingress_config_multi_vips(self, _run_cephadm, cephadm_module: CephadmOrchestrator): @@ -2835,7 +2847,7 @@ class TestIngressService: 'http-request use-service prometheus-exporter if { path /metrics }\n ' 'monitor-uri /health\n' '\nfrontend frontend\n ' - 'bind [::]:8089\n ' + 'bind [::]:8089 v4v6\n ' 'default_backend backend\n\n' 'backend backend\n ' 'option forwardfor\n ' @@ -3353,7 +3365,9 @@ class TestIngressService: service_name=ispec.service_name(), ), ) - assert haproxy_generated_conf == haproxy_expected_conf + gen_config_lines = [line.rstrip() for line in haproxy_generated_conf['files']['haproxy.cfg'].splitlines()] + exp_config_lines = [line.rstrip() for line in haproxy_expected_conf['files']['haproxy.cfg'].splitlines()] + assert gen_config_lines == exp_config_lines nfs_generated_conf, _ = nfs_svc.generate_config( CephadmDaemonDeploySpec( -- 2.39.5