From af9a5321b528a6f64c84ac5883a95310e8ab56b3 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sun, 2 Apr 2017 22:01:02 -0700 Subject: [PATCH] save allServices in prep for async iptables --- pkg/proxy/iptables/proxier.go | 34 +++++++++++++++--------------- pkg/proxy/iptables/proxier_test.go | 20 +++++++++--------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index fc00c52003a..16a893b3e8f 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -193,18 +193,19 @@ type proxyEndpointMap map[proxy.ServicePortName][]*endpointsInfo // Proxier is an iptables based proxy for connections between a localhost:lport // and services that provide the actual backends. type Proxier struct { - mu sync.Mutex // protects the following fields - serviceMap proxyServiceMap - endpointsMap proxyEndpointMap - portsMap map[localPort]closeable - haveReceivedServiceUpdate bool // true once we've seen an OnServiceUpdate event - // allEndpoints should never be modified by proxier - the pointers - // are shared with higher layers of kube-proxy. They are guaranteed - // to not be modified in the meantime, but also require to be not - // modified by Proxier. - // nil until we have seen an OnEndpointsUpdate event. + mu sync.Mutex // protects the following fields + serviceMap proxyServiceMap + endpointsMap proxyEndpointMap + portsMap map[localPort]closeable + // allServices and allEndpoints should never be modified by proxier - the + // pointers are shared with higher layers of kube-proxy. They are guaranteed + // to not be modified in the meantime, but also require to be not modified + // by Proxier. + // nil until we have seen an On*Update event. + allServices []*api.Service allEndpoints []*api.Endpoints - throttle flowcontrol.RateLimiter + + throttle flowcontrol.RateLimiter // These are effectively const and do not need the mutex to be held. syncPeriod time.Duration @@ -529,13 +530,12 @@ func buildServiceMap(allServices []*api.Service, oldServiceMap proxyServiceMap) // OnServiceUpdate tracks the active set of service proxies. // They will be synchronized using syncProxyRules() func (proxier *Proxier) OnServiceUpdate(allServices []*api.Service) { - start := time.Now() - defer func() { - glog.V(4).Infof("OnServiceUpdate took %v for %d services", time.Since(start), len(allServices)) - }() proxier.mu.Lock() defer proxier.mu.Unlock() - proxier.haveReceivedServiceUpdate = true + if proxier.allServices == nil { + glog.V(2).Info("Received first Services update") + } + proxier.allServices = allServices newServiceMap, hcAdd, hcDel, staleUDPServices := buildServiceMap(allServices, proxier.serviceMap) for _, hc := range hcAdd { @@ -769,7 +769,7 @@ func (proxier *Proxier) syncProxyRules() { glog.V(4).Infof("syncProxyRules took %v", time.Since(start)) }() // don't sync rules till we've received services and endpoints - if proxier.allEndpoints == nil || !proxier.haveReceivedServiceUpdate { + if proxier.allEndpoints == nil || proxier.allServices == nil { glog.V(2).Info("Not syncing iptables until Services and Endpoints have been received from master") return } diff --git a/pkg/proxy/iptables/proxier_test.go b/pkg/proxy/iptables/proxier_test.go index afcee91ee71..fff13e20a9e 100644 --- a/pkg/proxy/iptables/proxier_test.go +++ b/pkg/proxy/iptables/proxier_test.go @@ -365,16 +365,16 @@ func NewFakeProxier(ipt utiliptables.Interface) *Proxier { // TODO: Call NewProxier after refactoring out the goroutine // invocation into a Run() method. return &Proxier{ - exec: &exec.FakeExec{}, - serviceMap: make(map[proxy.ServicePortName]*serviceInfo), - iptables: ipt, - clusterCIDR: "10.0.0.0/24", - allEndpoints: []*api.Endpoints{}, - haveReceivedServiceUpdate: true, - hostname: testHostname, - portsMap: make(map[localPort]closeable), - portMapper: &fakePortOpener{[]*localPort{}}, - healthChecker: fakeHealthChecker{}, + exec: &exec.FakeExec{}, + serviceMap: make(map[proxy.ServicePortName]*serviceInfo), + iptables: ipt, + clusterCIDR: "10.0.0.0/24", + allEndpoints: []*api.Endpoints{}, + allServices: []*api.Service{}, + hostname: testHostname, + portsMap: make(map[localPort]closeable), + portMapper: &fakePortOpener{[]*localPort{}}, + healthChecker: fakeHealthChecker{}, } }