mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
changing UpdateEndpointsMap to Update
changing UpdateEndpointsMap to be a function of the EndpointsMap object
This commit is contained in:
parent
5201cc994c
commit
9d4693a70f
@ -197,18 +197,18 @@ type UpdateEndpointMapResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEndpointsMap updates endpointsMap base on the given changes.
|
// 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.StaleEndpoints = make([]ServiceEndpoint, 0)
|
||||||
result.StaleServiceNames = make([]ServicePortName, 0)
|
result.StaleServiceNames = make([]ServicePortName, 0)
|
||||||
result.LastChangeTriggerTimes = make([]time.Time, 0)
|
result.LastChangeTriggerTimes = make([]time.Time, 0)
|
||||||
|
|
||||||
endpointsMap.apply(
|
em.apply(
|
||||||
changes, &result.StaleEndpoints, &result.StaleServiceNames, &result.LastChangeTriggerTimes)
|
changes, &result.StaleEndpoints, &result.StaleServiceNames, &result.LastChangeTriggerTimes)
|
||||||
|
|
||||||
// TODO: If this will appear to be computationally expensive, consider
|
// TODO: If this will appear to be computationally expensive, consider
|
||||||
// computing this incrementally similarly to endpointsMap.
|
// computing this incrementally similarly to endpointsMap.
|
||||||
result.HCEndpointsLocalIPSize = make(map[types.NamespacedName]int)
|
result.HCEndpointsLocalIPSize = make(map[types.NamespacedName]int)
|
||||||
localIPs := endpointsMap.getLocalEndpointIPs()
|
localIPs := em.getLocalEndpointIPs()
|
||||||
for nsn, ips := range localIPs {
|
for nsn, ips := range localIPs {
|
||||||
result.HCEndpointsLocalIPSize[nsn] = len(ips)
|
result.HCEndpointsLocalIPSize[nsn] = len(ips)
|
||||||
}
|
}
|
||||||
|
@ -1213,7 +1213,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
|||||||
fp.addEndpoints(tc.previousEndpoints[i])
|
fp.addEndpoints(tc.previousEndpoints[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateEndpointsMap(fp.endpointsMap, fp.endpointsChanges)
|
fp.endpointsMap.Update(fp.endpointsChanges)
|
||||||
compareEndpointsMaps(t, tci, fp.endpointsMap, tc.oldEndpoints)
|
compareEndpointsMaps(t, tci, fp.endpointsMap, tc.oldEndpoints)
|
||||||
|
|
||||||
// Now let's call appropriate handlers to get to state we want to be.
|
// Now let's call appropriate handlers to get to state we want to be.
|
||||||
@ -1233,7 +1233,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
|||||||
fp.updateEndpoints(prev, curr)
|
fp.updateEndpoints(prev, curr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result := UpdateEndpointsMap(fp.endpointsMap, fp.endpointsChanges)
|
result := fp.endpointsMap.Update(fp.endpointsChanges)
|
||||||
newMap := fp.endpointsMap
|
newMap := fp.endpointsMap
|
||||||
compareEndpointsMaps(t, tci, newMap, tc.expectedResult)
|
compareEndpointsMaps(t, tci, newMap, tc.expectedResult)
|
||||||
if len(result.StaleEndpoints) != len(tc.expectedStaleEndpoints) {
|
if len(result.StaleEndpoints) != len(tc.expectedStaleEndpoints) {
|
||||||
@ -1373,7 +1373,7 @@ func TestLastChangeTriggerTime(t *testing.T) {
|
|||||||
|
|
||||||
tc.scenario(fp)
|
tc.scenario(fp)
|
||||||
|
|
||||||
result := UpdateEndpointsMap(fp.endpointsMap, fp.endpointsChanges)
|
result := fp.endpointsMap.Update(fp.endpointsChanges)
|
||||||
got := result.LastChangeTriggerTimes
|
got := result.LastChangeTriggerTimes
|
||||||
sortTimeSlice(got)
|
sortTimeSlice(got)
|
||||||
sortTimeSlice(tc.expected)
|
sortTimeSlice(tc.expected)
|
||||||
|
@ -666,7 +666,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
// even if nothing changed in the meantime. In other words, callers are
|
// even if nothing changed in the meantime. In other words, callers are
|
||||||
// responsible for detecting no-op changes and not calling this function.
|
// responsible for detecting no-op changes and not calling this function.
|
||||||
serviceUpdateResult := proxy.UpdateServiceMap(proxier.serviceMap, proxier.serviceChanges)
|
serviceUpdateResult := proxy.UpdateServiceMap(proxier.serviceMap, proxier.serviceChanges)
|
||||||
endpointUpdateResult := proxy.UpdateEndpointsMap(proxier.endpointsMap, proxier.endpointsChanges)
|
endpointUpdateResult := proxier.endpointsMap.Update(proxier.endpointsChanges)
|
||||||
|
|
||||||
staleServices := serviceUpdateResult.UDPStaleClusterIP
|
staleServices := serviceUpdateResult.UDPStaleClusterIP
|
||||||
// merge stale services gathered from updateEndpointsMap
|
// merge stale services gathered from updateEndpointsMap
|
||||||
|
@ -2185,7 +2185,7 @@ func Test_updateEndpointsMap(t *testing.T) {
|
|||||||
fp.OnEndpointsAdd(tc.previousEndpoints[i])
|
fp.OnEndpointsAdd(tc.previousEndpoints[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proxy.UpdateEndpointsMap(fp.endpointsMap, fp.endpointsChanges)
|
fp.endpointsMap.Update(fp.endpointsChanges)
|
||||||
compareEndpointsMaps(t, tci, fp.endpointsMap, tc.oldEndpoints)
|
compareEndpointsMaps(t, tci, fp.endpointsMap, tc.oldEndpoints)
|
||||||
|
|
||||||
// Now let's call appropriate handlers to get to state we want to be.
|
// Now let's call appropriate handlers to get to state we want to be.
|
||||||
@ -2205,7 +2205,7 @@ func Test_updateEndpointsMap(t *testing.T) {
|
|||||||
fp.OnEndpointsUpdate(prev, curr)
|
fp.OnEndpointsUpdate(prev, curr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result := proxy.UpdateEndpointsMap(fp.endpointsMap, fp.endpointsChanges)
|
result := fp.endpointsMap.Update(fp.endpointsChanges)
|
||||||
newMap := fp.endpointsMap
|
newMap := fp.endpointsMap
|
||||||
compareEndpointsMaps(t, tci, newMap, tc.expectedResult)
|
compareEndpointsMaps(t, tci, newMap, tc.expectedResult)
|
||||||
if len(result.StaleEndpoints) != len(tc.expectedStaleEndpoints) {
|
if len(result.StaleEndpoints) != len(tc.expectedStaleEndpoints) {
|
||||||
|
@ -753,7 +753,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
// even if nothing changed in the meantime. In other words, callers are
|
// even if nothing changed in the meantime. In other words, callers are
|
||||||
// responsible for detecting no-op changes and not calling this function.
|
// responsible for detecting no-op changes and not calling this function.
|
||||||
serviceUpdateResult := proxy.UpdateServiceMap(proxier.serviceMap, proxier.serviceChanges)
|
serviceUpdateResult := proxy.UpdateServiceMap(proxier.serviceMap, proxier.serviceChanges)
|
||||||
endpointUpdateResult := proxy.UpdateEndpointsMap(proxier.endpointsMap, proxier.endpointsChanges)
|
endpointUpdateResult := proxier.endpointsMap.Update(proxier.endpointsChanges)
|
||||||
|
|
||||||
staleServices := serviceUpdateResult.UDPStaleClusterIP
|
staleServices := serviceUpdateResult.UDPStaleClusterIP
|
||||||
// merge stale services gathered from updateEndpointsMap
|
// merge stale services gathered from updateEndpointsMap
|
||||||
|
@ -2486,7 +2486,7 @@ func Test_updateEndpointsMap(t *testing.T) {
|
|||||||
fp.OnEndpointsAdd(tc.previousEndpoints[i])
|
fp.OnEndpointsAdd(tc.previousEndpoints[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proxy.UpdateEndpointsMap(fp.endpointsMap, fp.endpointsChanges)
|
fp.endpointsMap.Update(fp.endpointsChanges)
|
||||||
compareEndpointsMaps(t, tci, fp.endpointsMap, tc.oldEndpoints)
|
compareEndpointsMaps(t, tci, fp.endpointsMap, tc.oldEndpoints)
|
||||||
|
|
||||||
// Now let's call appropriate handlers to get to state we want to be.
|
// Now let's call appropriate handlers to get to state we want to be.
|
||||||
@ -2506,7 +2506,7 @@ func Test_updateEndpointsMap(t *testing.T) {
|
|||||||
fp.OnEndpointsUpdate(prev, curr)
|
fp.OnEndpointsUpdate(prev, curr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result := proxy.UpdateEndpointsMap(fp.endpointsMap, fp.endpointsChanges)
|
result := fp.endpointsMap.Update(fp.endpointsChanges)
|
||||||
newMap := fp.endpointsMap
|
newMap := fp.endpointsMap
|
||||||
compareEndpointsMaps(t, tci, newMap, tc.expectedResult)
|
compareEndpointsMaps(t, tci, newMap, tc.expectedResult)
|
||||||
if len(result.StaleEndpoints) != len(tc.expectedStaleEndpoints) {
|
if len(result.StaleEndpoints) != len(tc.expectedStaleEndpoints) {
|
||||||
|
Loading…
Reference in New Issue
Block a user