Skip to content

Commit f9ba83d

Browse files
committed
hostPort tests
1 parent 343d24a commit f9ba83d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

internal/controller/provisioner/objects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
781781
container.Args = append(container.Args, "debug")
782782
}
783783

784-
if containerSpec.HostPort != nil && containerSpec.HostPort.Enable && len(container.Ports) > 1 {
784+
if containerSpec.HostPort != nil && containerSpec.HostPort.Enable && len(container.Ports) > 0 {
785785
container.Ports[0].HostPort = containerSpec.HostPort.Port
786786
}
787787

internal/controller/provisioner/objects_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
257257
Name: "gw",
258258
Namespace: "default",
259259
},
260+
Spec: gatewayv1.GatewaySpec{
261+
Listeners: []gatewayv1.Listener{},
262+
},
260263
}
261264

262265
resourceName := "gw-nginx"
@@ -293,6 +296,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
293296
corev1.ResourceCPU: resource.Quantity{Format: "100m"},
294297
},
295298
},
299+
HostPort: &ngfAPIv1alpha2.HostPort{Enable: true, Port: int32(8443)},
296300
},
297301
},
298302
},
@@ -338,6 +342,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
338342
g.Expect(container.Ports).To(ContainElement(corev1.ContainerPort{
339343
ContainerPort: 8080,
340344
Name: "metrics",
345+
HostPort: int32(8443),
341346
}))
342347

343348
g.Expect(container.Image).To(Equal("nginx-repo:1.1.1"))

0 commit comments

Comments
 (0)