Skip to content

Commit

Permalink
fix: only set gw.Spec.Addresses in gw.Status.Addresses (#1465)
Browse files Browse the repository at this point in the history
* only set gw.Spec.Addresses in gw.Status.Addresses

Dont append, just set/override the gw.Status.Addresses with the values
from gw.Spec.Addresses (which eventually get set in svc.Spec.ExternalIPs)

Relates to #1463

https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.Gateway

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* lint

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

---------

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed May 31, 2023
1 parent 903e481 commit eb62289
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions internal/status/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,44 @@ func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1b1.Gateway, svc *corev1.S
var addresses, hostnames []string
// Update the status addresses field.
if svc != nil {
if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
for i := range svc.Status.LoadBalancer.Ingress {
switch {
case len(svc.Status.LoadBalancer.Ingress[i].IP) > 0:
addresses = append(addresses, svc.Status.LoadBalancer.Ingress[i].IP)
case len(svc.Status.LoadBalancer.Ingress[i].Hostname) > 0:
// Remove when the following supports the hostname address type:
// https://github.com/kubernetes-sigs/gateway-api/blob/v0.5.0/conformance/utils/kubernetes/helpers.go#L201-L207
if svc.Status.LoadBalancer.Ingress[i].Hostname == "localhost" {
addresses = append(addresses, "127.0.0.1")
// If the addresses if explicitly set in the Gateway spec by the user, use it
// to populate the Status
if len(gw.Spec.Addresses) > 0 {
// Make sure the addresses have been populated into ExternalIPs
// and use that value
if len(svc.Spec.ExternalIPs) > 0 {
addresses = append(addresses, svc.Spec.ExternalIPs...)
}
} else {
if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
for i := range svc.Status.LoadBalancer.Ingress {
switch {
case len(svc.Status.LoadBalancer.Ingress[i].IP) > 0:
addresses = append(addresses, svc.Status.LoadBalancer.Ingress[i].IP)
case len(svc.Status.LoadBalancer.Ingress[i].Hostname) > 0:
// Remove when the following supports the hostname address type:
// https://github.com/kubernetes-sigs/gateway-api/blob/v0.5.0/conformance/utils/kubernetes/helpers.go#L201-L207
if svc.Status.LoadBalancer.Ingress[i].Hostname == "localhost" {
addresses = append(addresses, "127.0.0.1")
}
hostnames = append(hostnames, svc.Status.LoadBalancer.Ingress[i].Hostname)
}
hostnames = append(hostnames, svc.Status.LoadBalancer.Ingress[i].Hostname)
}
}
}

if svc.Spec.Type == corev1.ServiceTypeClusterIP {
for i := range svc.Spec.ClusterIPs {
if svc.Spec.ClusterIPs[i] != "" {
addresses = append(addresses, svc.Spec.ClusterIPs[i])
if svc.Spec.Type == corev1.ServiceTypeClusterIP {
for i := range svc.Spec.ClusterIPs {
if svc.Spec.ClusterIPs[i] != "" {
addresses = append(addresses, svc.Spec.ClusterIPs[i])
}
}
}
}

if svc.Spec.Type == corev1.ServiceTypeNodePort {
addresses = nodeAddresses
if svc.Spec.Type == corev1.ServiceTypeNodePort {
addresses = nodeAddresses
}
}

addresses = append(addresses, svc.Spec.ExternalIPs...)

var gwAddresses []gwapiv1b1.GatewayAddress
for i := range addresses {
addr := gwapiv1b1.GatewayAddress{
Expand Down

0 comments on commit eb62289

Please sign in to comment.