]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: ingress- Add v4v6 flag to HAProxy bind directive 61833/head
authorKushal Deb <Kushal.Deb@ibm.com>
Fri, 14 Feb 2025 17:16:09 +0000 (22:46 +0530)
committerKushal Deb <Kushal.Deb@ibm.com>
Mon, 17 Feb 2025 09:17:02 +0000 (14:47 +0530)
Signed-off-by: Kushal Deb <Kushal.Deb@ibm.com>
src/pybind/mgr/cephadm/services/ingress.py
src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2
src/pybind/mgr/cephadm/tests/test_services.py

index 60fc586da85c65582b3330e7f9c3f49492ee4805..13c76a85fc7203a230d796b970ff0d2a1b295df9 100644 (file)
@@ -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 = {
index 9a0309ab409d5f786b9d19f66275b6986efac4d9..27c0a6d5c71471d33c44e46013bcf6aa881756a5 100644 (file)
@@ -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
 
index ebdbcc4991d04e81269343c9851c779b8ec3910a..7761a58128cfcce3bee91292dad609e238c0b4a4 100644 (file)
@@ -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(