Merge pull request #76165 from JacobTanenbaum/minor-cleanups
Minor cleanups in pkg/proxy/endpoints.go
This commit is contained in:
@@ -201,18 +201,18 @@ type UpdateEndpointMapResult struct {
|
||||
}
|
||||
|
||||
// UpdateEndpointsMap updates endpointsMap base on the given changes.
|
||||
func UpdateEndpointsMap(endpointsMap EndpointsMap, changes *EndpointChangeTracker) (result UpdateEndpointMapResult) {
|
||||
func (em EndpointsMap) Update(changes *EndpointChangeTracker) (result UpdateEndpointMapResult) {
|
||||
result.StaleEndpoints = make([]ServiceEndpoint, 0)
|
||||
result.StaleServiceNames = make([]ServicePortName, 0)
|
||||
result.LastChangeTriggerTimes = make([]time.Time, 0)
|
||||
|
||||
endpointsMap.apply(
|
||||
em.apply(
|
||||
changes, &result.StaleEndpoints, &result.StaleServiceNames, &result.LastChangeTriggerTimes)
|
||||
|
||||
// TODO: If this will appear to be computationally expensive, consider
|
||||
// computing this incrementally similarly to endpointsMap.
|
||||
result.HCEndpointsLocalIPSize = make(map[types.NamespacedName]int)
|
||||
localIPs := GetLocalEndpointIPs(endpointsMap)
|
||||
localIPs := em.getLocalEndpointIPs()
|
||||
for nsn, ips := range localIPs {
|
||||
result.HCEndpointsLocalIPSize[nsn] = len(ips)
|
||||
}
|
||||
@@ -294,8 +294,8 @@ func (em EndpointsMap) apply(changes *EndpointChangeTracker, staleEndpoints *[]S
|
||||
changes.lock.Lock()
|
||||
defer changes.lock.Unlock()
|
||||
for _, change := range changes.items {
|
||||
em.Unmerge(change.previous)
|
||||
em.Merge(change.current)
|
||||
em.unmerge(change.previous)
|
||||
em.merge(change.current)
|
||||
detectStaleConnections(change.previous, change.current, staleEndpoints, staleServiceNames)
|
||||
}
|
||||
changes.items = make(map[types.NamespacedName]*endpointsChange)
|
||||
@@ -307,23 +307,23 @@ func (em EndpointsMap) apply(changes *EndpointChangeTracker, staleEndpoints *[]S
|
||||
}
|
||||
|
||||
// Merge ensures that the current EndpointsMap contains all <service, endpoints> pairs from the EndpointsMap passed in.
|
||||
func (em EndpointsMap) Merge(other EndpointsMap) {
|
||||
func (em EndpointsMap) merge(other EndpointsMap) {
|
||||
for svcPortName := range other {
|
||||
em[svcPortName] = other[svcPortName]
|
||||
}
|
||||
}
|
||||
|
||||
// Unmerge removes the <service, endpoints> pairs from the current EndpointsMap which are contained in the EndpointsMap passed in.
|
||||
func (em EndpointsMap) Unmerge(other EndpointsMap) {
|
||||
func (em EndpointsMap) unmerge(other EndpointsMap) {
|
||||
for svcPortName := range other {
|
||||
delete(em, svcPortName)
|
||||
}
|
||||
}
|
||||
|
||||
// GetLocalEndpointIPs returns endpoints IPs if given endpoint is local - local means the endpoint is running in same host as kube-proxy.
|
||||
func GetLocalEndpointIPs(endpointsMap EndpointsMap) map[types.NamespacedName]sets.String {
|
||||
func (em EndpointsMap) getLocalEndpointIPs() map[types.NamespacedName]sets.String {
|
||||
localIPs := make(map[types.NamespacedName]sets.String)
|
||||
for svcPortName, epList := range endpointsMap {
|
||||
for svcPortName, epList := range em {
|
||||
for _, ep := range epList {
|
||||
if ep.GetIsLocal() {
|
||||
nsn := svcPortName.NamespacedName
|
||||
|
||||
Reference in New Issue
Block a user