Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Bug: LoadBalancers - Use Hostnames in addition to IP #187

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/187.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
k8s/reconciler: gateway addresses have invalid empty string when LoadBalancer services use a hostname for ExternalIP (like EKS)
```
10 changes: 8 additions & 2 deletions internal/k8s/reconciler/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,14 @@ func (g *K8sGateway) assignGatewayIPFromServiceIngress(ctx context.Context, serv
}

for _, ingress := range updated.Status.LoadBalancer.Ingress {
g.serviceReady = true
g.addresses = append(g.addresses, ingress.IP)
if ingress.IP != "" {
g.serviceReady = true
g.addresses = append(g.addresses, ingress.IP)
}
if ingress.Hostname != "" {
g.serviceReady = true
g.addresses = append(g.addresses, ingress.Hostname)
}
}

return nil
Expand Down
17 changes: 10 additions & 7 deletions internal/k8s/reconciler/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ func TestGatewayValidateGatewayIP(t *testing.T) {
{
IP: "4.4.4.4",
},
{
Hostname: "this.is.a.hostname",
},
},
},
},
}

for _, tc := range []struct {
// What IP address do we expect the Gateway to be assigned?
expectedIP string
expectedIPs []string

// Should the mock client expect a request for the Service?
// If false, the mock client expects a request for the Pod instead.
Expand All @@ -120,22 +123,22 @@ func TestGatewayValidateGatewayIP(t *testing.T) {
serviceType *core.ServiceType
}{
{
expectedIP: pod.Status.PodIP,
expectedIPs: []string{pod.Status.PodIP},
expectedIPFromSvc: false,
serviceType: nil,
},
{
expectedIP: pod.Status.HostIP,
expectedIPs: []string{pod.Status.HostIP},
expectedIPFromSvc: false,
serviceType: serviceType(core.ServiceTypeNodePort),
},
{
expectedIP: svc.Status.LoadBalancer.Ingress[0].IP,
expectedIPs: []string{svc.Status.LoadBalancer.Ingress[0].IP, svc.Status.LoadBalancer.Ingress[1].Hostname},
expectedIPFromSvc: true,
serviceType: serviceType(core.ServiceTypeLoadBalancer),
},
{
expectedIP: svc.Spec.ClusterIP,
expectedIPs: []string{svc.Spec.ClusterIP},
expectedIPFromSvc: true,
serviceType: serviceType(core.ServiceTypeClusterIP),
},
Expand Down Expand Up @@ -163,8 +166,8 @@ func TestGatewayValidateGatewayIP(t *testing.T) {
}
assert.NoError(t, gateway.validateGatewayIP(context.Background()))

require.Len(t, gateway.addresses, 1)
assert.Equal(t, tc.expectedIP, gateway.addresses[0])
require.Len(t, gateway.addresses, len(tc.expectedIPs))
assert.Equal(t, tc.expectedIPs, gateway.addresses)

assert.True(t, gateway.serviceReady)
})
Expand Down