diff --git a/control-plane/api/mesh/v2beta1/api_gateway_types.go b/control-plane/api/mesh/v2beta1/api_gateway_types.go index 3eab687ecd..a62cc881c7 100644 --- a/control-plane/api/mesh/v2beta1/api_gateway_types.go +++ b/control-plane/api/mesh/v2beta1/api_gateway_types.go @@ -183,16 +183,7 @@ func (in *APIGateway) ListenersToServicePorts(portModifier int32) []corev1.Servi return ports } -func (in *APIGateway) ListenersToContainerPorts(portModifier int32) []corev1.ContainerPort { - ports := []corev1.ContainerPort{} - - for _, listener := range in.Spec.Listeners { - port := int32(listener.Port) - ports = append(ports, corev1.ContainerPort{ - Name: listener.Name, - ContainerPort: port + portModifier, - Protocol: corev1.Protocol(listener.Protocol), - }) - } - return ports +func (in *APIGateway) ListenersToContainerPorts(_ int32, _ int32) []corev1.ContainerPort { + // TODO: check if this is actually needed: we don't map any container ports in v1 + return []corev1.ContainerPort{} } diff --git a/control-plane/api/mesh/v2beta1/mesh_gateway_types.go b/control-plane/api/mesh/v2beta1/mesh_gateway_types.go index ae27550886..8bf8cc8435 100644 --- a/control-plane/api/mesh/v2beta1/mesh_gateway_types.go +++ b/control-plane/api/mesh/v2beta1/mesh_gateway_types.go @@ -166,7 +166,7 @@ func (in *MeshGateway) ListenersToServicePorts(portModifier int32) []corev1.Serv return ports } -func (in *MeshGateway) ListenersToContainerPorts(portModifier int32) []corev1.ContainerPort { +func (in *MeshGateway) ListenersToContainerPorts(portModifier int32, hostPort int32) []corev1.ContainerPort { ports := []corev1.ContainerPort{} for _, listener := range in.Spec.Listeners { @@ -175,6 +175,7 @@ func (in *MeshGateway) ListenersToContainerPorts(portModifier int32) []corev1.Co ports = append(ports, corev1.ContainerPort{ Name: listener.Name, ContainerPort: port + portModifier, + HostPort: hostPort, Protocol: corev1.Protocol(listener.Protocol), }) } diff --git a/control-plane/gateways/builder.go b/control-plane/gateways/builder.go index 8aeb5b0957..29242c1841 100644 --- a/control-plane/gateways/builder.go +++ b/control-plane/gateways/builder.go @@ -13,7 +13,7 @@ type Gateway interface { GetName() string GetNamespace() string ListenersToServicePorts(int32) []corev1.ServicePort - ListenersToContainerPorts(int32) []corev1.ContainerPort + ListenersToContainerPorts(int32, int32) []corev1.ContainerPort GetAnnotations() map[string]string GetLabels() map[string]string } diff --git a/control-plane/gateways/deployment_dataplane_container.go b/control-plane/gateways/deployment_dataplane_container.go index 7e7523d629..630e337ad5 100644 --- a/control-plane/gateways/deployment_dataplane_container.go +++ b/control-plane/gateways/deployment_dataplane_container.go @@ -117,7 +117,7 @@ func (b *gatewayBuilder[T]) consulDataplaneContainer(containerConfig v2beta1.Gat ContainerPort: int32(constants.ProxyDefaultHealthPort), }) - container.Ports = append(container.Ports, b.gateway.ListenersToContainerPorts(containerConfig.PortModifier)...) + container.Ports = append(container.Ports, b.gateway.ListenersToContainerPorts(containerConfig.PortModifier, containerConfig.HostPort)...) // Configure the resource requests and limits for the proxy if they are set. if resources != nil { diff --git a/control-plane/gateways/deployment_test.go b/control-plane/gateways/deployment_test.go index 99fc9b7090..2444d02e3d 100644 --- a/control-plane/gateways/deployment_test.go +++ b/control-plane/gateways/deployment_test.go @@ -67,6 +67,13 @@ func Test_gatewayBuilder_Deployment(t *testing.T) { }, Spec: pbmesh.MeshGateway{ GatewayClassName: "test-gateway-class", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 443, + Protocol: "tcp", + }, + }, }, }, config: GatewayConfig{}, @@ -327,6 +334,7 @@ func Test_gatewayBuilder_Deployment(t *testing.T) { Name: "wan", ContainerPort: 8443, HostPort: 8080, + Protocol: "tcp", }, }, Env: []corev1.EnvVar{ @@ -475,6 +483,13 @@ func Test_gatewayBuilder_Deployment(t *testing.T) { }, Spec: pbmesh.MeshGateway{ GatewayClassName: "test-gateway-class", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 443, + Protocol: "tcp", + }, + }, }, }, config: GatewayConfig{ @@ -728,6 +743,7 @@ func Test_gatewayBuilder_Deployment(t *testing.T) { Name: "wan", ContainerPort: 8443, HostPort: 8080, + Protocol: "tcp", }, }, Env: []corev1.EnvVar{ @@ -876,6 +892,13 @@ func Test_gatewayBuilder_Deployment(t *testing.T) { }, Spec: pbmesh.MeshGateway{ GatewayClassName: "test-gateway-class", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 443, + Protocol: "tcp", + }, + }, }, }, config: GatewayConfig{}, @@ -1009,6 +1032,7 @@ func Test_gatewayBuilder_Deployment(t *testing.T) { { Name: "wan", ContainerPort: 443, + Protocol: "tcp", }, }, Env: []corev1.EnvVar{