Expose all ports from http-proxy routes in k8s Service

Previously get_service() only exposed the first port from pod definition.
Now it collects all unique ports from http-proxy routes and exposes them
all in the Service spec.

This is needed for WebSocket support where RPC runs on one port (8899)
and WebSocket pubsub on another (8900) - both need to be accessible
through the ingress.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
multi-port-service
A. F. Dudley 2026-01-24 15:13:11 -05:00
parent 811bbd9db4
commit 4f01054781
1 changed files with 21 additions and 12 deletions

View File

@ -216,23 +216,32 @@ class ClusterInfo:
# TODO: suppoprt multiple services # TODO: suppoprt multiple services
def get_service(self): def get_service(self):
port = None # Collect all ports from http-proxy routes
for pod_name in self.parsed_pod_yaml_map: ports_set = set()
pod = self.parsed_pod_yaml_map[pod_name] http_proxy_list = self.spec.get_http_proxy()
services = pod["services"] if http_proxy_list:
for service_name in services: for http_proxy in http_proxy_list:
service_info = services[service_name] for route in http_proxy.get("routes", []):
if "ports" in service_info: proxy_to = route.get("proxy-to", "")
port = int(service_info["ports"][0]) if ":" in proxy_to:
if opts.o.debug: port = int(proxy_to.split(":")[1])
print(f"service port: {port}") ports_set.add(port)
if port is None: if opts.o.debug:
print(f"http-proxy route port: {port}")
if not ports_set:
return None return None
service_ports = [
client.V1ServicePort(port=p, target_port=p, name=f"port-{p}")
for p in sorted(ports_set)
]
service = client.V1Service( service = client.V1Service(
metadata=client.V1ObjectMeta(name=f"{self.app_name}-service"), metadata=client.V1ObjectMeta(name=f"{self.app_name}-service"),
spec=client.V1ServiceSpec( spec=client.V1ServiceSpec(
type="ClusterIP", type="ClusterIP",
ports=[client.V1ServicePort(port=port, target_port=port)], ports=service_ports,
selector={"app": self.app_name}, selector={"app": self.app_name},
), ),
) )