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

Commit

Permalink
Bug: LoadBalancers - Use Hostnames in addition to IP (#187)
Browse files Browse the repository at this point in the history
* Use Hostnames in addition to IPs

* Add changelog entry
  • Loading branch information
Andrew Stucki authored Apr 29, 2022
1 parent 8cd8b37 commit 5986efb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
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

0 comments on commit 5986efb

Please sign in to comment.