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.)
This commit is contained in:
		| @@ -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{ | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Dan Winship
					Dan Winship