|
22 | 22 | import pytest |
23 | 23 | import yaml |
24 | 24 |
|
25 | | -from airflow_breeze.utils.kubernetes_utils import get_kubernetes_port_numbers |
| 25 | +from airflow_breeze.utils.kubernetes_utils import FORWARDED_NODE_PORT, get_kubernetes_port_numbers |
| 26 | +from airflow_breeze.utils.path_utils import AIRFLOW_ROOT_PATH |
| 27 | + |
| 28 | +KUBERNETES_CI_PATH = AIRFLOW_ROOT_PATH / "scripts" / "ci" / "kubernetes" |
26 | 29 |
|
27 | 30 | SINGLE_NODE_CONFIG = """\ |
28 | 31 | kind: Cluster |
@@ -85,3 +88,22 @@ def test_get_kubernetes_port_numbers_raises_when_forwarded_port_mapping_is_missi |
85 | 88 | mock_get_content.return_value = yaml.safe_load(NO_FORWARDED_PORT_CONFIG) |
86 | 89 | with pytest.raises(ValueError, match="extraPortMappings"): |
87 | 90 | get_kubernetes_port_numbers(python="3.10", kubernetes_version="v1.30.13") |
| 91 | + |
| 92 | + |
| 93 | +def test_forwarded_node_port_matches_kind_config_and_nodeport_service(): |
| 94 | + # The template placeholders are not valid YAML scalars, so render them before parsing. |
| 95 | + kind_conf = yaml.safe_load( |
| 96 | + (KUBERNETES_CI_PATH / "kind-cluster-conf.yaml") |
| 97 | + .read_text() |
| 98 | + .replace("{{FORWARDED_PORT_NUMBER}}", "18150") |
| 99 | + .replace("{{API_SERVER_PORT}}", "48366") |
| 100 | + ) |
| 101 | + container_ports = [ |
| 102 | + port_mapping["containerPort"] |
| 103 | + for node in kind_conf["nodes"] |
| 104 | + for port_mapping in node.get("extraPortMappings", []) |
| 105 | + ] |
| 106 | + node_port_service = yaml.safe_load((KUBERNETES_CI_PATH / "nodeport.yaml").read_text()) |
| 107 | + |
| 108 | + assert container_ports == [FORWARDED_NODE_PORT] |
| 109 | + assert [port["nodePort"] for port in node_port_service["spec"]["ports"]] == [FORWARDED_NODE_PORT] |
0 commit comments