Commit f31da05c authored by Konstantinos Togias's avatar Konstantinos Togias
Browse files

refactor: share workload endpoint result construction

parent 4a8bf2a3
Loading
Loading
Loading
Loading
Loading
+10 −12
Changes for src/openop_tfsdk/contract/adapters/kubernetes.py: 10 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -234,29 +234,27 @@ class KubernetesCapabilityAdapter:
        try:
            if unit.runtime_type == "helm":
                services = _release_services(release, namespace, self._connection)
                return [
                    ServiceEndpoint(
                        interface_id=interface.interface_id,
                        fqdn=host,
                        port=_helm_node_port(services, interface),
                    )
                    for interface in external
                ]
            if unit.runtime_type != "container":
                return None
                ports = [_helm_node_port(services, interface) for interface in external]
            elif unit.runtime_type == "container":
                service = _read_service(release, namespace, self._connection)
                node_ports = {
                    port.name: port.node_port
                    for port in service.spec.ports or []
                    if port.node_port is not None
                }
                ports = [
                    node_ports[f"p{interface.port}-{interface.protocol.lower()}"]
                    for interface in external
                ]
            else:
                return None
            return [
                ServiceEndpoint(
                    interface_id=interface.interface_id,
                    fqdn=host,
                    port=node_ports[f"p{interface.port}-{interface.protocol.lower()}"],
                    port=port,
                )
                for interface in external
                for interface, port in zip(external, ports)
            ]
        except (
            OSError,