diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index 9faabed5f82..a2b358b0068 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -1028,11 +1028,9 @@ func (proxier *Proxier) syncProxyRules() { serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds) } if err := proxier.syncService(svcNameString, serv, true); err == nil { - // check if service need skip endpoints that not in same host as kube-proxy - onlyLocal := svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP && svcInfo.OnlyNodeLocalEndpoints activeIPVSServices[serv.String()] = true activeBindAddrs[serv.Address.String()] = true - if err := proxier.syncEndpoint(svcName, onlyLocal, serv); err != nil { + if err := proxier.syncEndpoint(svcName, svcInfo.OnlyNodeLocalEndpoints, serv); err != nil { klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err) } } else { diff --git a/pkg/proxy/ipvs/proxier_test.go b/pkg/proxy/ipvs/proxier_test.go index 5c5f7492ff1..fe0da923592 100644 --- a/pkg/proxy/ipvs/proxier_test.go +++ b/pkg/proxy/ipvs/proxier_test.go @@ -1266,18 +1266,32 @@ func TestOnlyLocalLoadBalancing(t *testing.T) { ) epIP := "10.180.0.1" + epIP1 := "10.180.1.1" + thisHostname := testHostname + otherHostname := "other-hostname" + makeEndpointsMap(fp, makeTestEndpoints(svcPortName.Namespace, svcPortName.Name, func(ept *v1.Endpoints) { - ept.Subsets = []v1.EndpointSubset{{ - Addresses: []v1.EndpointAddress{{ - IP: epIP, - NodeName: nil, - }}, - Ports: []v1.EndpointPort{{ - Name: svcPortName.Port, - Port: int32(svcPort), - }}, - }} + ept.Subsets = []v1.EndpointSubset{ + { // **local** endpoint address, should be added as RS + Addresses: []v1.EndpointAddress{{ + IP: epIP, + NodeName: &thisHostname, + }}, + Ports: []v1.EndpointPort{{ + Name: svcPortName.Port, + Port: int32(svcPort), + }}}, + { // **remote** endpoint address, should not be added as RS + Addresses: []v1.EndpointAddress{{ + IP: epIP1, + NodeName: &otherHostname, + }}, + Ports: []v1.EndpointPort{{ + Name: svcPortName.Port, + Port: int32(svcPort), + }}, + }} }), )