diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index 615baa8ed76..54290a367cb 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -1020,8 +1020,6 @@ func (proxier *Proxier) syncProxyRules() { allEndpoints := proxier.endpointsMap[svcName] - hasEndpoints := len(allEndpoints) > 0 - // Service Topology will not be enabled in the following cases: // 1. externalTrafficPolicy=Local (mutually exclusive with service topology). // 2. ServiceTopology is not enabled. @@ -1029,9 +1027,18 @@ func (proxier *Proxier) syncProxyRules() { // to get topology information). if !svcInfo.OnlyNodeLocalEndpoints() && utilfeature.DefaultFeatureGate.Enabled(features.ServiceTopology) && utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceProxying) { allEndpoints = proxy.FilterTopologyEndpoint(proxier.nodeLabels, svcInfo.TopologyKeys(), allEndpoints) - hasEndpoints = len(allEndpoints) > 0 } + readyEndpoints := make([]proxy.Endpoint, 0, len(allEndpoints)) + for _, endpoint := range allEndpoints { + if !endpoint.IsReady() { + continue + } + + readyEndpoints = append(readyEndpoints, endpoint) + } + hasEndpoints := len(readyEndpoints) > 0 + svcChain := svcInfo.servicePortChainName if hasEndpoints { // Create the per-service chain, retaining counters if possible. @@ -1340,7 +1347,7 @@ func (proxier *Proxier) syncProxyRules() { endpoints = endpoints[:0] endpointChains = endpointChains[:0] var endpointChain utiliptables.Chain - for _, ep := range allEndpoints { + for _, ep := range readyEndpoints { epInfo, ok := ep.(*endpointsInfo) if !ok { klog.ErrorS(err, "Failed to cast endpointsInfo", "endpointsInfo", ep.String()) diff --git a/pkg/proxy/iptables/proxier_test.go b/pkg/proxy/iptables/proxier_test.go index 1e798313cf7..e303ea99371 100644 --- a/pkg/proxy/iptables/proxier_test.go +++ b/pkg/proxy/iptables/proxier_test.go @@ -2670,6 +2670,10 @@ COMMIT Addresses: []string{"10.0.1.3"}, Conditions: discovery.EndpointConditions{Ready: utilpointer.BoolPtr(true)}, Topology: map[string]string{"kubernetes.io/hostname": "node3"}, + }, { // not ready endpoints should be ignored + Addresses: []string{"10.0.1.4"}, + Conditions: discovery.EndpointConditions{Ready: utilpointer.BoolPtr(false)}, + Topology: map[string]string{"kubernetes.io/hostname": "node4"}, }}, }