diff --git a/internal/gatewayapi/status/gateway.go b/internal/gatewayapi/status/gateway.go index 5c0354c0be..af45012b67 100644 --- a/internal/gatewayapi/status/gateway.go +++ b/internal/gatewayapi/status/gateway.go @@ -58,7 +58,12 @@ func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1.Gateway, svc *corev1.Ser if len(svc.Spec.ExternalIPs) > 0 { addresses = append(addresses, svc.Spec.ExternalIPs...) } else if len(svc.Spec.ClusterIPs) > 0 { - addresses = append(addresses, svc.Spec.ClusterIPs...) + // Filter out "None" values which represent headless services + for _, ip := range svc.Spec.ClusterIPs { + if ip != "" && ip != "None" { + addresses = append(addresses, ip) + } + } } } else { if svc.Spec.Type == corev1.ServiceTypeLoadBalancer { @@ -79,7 +84,8 @@ func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1.Gateway, svc *corev1.Ser if svc.Spec.Type == corev1.ServiceTypeClusterIP { for i := range svc.Spec.ClusterIPs { - if svc.Spec.ClusterIPs[i] != "" { + // Filter out "None" values which represent headless services + if svc.Spec.ClusterIPs[i] != "" && svc.Spec.ClusterIPs[i] != "None" { addresses = append(addresses, svc.Spec.ClusterIPs[i]) } } diff --git a/internal/gatewayapi/status/gateway_test.go b/internal/gatewayapi/status/gateway_test.go index c2d18a7fc1..0dcb550a10 100644 --- a/internal/gatewayapi/status/gateway_test.go +++ b/internal/gatewayapi/status/gateway_test.go @@ -242,6 +242,45 @@ func TestUpdateGatewayStatusProgrammedCondition(t *testing.T) { }, }, }, + { + name: "Headless ClusterIP svc with None", + args: args{ + gw: &gwapiv1.Gateway{}, + svc: &corev1.Service{ + TypeMeta: metav1.TypeMeta{}, + ObjectMeta: metav1.ObjectMeta{}, + Spec: corev1.ServiceSpec{ + ClusterIPs: []string{"None"}, + Type: corev1.ServiceTypeClusterIP, + }, + }, + }, + wantAddresses: []gwapiv1.GatewayStatusAddress{}, + }, + { + name: "Headless ClusterIP svc with None and explicit Gateway addresses", + args: args{ + gw: &gwapiv1.Gateway{ + Spec: gwapiv1.GatewaySpec{ + Addresses: []gwapiv1.GatewaySpecAddress{ + { + Type: ptr.To(gwapiv1.IPAddressType), + Value: "10.0.0.1", + }, + }, + }, + }, + svc: &corev1.Service{ + TypeMeta: metav1.TypeMeta{}, + ObjectMeta: metav1.ObjectMeta{}, + Spec: corev1.ServiceSpec{ + ClusterIPs: []string{"None"}, + Type: corev1.ServiceTypeClusterIP, + }, + }, + }, + wantAddresses: []gwapiv1.GatewayStatusAddress{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {