Loading src/openop_tfsdk/contract/adapters/kubernetes.py +4 −0 Changes for src/openop_tfsdk/contract/adapters/kubernetes.py: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,10 @@ def _chart_args(unit) -> list: name = f"p{interface.port}-{protocol.lower()}" ports[name] = {"name": name, "port": interface.port, "protocol": protocol} external = any(interface.visibility == "external" for interface in interfaces) if external and any(interface.visibility == "internal" for interface in interfaces): raise ValidationError( "kubernetes container does not support mixed internal and external ports" ) values = { "image": unit.artifact_ref, "ports": list(ports.values()), Loading tests/contract/test_kubernetes_container.py +19 −3 Changes for tests/contract/test_kubernetes_container.py: 19 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -54,8 +54,16 @@ def test_bundled_chart_ships_with_the_adapter(): @pytest.mark.parametrize("action", ["activate", "update"]) def test_container_runs_the_image_from_the_bundled_chart(helm_calls, action): interfaces = [_interface(80, visibility="external"), _interface(9000, "udp")] @pytest.mark.parametrize( "visibility, service_type", [("external", "NodePort"), ("internal", "ClusterIP")] ) def test_container_runs_the_image_from_the_bundled_chart( helm_calls, action, visibility, service_type ): interfaces = [ _interface(80, visibility=visibility), _interface(9000, "udp", visibility=visibility), ] getattr(KubernetesCapabilityAdapter(), action)(_request("container", interfaces=interfaces)) assert helm_calls[0][3] == CONTAINER_CHART assert _values(helm_calls[0]) == { Loading @@ -64,7 +72,7 @@ def test_container_runs_the_image_from_the_bundled_chart(helm_calls, action): {"name": "p80-tcp", "port": 80, "protocol": "TCP"}, {"name": "p9000-udp", "port": 9000, "protocol": "UDP"}, ], "serviceType": "NodePort", "serviceType": service_type, } Loading Loading @@ -93,3 +101,11 @@ def test_unsupported_unit_is_rejected_before_helm(helm_calls, runtime_type, inte with pytest.raises(ValidationError): KubernetesCapabilityAdapter().activate(_request(runtime_type, interfaces=interfaces)) assert helm_calls == [] @pytest.mark.parametrize("action", ["activate", "update"]) def test_mixed_visibility_is_rejected_before_exposing_internal_ports(helm_calls, action): interfaces = [_interface(80, visibility="external"), _interface(9000, "udp")] with pytest.raises(ValidationError, match="mixed internal and external"): getattr(KubernetesCapabilityAdapter(), action)(_request("container", interfaces=interfaces)) assert helm_calls == [] Loading
src/openop_tfsdk/contract/adapters/kubernetes.py +4 −0 Changes for src/openop_tfsdk/contract/adapters/kubernetes.py: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,10 @@ def _chart_args(unit) -> list: name = f"p{interface.port}-{protocol.lower()}" ports[name] = {"name": name, "port": interface.port, "protocol": protocol} external = any(interface.visibility == "external" for interface in interfaces) if external and any(interface.visibility == "internal" for interface in interfaces): raise ValidationError( "kubernetes container does not support mixed internal and external ports" ) values = { "image": unit.artifact_ref, "ports": list(ports.values()), Loading
tests/contract/test_kubernetes_container.py +19 −3 Changes for tests/contract/test_kubernetes_container.py: 19 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -54,8 +54,16 @@ def test_bundled_chart_ships_with_the_adapter(): @pytest.mark.parametrize("action", ["activate", "update"]) def test_container_runs_the_image_from_the_bundled_chart(helm_calls, action): interfaces = [_interface(80, visibility="external"), _interface(9000, "udp")] @pytest.mark.parametrize( "visibility, service_type", [("external", "NodePort"), ("internal", "ClusterIP")] ) def test_container_runs_the_image_from_the_bundled_chart( helm_calls, action, visibility, service_type ): interfaces = [ _interface(80, visibility=visibility), _interface(9000, "udp", visibility=visibility), ] getattr(KubernetesCapabilityAdapter(), action)(_request("container", interfaces=interfaces)) assert helm_calls[0][3] == CONTAINER_CHART assert _values(helm_calls[0]) == { Loading @@ -64,7 +72,7 @@ def test_container_runs_the_image_from_the_bundled_chart(helm_calls, action): {"name": "p80-tcp", "port": 80, "protocol": "TCP"}, {"name": "p9000-udp", "port": 9000, "protocol": "UDP"}, ], "serviceType": "NodePort", "serviceType": service_type, } Loading Loading @@ -93,3 +101,11 @@ def test_unsupported_unit_is_rejected_before_helm(helm_calls, runtime_type, inte with pytest.raises(ValidationError): KubernetesCapabilityAdapter().activate(_request(runtime_type, interfaces=interfaces)) assert helm_calls == [] @pytest.mark.parametrize("action", ["activate", "update"]) def test_mixed_visibility_is_rejected_before_exposing_internal_ports(helm_calls, action): interfaces = [_interface(80, visibility="external"), _interface(9000, "udp")] with pytest.raises(ValidationError, match="mixed internal and external"): getattr(KubernetesCapabilityAdapter(), action)(_request("container", interfaces=interfaces)) assert helm_calls == []