From 764cb0457f5cbd1d2cee8476c59fc1daaadcb6ce Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 20 Nov 2023 09:41:55 -0500 Subject: [PATCH] Move some code around in servicechangetracker.go/endpointschangetracker.go Put the ServiceChangeTracker and EndpointsChangeTracker definitions at the top of the files, and put the ServicePortMap and EndpointsMap definitions before their methods. (No code changes.) --- pkg/proxy/endpointschangetracker.go | 12 +++++----- pkg/proxy/endpointslicecache.go | 8 +++---- pkg/proxy/servicechangetracker.go | 34 ++++++++++++++--------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/proxy/endpointschangetracker.go b/pkg/proxy/endpointschangetracker.go index f75a65bfc2e..3347e55709a 100644 --- a/pkg/proxy/endpointschangetracker.go +++ b/pkg/proxy/endpointschangetracker.go @@ -34,12 +34,6 @@ var supportedEndpointSliceAddressTypes = sets.New[string]( string(discovery.AddressTypeIPv6), ) -type makeEndpointFunc func(info *BaseEndpointInfo, svcPortName *ServicePortName) Endpoint - -// This handler is invoked by the apply function on every change. This function should not modify the -// EndpointsMap's but just use the changes for any Proxier specific cleanup. -type processEndpointsMapChangeFunc func(oldEndpointsMap, newEndpointsMap EndpointsMap) - // EndpointsChangeTracker carries state about uncommitted changes to an arbitrary number of // Endpoints, keyed by their namespace and name. type EndpointsChangeTracker struct { @@ -59,6 +53,12 @@ type EndpointsChangeTracker struct { trackerStartTime time.Time } +type makeEndpointFunc func(info *BaseEndpointInfo, svcPortName *ServicePortName) Endpoint + +// This handler is invoked by the apply function on every change. This function should not modify the +// EndpointsMap's but just use the changes for any Proxier specific cleanup. +type processEndpointsMapChangeFunc func(oldEndpointsMap, newEndpointsMap EndpointsMap) + // NewEndpointsChangeTracker initializes an EndpointsChangeTracker func NewEndpointsChangeTracker(hostname string, makeEndpointInfo makeEndpointFunc, ipFamily v1.IPFamily, recorder events.EventRecorder, processEndpointsMapChange processEndpointsMapChangeFunc) *EndpointsChangeTracker { return &EndpointsChangeTracker{ diff --git a/pkg/proxy/endpointslicecache.go b/pkg/proxy/endpointslicecache.go index 125d625cad2..49254cdf7ba 100644 --- a/pkg/proxy/endpointslicecache.go +++ b/pkg/proxy/endpointslicecache.go @@ -88,10 +88,6 @@ type endpointInfo struct { Terminating bool } -// spToEndpointMap stores groups Endpoint objects by ServicePortName and -// endpoint string (returned by Endpoint.String()). -type spToEndpointMap map[ServicePortName]map[string]Endpoint - // NewEndpointSliceCache initializes an EndpointSliceCache. func NewEndpointSliceCache(hostname string, ipFamily v1.IPFamily, recorder events.EventRecorder, makeEndpointInfo makeEndpointFunc) *EndpointSliceCache { if makeEndpointInfo == nil { @@ -222,6 +218,10 @@ func (cache *EndpointSliceCache) checkoutChanges() map[types.NamespacedName]*end return changes } +// spToEndpointMap stores groups Endpoint objects by ServicePortName and +// endpoint string (returned by Endpoint.String()). +type spToEndpointMap map[ServicePortName]map[string]Endpoint + // getEndpointsMap computes an EndpointsMap for a given set of EndpointSlices. func (cache *EndpointSliceCache) getEndpointsMap(serviceNN types.NamespacedName, sliceInfoByName endpointSliceInfoByName) EndpointsMap { endpointInfoBySP := cache.endpointInfoByServicePort(serviceNN, sliceInfoByName) diff --git a/pkg/proxy/servicechangetracker.go b/pkg/proxy/servicechangetracker.go index 1d72719b9f3..37d22357262 100644 --- a/pkg/proxy/servicechangetracker.go +++ b/pkg/proxy/servicechangetracker.go @@ -29,20 +29,6 @@ import ( proxyutil "k8s.io/kubernetes/pkg/proxy/util" ) -type makeServicePortFunc func(*v1.ServicePort, *v1.Service, *BaseServicePortInfo) ServicePort - -// This handler is invoked by the apply function on every change. This function should not modify the -// ServicePortMap's but just use the changes for any Proxier specific cleanup. -type processServiceMapChangeFunc func(previous, current ServicePortMap) - -// serviceChange contains all changes to services that happened since proxy rules were synced. For a single object, -// changes are accumulated, i.e. previous is state from before applying the changes, -// current is state after applying all of the changes. -type serviceChange struct { - previous ServicePortMap - current ServicePortMap -} - // ServiceChangeTracker carries state about uncommitted changes to an arbitrary number of // Services, keyed by their namespace and name. type ServiceChangeTracker struct { @@ -58,6 +44,20 @@ type ServiceChangeTracker struct { recorder events.EventRecorder } +type makeServicePortFunc func(*v1.ServicePort, *v1.Service, *BaseServicePortInfo) ServicePort + +// This handler is invoked by the apply function on every change. This function should not modify the +// ServicePortMap's but just use the changes for any Proxier specific cleanup. +type processServiceMapChangeFunc func(previous, current ServicePortMap) + +// serviceChange contains all changes to services that happened since proxy rules were synced. For a single object, +// changes are accumulated, i.e. previous is state from before applying the changes, +// current is state after applying all of the changes. +type serviceChange struct { + previous ServicePortMap + current ServicePortMap +} + // NewServiceChangeTracker initializes a ServiceChangeTracker func NewServiceChangeTracker(makeServiceInfo makeServicePortFunc, ipFamily v1.IPFamily, recorder events.EventRecorder, processServiceMapChange processServiceMapChangeFunc) *ServiceChangeTracker { return &ServiceChangeTracker{ @@ -112,6 +112,9 @@ func (sct *ServiceChangeTracker) Update(previous, current *v1.Service) bool { return len(sct.items) > 0 } +// ServicePortMap maps a service to its ServicePort. +type ServicePortMap map[ServicePortName]ServicePort + // UpdateServiceMapResult is the updated results after applying service changes. type UpdateServiceMapResult struct { // UpdatedServices lists the names of all services added/updated/deleted since the @@ -138,9 +141,6 @@ func (sm ServicePortMap) HealthCheckNodePorts() map[types.NamespacedName]uint16 return ports } -// ServicePortMap maps a service to its ServicePort. -type ServicePortMap map[ServicePortName]ServicePort - // serviceToServiceMap translates a single Service object to a ServicePortMap. // // NOTE: service object should NOT be modified.