From c6990f973f5fc5b793bccc057f2034496f08e7f0 Mon Sep 17 00:00:00 2001 From: Hong Zhiguo Date: Wed, 11 Jul 2018 16:48:34 +0800 Subject: [PATCH 1/2] fix NodePort with Local policy not working --- pkg/proxy/ipvs/proxier.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index 10dd36f226f..a7bb9daafff 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -1116,7 +1116,7 @@ func (proxier *Proxier) syncProxyRules() { // There is no need to bind Node IP to dummy interface, so set parameter `bindAddr` to `false`. if err := proxier.syncService(svcNameString, serv, false); err == nil { activeIPVSServices[serv.String()] = true - if err := proxier.syncEndpoint(svcName, false, serv); err != nil { + if err := proxier.syncEndpoint(svcName, svcInfo.OnlyNodeLocalEndpoints, serv); err != nil { glog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err) } } else { From 8bb6a5fa9c280df784825e270068be85569265f6 Mon Sep 17 00:00:00 2001 From: Hong Zhiguo Date: Thu, 12 Jul 2018 11:29:23 +0800 Subject: [PATCH 2/2] update TestOnlyLocalNodePorts to make sure only add local RS --- pkg/proxy/ipvs/proxier_test.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/proxy/ipvs/proxier_test.go b/pkg/proxy/ipvs/proxier_test.go index 659bc98932a..6041668ab36 100644 --- a/pkg/proxy/ipvs/proxier_test.go +++ b/pkg/proxy/ipvs/proxier_test.go @@ -1001,18 +1001,32 @@ func TestOnlyLocalNodePorts(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 *api.Endpoints) { - ept.Subsets = []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{ - IP: epIP, - NodeName: nil, - }}, - Ports: []api.EndpointPort{{ - Name: svcPortName.Port, - Port: int32(svcPort), - }}, - }} + ept.Subsets = []api.EndpointSubset{ + { // **local** endpoint address, should be added as RS + Addresses: []api.EndpointAddress{{ + IP: epIP, + NodeName: &thisHostname, + }}, + Ports: []api.EndpointPort{{ + Name: svcPortName.Port, + Port: int32(svcPort), + }}}, + { // **remote** endpoint address, should not be added as RS + Addresses: []api.EndpointAddress{{ + IP: epIP1, + NodeName: &otherHostname, + }}, + Ports: []api.EndpointPort{{ + Name: svcPortName.Port, + Port: int32(svcPort), + }}, + }} }), )