Skip to content

Commit

Permalink
Fix Gateway Status Addresses Updater with multiple Ingress entries. (#…
Browse files Browse the repository at this point in the history
…5651)

* Fix Gateway Status Addresses Updater with multiple Ingress entries.

That field is used by other components like k8s external-dns, and should contains all information provided by the envoy service load balancer status.

Fixes #5650

Signed-off-by: Jean-Daniel Dupas <jddupas@xooloo.com>

* Changelog

Signed-off-by: Jean-Daniel Dupas <jddupas@xooloo.com>

---------

Signed-off-by: Jean-Daniel Dupas <jddupas@xooloo.com>
Co-authored-by: Jean-Daniel Dupas <jddupas@xooloo.com>
  • Loading branch information
Jean-Daniel and Jean-Daniel Dupas authored Aug 11, 2023
1 parent 3231bf7 commit 4c00ba9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5651-Jean-Daniel-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gateway provisioner: Expose all Envoy service IPs and Hostname in `Gateway.Status.Addresses`. Only the first IP was exposed before, even for dual-stack service.
43 changes: 22 additions & 21 deletions internal/k8s/statusaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,7 @@ func (s *StatusAddressUpdater) OnAdd(obj any, isInInitialList bool) {
}

dco := gateway.DeepCopy()

if len(loadBalancerStatus.Ingress) == 0 {
return dco
}

if ip := loadBalancerStatus.Ingress[0].IP; len(ip) > 0 {
dco.Status.Addresses = []gatewayapi_v1beta1.GatewayAddress{
{
Type: ref.To(gatewayapi_v1beta1.IPAddressType),
Value: ip,
},
}
} else if hostname := loadBalancerStatus.Ingress[0].Hostname; len(hostname) > 0 {
dco.Status.Addresses = []gatewayapi_v1beta1.GatewayAddress{
{
Type: ref.To(gatewayapi_v1beta1.HostnameAddressType),
Value: hostname,
},
}
}

dco.Status.Addresses = lbStatusToGatewayAddresses(loadBalancerStatus)
return dco
}),
))
Expand Down Expand Up @@ -305,3 +285,24 @@ func coreToNetworkingLBStatus(lbs v1.LoadBalancerStatus) networking_v1.IngressLo
Ingress: ingress,
}
}

func lbStatusToGatewayAddresses(lbs v1.LoadBalancerStatus) []gatewayapi_v1beta1.GatewayAddress {
addrs := []gatewayapi_v1beta1.GatewayAddress{}

for _, lbi := range lbs.Ingress {
if len(lbi.IP) > 0 {
addrs = append(addrs, gatewayapi_v1beta1.GatewayAddress{
Type: ref.To(gatewayapi_v1beta1.IPAddressType),
Value: lbi.IP,
})
}
if len(lbi.Hostname) > 0 {
addrs = append(addrs, gatewayapi_v1beta1.GatewayAddress{
Type: ref.To(gatewayapi_v1beta1.HostnameAddressType),
Value: lbi.Hostname,
})
}
}

return addrs
}
11 changes: 11 additions & 0 deletions internal/k8s/statusaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ func TestStatusAddressUpdater_Gateway(t *testing.T) {
{
IP: "127.0.0.1",
},
{
IP: "fe80::1",
},
},
}

Expand Down Expand Up @@ -417,6 +420,10 @@ func TestStatusAddressUpdater_Gateway(t *testing.T) {
Type: ref.To(gatewayapi_v1beta1.IPAddressType),
Value: ipLBStatus.Ingress[0].IP,
},
{
Type: ref.To(gatewayapi_v1beta1.IPAddressType),
Value: ipLBStatus.Ingress[1].IP,
},
},
},
},
Expand Down Expand Up @@ -581,6 +588,10 @@ func TestStatusAddressUpdater_Gateway(t *testing.T) {
Type: ref.To(gatewayapi_v1beta1.IPAddressType),
Value: ipLBStatus.Ingress[0].IP,
},
{
Type: ref.To(gatewayapi_v1beta1.IPAddressType),
Value: ipLBStatus.Ingress[1].IP,
},
},
},
},
Expand Down

0 comments on commit 4c00ba9

Please sign in to comment.