Skip to content

Commit c690c65

Browse files
committed
Add test for forwarded node port matching Kind config and NodePort service
1 parent 73c0dd4 commit c690c65

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎dev/breeze/tests/test_kubernetes_utils.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
import pytest
2323
import yaml
2424

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"
2629

2730
SINGLE_NODE_CONFIG = """\
2831
kind: Cluster
@@ -85,3 +88,22 @@ def test_get_kubernetes_port_numbers_raises_when_forwarded_port_mapping_is_missi
8588
mock_get_content.return_value = yaml.safe_load(NO_FORWARDED_PORT_CONFIG)
8689
with pytest.raises(ValueError, match="extraPortMappings"):
8790
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

Comments
 (0)