Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jm96441n committed Feb 6, 2024
1 parent b4d1455 commit b93b3b3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
15 changes: 3 additions & 12 deletions control-plane/api/mesh/v2beta1/api_gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
3 changes: 2 additions & 1 deletion control-plane/api/mesh/v2beta1/mesh_gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
})
}
Expand Down
2 changes: 1 addition & 1 deletion control-plane/gateways/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion control-plane/gateways/deployment_dataplane_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions control-plane/gateways/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -327,6 +334,7 @@ func Test_gatewayBuilder_Deployment(t *testing.T) {
Name: "wan",
ContainerPort: 8443,
HostPort: 8080,
Protocol: "tcp",
},
},
Env: []corev1.EnvVar{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -728,6 +743,7 @@ func Test_gatewayBuilder_Deployment(t *testing.T) {
Name: "wan",
ContainerPort: 8443,
HostPort: 8080,
Protocol: "tcp",
},
},
Env: []corev1.EnvVar{
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -1009,6 +1032,7 @@ func Test_gatewayBuilder_Deployment(t *testing.T) {
{
Name: "wan",
ContainerPort: 443,
Protocol: "tcp",
},
},
Env: []corev1.EnvVar{
Expand Down

0 comments on commit b93b3b3

Please sign in to comment.