diff --git a/pkg/apis/core/v1/defaults.go b/pkg/apis/core/v1/defaults.go index 5c5a95c61c3..5e8ef589b28 100644 --- a/pkg/apis/core/v1/defaults.go +++ b/pkg/apis/core/v1/defaults.go @@ -169,10 +169,10 @@ func SetDefaults_Service(obj *v1.Service) { if utilfeature.DefaultFeatureGate.Enabled(features.LoadBalancerIPMode) && obj.Spec.Type == v1.ServiceTypeLoadBalancer { + ipMode := v1.LoadBalancerIPModeVIP for _, ing := range obj.Status.LoadBalancer.Ingress { if ing.IPMode == nil { - ipMode := v1.LoadBalancerIPModeVIP ing.IPMode = &ipMode } } diff --git a/pkg/proxy/ipvs/proxier_test.go b/pkg/proxy/ipvs/proxier_test.go index 5531189b5be..acfce215ef5 100644 --- a/pkg/proxy/ipvs/proxier_test.go +++ b/pkg/proxy/ipvs/proxier_test.go @@ -4404,7 +4404,7 @@ func TestLoadBalancerIngressRouteTypeProxy(t *testing.T) { t.Errorf("Failed to get ipvs services, err: %v", err) } if len(services) != testCase.expectedServices { - t.Errorf("Expect %d ipvs services, got %d", testCase.expectedServices, len(services)) + t.Errorf("Expected %d ipvs services, got %d", testCase.expectedServices, len(services)) } } } diff --git a/pkg/proxy/service.go b/pkg/proxy/service.go index 1614c2a1cf1..4557c283760 100644 --- a/pkg/proxy/service.go +++ b/pkg/proxy/service.go @@ -166,16 +166,17 @@ func (sct *ServiceChangeTracker) newBaseServiceInfo(port *v1.ServicePort, servic // Obtain Load Balancer Ingress IPs var allIncorrectIPs []string for _, ing := range service.Status.LoadBalancer.Ingress { + // []string{ing.IP} have a len of 1, so len(correctIPs) + len(incorrectIPs) == 1 correctIPs, incorrectIPs := utilproxy.FilterIncorrectIPVersion([]string{ing.IP}, sct.ipFamily) // len is either 1 or 0 if len(correctIPs) == 1 { - // Update the LoadBalancerStatus with the filtered IPs + // Update the LoadBalancerStatus with the filtered IP info.loadBalancerStatus.Ingress = append(info.loadBalancerStatus.Ingress, ing) continue } - // here len(incorrectIPs) == 1 + // here len(incorrectIPs) == 1 since len(correctIPs) == 0 allIncorrectIPs = append(allIncorrectIPs, incorrectIPs[0]) } diff --git a/pkg/registry/core/service/strategy.go b/pkg/registry/core/service/strategy.go index f0aa548c813..e3137430d52 100644 --- a/pkg/registry/core/service/strategy.go +++ b/pkg/registry/core/service/strategy.go @@ -208,7 +208,7 @@ func topologyKeysInUse(svc *api.Service) bool { return len(svc.Spec.TopologyKeys) > 0 } -// returns true is svc.Status.LoadBalancer.Ingress[].IPMode fields are in use +// returns true when the LoadBalancer Ingress IPMode fields are in use. func loadbalancerIPModeInUse(svc *api.Service) bool { if svc == nil { return false