Skip to content

Commit d838ca2

Browse files
authored
allow for a listener with no hostname set (#908)
Signed-off-by: craig <[email protected]> rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED
1 parent b616a87 commit d838ca2

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

controllers/dnspolicy_dnsrecords.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ func (r *DNSPolicyReconciler) reconcileGatewayDNSRecords(ctx context.Context, ga
5555
}
5656

5757
log.V(3).Info("checking gateway for attached routes ", "gateway", gateway.Name)
58-
5958
for _, listener := range gateway.Spec.Listeners {
60-
listenerHost := *listener.Hostname
61-
if listenerHost == "" {
62-
log.Info("skipping listener no hostname assigned", listener.Name, "in ns ", gateway.Namespace)
59+
if listener.Hostname == nil || *listener.Hostname == "" {
60+
log.Info("skipping listener no hostname assigned", "listener", listener.Name, "in ns ", gateway.Namespace)
6361
continue
6462
}
63+
6564
hasAttachedRoute := false
6665
for _, statusListener := range gateway.Status.Listeners {
6766
if string(listener.Name) == string(statusListener.Name) {

tests/common/dnspolicy/dnspolicy_controller_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var _ = Describe("DNSPolicy controller", func() {
8080

8181
It("should validate loadBalancing field correctly", func(ctx SpecContext) {
8282
gateway = tests.NewGatewayBuilder("test-gateway", gatewayClass.Name, testNamespace).
83+
WithHTTPListener(tests.ListenerNameOne, "").
8384
WithHTTPListener(tests.ListenerNameOne, tests.HostTwo(domain)).Gateway
8485

8586
// simple should succeed
@@ -140,6 +141,7 @@ var _ = Describe("DNSPolicy controller", func() {
140141
It("should validate provider ref field correctly", func(ctx SpecContext) {
141142

142143
gateway = tests.NewGatewayBuilder("test-gateway", gatewayClass.Name, testNamespace).
144+
WithHTTPListener(tests.ListenerNameOne, "").
143145
WithHTTPListener(tests.ListenerNameOne, tests.HostTwo(domain)).Gateway
144146

145147
// should not allow an empty providerRef list

tests/common/tlspolicy/tlspolicy_controller_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ var _ = Describe("TLSPolicy controller", func() {
115115

116116
By("creating a valid Gateway")
117117
gateway = tests.NewGatewayBuilder("test-gateway", gatewayClass.Name, testNamespace).
118+
WithHTTPListener("no-host", "").
118119
WithHTTPListener("test-listener", "test.example.com").Gateway
119120
Expect(k8sClient.Create(ctx, gateway)).To(Succeed())
120121

tests/commons.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -548,14 +548,20 @@ func (t *GatewayBuilder) WithLabels(labels map[string]string) *GatewayBuilder {
548548
return t
549549
}
550550

551-
func (t *GatewayBuilder) WithHTTPListener(name, hostname string) *GatewayBuilder {
552-
typedHostname := gatewayapiv1.Hostname(hostname)
553-
t.WithListener(gatewayapiv1.Listener{
551+
func (t *GatewayBuilder) WithHTTPListener(name string, hostname string) *GatewayBuilder {
552+
553+
var typedHostname gatewayapiv1.Hostname
554+
gl := gatewayapiv1.Listener{
554555
Name: gatewayapiv1.SectionName(name),
555-
Hostname: &typedHostname,
556556
Port: gatewayapiv1.PortNumber(80),
557557
Protocol: gatewayapiv1.HTTPProtocolType,
558-
})
558+
}
559+
if hostname != "" {
560+
typedHostname = gatewayapiv1.Hostname(hostname)
561+
gl.Hostname = &typedHostname
562+
}
563+
564+
t.WithListener(gl)
559565
return t
560566
}
561567

0 commit comments

Comments
 (0)