Add UDP protocol support for K8s port definitions
- Parse protocol suffix (e.g., "8001/udp") in port definitions - Support multiple ports per container instead of just the first - Include protocol in NodePort service names for uniqueness - Enables Solana RPC deployments that require UDP for QUIC protocol Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>afd-caddy-ingress
parent
81e8af4d6b
commit
b458295fa5
|
|
@ -90,23 +90,30 @@ class ClusterInfo:
|
||||||
for raw_port in [str(p) for p in service_info["ports"]]:
|
for raw_port in [str(p) for p in service_info["ports"]]:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"service port: {raw_port}")
|
print(f"service port: {raw_port}")
|
||||||
if ":" in raw_port:
|
# Parse protocol suffix (e.g., "8001/udp" -> port=8001, protocol=UDP)
|
||||||
parts = raw_port.split(":")
|
protocol = "TCP"
|
||||||
|
port_str = raw_port
|
||||||
|
if "/" in raw_port:
|
||||||
|
port_str, proto = raw_port.rsplit("/", 1)
|
||||||
|
protocol = proto.upper()
|
||||||
|
if ":" in port_str:
|
||||||
|
parts = port_str.split(":")
|
||||||
if len(parts) != 2:
|
if len(parts) != 2:
|
||||||
raise Exception(f"Invalid port definition: {raw_port}")
|
raise Exception(f"Invalid port definition: {raw_port}")
|
||||||
node_port = int(parts[0])
|
node_port = int(parts[0])
|
||||||
pod_port = int(parts[1])
|
pod_port = int(parts[1])
|
||||||
else:
|
else:
|
||||||
node_port = None
|
node_port = None
|
||||||
pod_port = int(raw_port)
|
pod_port = int(port_str)
|
||||||
service = client.V1Service(
|
service = client.V1Service(
|
||||||
metadata=client.V1ObjectMeta(name=f"{self.app_name}-nodeport-{pod_port}"),
|
metadata=client.V1ObjectMeta(name=f"{self.app_name}-nodeport-{pod_port}-{protocol.lower()}"),
|
||||||
spec=client.V1ServiceSpec(
|
spec=client.V1ServiceSpec(
|
||||||
type="NodePort",
|
type="NodePort",
|
||||||
ports=[client.V1ServicePort(
|
ports=[client.V1ServicePort(
|
||||||
port=pod_port,
|
port=pod_port,
|
||||||
target_port=pod_port,
|
target_port=pod_port,
|
||||||
node_port=node_port
|
node_port=node_port,
|
||||||
|
protocol=protocol
|
||||||
)],
|
)],
|
||||||
selector={"app": self.app_name}
|
selector={"app": self.app_name}
|
||||||
)
|
)
|
||||||
|
|
@ -328,11 +335,23 @@ class ClusterInfo:
|
||||||
container_name = service_name
|
container_name = service_name
|
||||||
service_info = services[service_name]
|
service_info = services[service_name]
|
||||||
image = service_info["image"]
|
image = service_info["image"]
|
||||||
|
container_ports = []
|
||||||
if "ports" in service_info:
|
if "ports" in service_info:
|
||||||
port = int(service_info["ports"][0])
|
for raw_port in [str(p) for p in service_info["ports"]]:
|
||||||
|
# Parse protocol suffix (e.g., "8001/udp" -> port=8001, protocol=UDP)
|
||||||
|
protocol = "TCP"
|
||||||
|
port_str = raw_port
|
||||||
|
if "/" in raw_port:
|
||||||
|
port_str, proto = raw_port.rsplit("/", 1)
|
||||||
|
protocol = proto.upper()
|
||||||
|
# Handle host:container port mapping - use container port
|
||||||
|
if ":" in port_str:
|
||||||
|
port_str = port_str.split(":")[-1]
|
||||||
|
port = int(port_str)
|
||||||
|
container_ports.append(client.V1ContainerPort(container_port=port, protocol=protocol))
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"image: {image}")
|
print(f"image: {image}")
|
||||||
print(f"service port: {port}")
|
print(f"service ports: {container_ports}")
|
||||||
merged_envs = merge_envs(
|
merged_envs = merge_envs(
|
||||||
envs_from_compose_file(
|
envs_from_compose_file(
|
||||||
service_info["environment"]), self.environment_variables.map
|
service_info["environment"]), self.environment_variables.map
|
||||||
|
|
@ -352,7 +371,7 @@ class ClusterInfo:
|
||||||
image=image_to_use,
|
image=image_to_use,
|
||||||
image_pull_policy=image_pull_policy,
|
image_pull_policy=image_pull_policy,
|
||||||
env=envs,
|
env=envs,
|
||||||
ports=[client.V1ContainerPort(container_port=port)],
|
ports=container_ports if container_ports else None,
|
||||||
volume_mounts=volume_mounts,
|
volume_mounts=volume_mounts,
|
||||||
security_context=client.V1SecurityContext(
|
security_context=client.V1SecurityContext(
|
||||||
privileged=self.spec.get_privileged(),
|
privileged=self.spec.get_privileged(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue