mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 05:46:16 +00:00
Rename cache's endpointSliceInfo/endpointInfo to endpointSliceData/endpointData
EndpointSliceCache was using the name "endpointInfo" to refer to two different data types (most egregiously in addEndpoints(), which had a variable named `endpoint` of type `*endpointInfo` and a variable named `endpointInfo` of type `Endpoint`). Continue using "endpointInfo" in places that refer to proxy.Endpoint / BaseEndpointInfo, since that's consistent with other code, but rename the local "cache of the Endpoints field of an EndpointSlice" type from "endpointInfo" to "endpointData". Likewise, rename endpointSliceInfo to endpointSliceData, for consistency.
This commit is contained in:
parent
764cb0457f
commit
a8a12be3d3
@ -1745,6 +1745,6 @@ func initializeCache(endpointSliceCache *EndpointSliceCache, endpointSlices []*d
|
|||||||
|
|
||||||
for _, tracker := range endpointSliceCache.trackerByServiceMap {
|
for _, tracker := range endpointSliceCache.trackerByServiceMap {
|
||||||
tracker.applied = tracker.pending
|
tracker.applied = tracker.pending
|
||||||
tracker.pending = endpointSliceInfoByName{}
|
tracker.pending = endpointSliceDataByName{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,26 +58,26 @@ type EndpointSliceCache struct {
|
|||||||
// by a proxier along with any pending EndpointSlices that have been updated
|
// by a proxier along with any pending EndpointSlices that have been updated
|
||||||
// in this cache but not yet applied by a proxier.
|
// in this cache but not yet applied by a proxier.
|
||||||
type endpointSliceTracker struct {
|
type endpointSliceTracker struct {
|
||||||
applied endpointSliceInfoByName
|
applied endpointSliceDataByName
|
||||||
pending endpointSliceInfoByName
|
pending endpointSliceDataByName
|
||||||
}
|
}
|
||||||
|
|
||||||
// endpointSliceInfoByName groups endpointSliceInfo by the names of the
|
// endpointSliceDataByName groups endpointSliceData by the names of the
|
||||||
// corresponding EndpointSlices.
|
// corresponding EndpointSlices.
|
||||||
type endpointSliceInfoByName map[string]*endpointSliceInfo
|
type endpointSliceDataByName map[string]*endpointSliceData
|
||||||
|
|
||||||
// endpointSliceInfo contains just the attributes kube-proxy cares about.
|
// endpointSliceData contains just the attributes kube-proxy cares about.
|
||||||
// Used for caching. Intentionally small to limit memory util.
|
// Used for caching. Intentionally small to limit memory util.
|
||||||
type endpointSliceInfo struct {
|
type endpointSliceData struct {
|
||||||
Ports []discovery.EndpointPort
|
Ports []discovery.EndpointPort
|
||||||
Endpoints []*endpointInfo
|
Endpoints []*endpointData
|
||||||
Remove bool
|
Remove bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// endpointInfo contains just the attributes kube-proxy cares about.
|
// endpointData contains just the attributes kube-proxy cares about.
|
||||||
// Used for caching. Intentionally small to limit memory util.
|
// Used for caching. Intentionally small to limit memory util.
|
||||||
// Addresses, NodeName, and Zone are copied from EndpointSlice Endpoints.
|
// Addresses, NodeName, and Zone are copied from EndpointSlice Endpoints.
|
||||||
type endpointInfo struct {
|
type endpointData struct {
|
||||||
Addresses []string
|
Addresses []string
|
||||||
NodeName *string
|
NodeName *string
|
||||||
Zone *string
|
Zone *string
|
||||||
@ -105,26 +105,26 @@ func NewEndpointSliceCache(hostname string, ipFamily v1.IPFamily, recorder event
|
|||||||
// newEndpointSliceTracker initializes an endpointSliceTracker.
|
// newEndpointSliceTracker initializes an endpointSliceTracker.
|
||||||
func newEndpointSliceTracker() *endpointSliceTracker {
|
func newEndpointSliceTracker() *endpointSliceTracker {
|
||||||
return &endpointSliceTracker{
|
return &endpointSliceTracker{
|
||||||
applied: endpointSliceInfoByName{},
|
applied: endpointSliceDataByName{},
|
||||||
pending: endpointSliceInfoByName{},
|
pending: endpointSliceDataByName{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// newEndpointSliceInfo generates endpointSliceInfo from an EndpointSlice.
|
// newEndpointSliceData generates endpointSliceData from an EndpointSlice.
|
||||||
func newEndpointSliceInfo(endpointSlice *discovery.EndpointSlice, remove bool) *endpointSliceInfo {
|
func newEndpointSliceData(endpointSlice *discovery.EndpointSlice, remove bool) *endpointSliceData {
|
||||||
esInfo := &endpointSliceInfo{
|
esData := &endpointSliceData{
|
||||||
Ports: make([]discovery.EndpointPort, len(endpointSlice.Ports)),
|
Ports: make([]discovery.EndpointPort, len(endpointSlice.Ports)),
|
||||||
Endpoints: []*endpointInfo{},
|
Endpoints: []*endpointData{},
|
||||||
Remove: remove,
|
Remove: remove,
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy here to avoid mutating shared EndpointSlice object.
|
// copy here to avoid mutating shared EndpointSlice object.
|
||||||
copy(esInfo.Ports, endpointSlice.Ports)
|
copy(esData.Ports, endpointSlice.Ports)
|
||||||
sort.Sort(byPort(esInfo.Ports))
|
sort.Sort(byPort(esData.Ports))
|
||||||
|
|
||||||
if !remove {
|
if !remove {
|
||||||
for _, endpoint := range endpointSlice.Endpoints {
|
for _, endpoint := range endpointSlice.Endpoints {
|
||||||
epInfo := &endpointInfo{
|
epData := &endpointData{
|
||||||
Addresses: endpoint.Addresses,
|
Addresses: endpoint.Addresses,
|
||||||
Zone: endpoint.Zone,
|
Zone: endpoint.Zone,
|
||||||
NodeName: endpoint.NodeName,
|
NodeName: endpoint.NodeName,
|
||||||
@ -137,20 +137,20 @@ func newEndpointSliceInfo(endpointSlice *discovery.EndpointSlice, remove bool) *
|
|||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.TopologyAwareHints) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.TopologyAwareHints) {
|
||||||
if endpoint.Hints != nil && len(endpoint.Hints.ForZones) > 0 {
|
if endpoint.Hints != nil && len(endpoint.Hints.ForZones) > 0 {
|
||||||
epInfo.ZoneHints = sets.New[string]()
|
epData.ZoneHints = sets.New[string]()
|
||||||
for _, zone := range endpoint.Hints.ForZones {
|
for _, zone := range endpoint.Hints.ForZones {
|
||||||
epInfo.ZoneHints.Insert(zone.Name)
|
epData.ZoneHints.Insert(zone.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esInfo.Endpoints = append(esInfo.Endpoints, epInfo)
|
esData.Endpoints = append(esData.Endpoints, epData)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(byAddress(esInfo.Endpoints))
|
sort.Sort(byAddress(esData.Endpoints))
|
||||||
}
|
}
|
||||||
|
|
||||||
return esInfo
|
return esData
|
||||||
}
|
}
|
||||||
|
|
||||||
// standardEndpointInfo is the default makeEndpointFunc.
|
// standardEndpointInfo is the default makeEndpointFunc.
|
||||||
@ -166,7 +166,7 @@ func (cache *EndpointSliceCache) updatePending(endpointSlice *discovery.Endpoint
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
esInfo := newEndpointSliceInfo(endpointSlice, remove)
|
esData := newEndpointSliceData(endpointSlice, remove)
|
||||||
|
|
||||||
cache.lock.Lock()
|
cache.lock.Lock()
|
||||||
defer cache.lock.Unlock()
|
defer cache.lock.Unlock()
|
||||||
@ -175,10 +175,10 @@ func (cache *EndpointSliceCache) updatePending(endpointSlice *discovery.Endpoint
|
|||||||
cache.trackerByServiceMap[serviceKey] = newEndpointSliceTracker()
|
cache.trackerByServiceMap[serviceKey] = newEndpointSliceTracker()
|
||||||
}
|
}
|
||||||
|
|
||||||
changed := cache.esInfoChanged(serviceKey, sliceKey, esInfo)
|
changed := cache.esDataChanged(serviceKey, sliceKey, esData)
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
cache.trackerByServiceMap[serviceKey].pending[sliceKey] = esInfo
|
cache.trackerByServiceMap[serviceKey].pending[sliceKey] = esData
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed
|
return changed
|
||||||
@ -201,11 +201,11 @@ func (cache *EndpointSliceCache) checkoutChanges() map[types.NamespacedName]*end
|
|||||||
|
|
||||||
change.previous = cache.getEndpointsMap(serviceNN, esTracker.applied)
|
change.previous = cache.getEndpointsMap(serviceNN, esTracker.applied)
|
||||||
|
|
||||||
for name, sliceInfo := range esTracker.pending {
|
for name, sliceData := range esTracker.pending {
|
||||||
if sliceInfo.Remove {
|
if sliceData.Remove {
|
||||||
delete(esTracker.applied, name)
|
delete(esTracker.applied, name)
|
||||||
} else {
|
} else {
|
||||||
esTracker.applied[name] = sliceInfo
|
esTracker.applied[name] = sliceData
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(esTracker.pending, name)
|
delete(esTracker.pending, name)
|
||||||
@ -223,17 +223,17 @@ func (cache *EndpointSliceCache) checkoutChanges() map[types.NamespacedName]*end
|
|||||||
type spToEndpointMap map[ServicePortName]map[string]Endpoint
|
type spToEndpointMap map[ServicePortName]map[string]Endpoint
|
||||||
|
|
||||||
// getEndpointsMap computes an EndpointsMap for a given set of EndpointSlices.
|
// getEndpointsMap computes an EndpointsMap for a given set of EndpointSlices.
|
||||||
func (cache *EndpointSliceCache) getEndpointsMap(serviceNN types.NamespacedName, sliceInfoByName endpointSliceInfoByName) EndpointsMap {
|
func (cache *EndpointSliceCache) getEndpointsMap(serviceNN types.NamespacedName, sliceDataByName endpointSliceDataByName) EndpointsMap {
|
||||||
endpointInfoBySP := cache.endpointInfoByServicePort(serviceNN, sliceInfoByName)
|
endpointInfoBySP := cache.endpointInfoByServicePort(serviceNN, sliceDataByName)
|
||||||
return endpointsMapFromEndpointInfo(endpointInfoBySP)
|
return endpointsMapFromEndpointInfo(endpointInfoBySP)
|
||||||
}
|
}
|
||||||
|
|
||||||
// endpointInfoByServicePort groups endpoint info by service port name and address.
|
// endpointInfoByServicePort groups endpoint info by service port name and address.
|
||||||
func (cache *EndpointSliceCache) endpointInfoByServicePort(serviceNN types.NamespacedName, sliceInfoByName endpointSliceInfoByName) spToEndpointMap {
|
func (cache *EndpointSliceCache) endpointInfoByServicePort(serviceNN types.NamespacedName, sliceDataByName endpointSliceDataByName) spToEndpointMap {
|
||||||
endpointInfoBySP := spToEndpointMap{}
|
endpointInfoBySP := spToEndpointMap{}
|
||||||
|
|
||||||
for _, sliceInfo := range sliceInfoByName {
|
for _, sliceData := range sliceDataByName {
|
||||||
for _, port := range sliceInfo.Ports {
|
for _, port := range sliceData.Ports {
|
||||||
if port.Name == nil {
|
if port.Name == nil {
|
||||||
klog.ErrorS(nil, "Ignoring port with nil name", "portName", port.Name)
|
klog.ErrorS(nil, "Ignoring port with nil name", "portName", port.Name)
|
||||||
continue
|
continue
|
||||||
@ -250,7 +250,7 @@ func (cache *EndpointSliceCache) endpointInfoByServicePort(serviceNN types.Names
|
|||||||
Protocol: *port.Protocol,
|
Protocol: *port.Protocol,
|
||||||
}
|
}
|
||||||
|
|
||||||
endpointInfoBySP[svcPortName] = cache.addEndpoints(&svcPortName, int(*port.Port), endpointInfoBySP[svcPortName], sliceInfo.Endpoints)
|
endpointInfoBySP[svcPortName] = cache.addEndpoints(&svcPortName, int(*port.Port), endpointInfoBySP[svcPortName], sliceData.Endpoints)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ func (cache *EndpointSliceCache) endpointInfoByServicePort(serviceNN types.Names
|
|||||||
}
|
}
|
||||||
|
|
||||||
// addEndpoints adds endpointInfo for each unique endpoint.
|
// addEndpoints adds endpointInfo for each unique endpoint.
|
||||||
func (cache *EndpointSliceCache) addEndpoints(svcPortName *ServicePortName, portNum int, endpointSet map[string]Endpoint, endpoints []*endpointInfo) map[string]Endpoint {
|
func (cache *EndpointSliceCache) addEndpoints(svcPortName *ServicePortName, portNum int, endpointSet map[string]Endpoint, endpoints []*endpointData) map[string]Endpoint {
|
||||||
if endpointSet == nil {
|
if endpointSet == nil {
|
||||||
endpointSet = map[string]Endpoint{}
|
endpointSet = map[string]Endpoint{}
|
||||||
}
|
}
|
||||||
@ -299,29 +299,29 @@ func (cache *EndpointSliceCache) isLocal(hostname string) bool {
|
|||||||
return len(cache.hostname) > 0 && hostname == cache.hostname
|
return len(cache.hostname) > 0 && hostname == cache.hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
// esInfoChanged returns true if the esInfo parameter should be set as a new
|
// esDataChanged returns true if the esData parameter should be set as a new
|
||||||
// pending value in the cache.
|
// pending value in the cache.
|
||||||
func (cache *EndpointSliceCache) esInfoChanged(serviceKey types.NamespacedName, sliceKey string, esInfo *endpointSliceInfo) bool {
|
func (cache *EndpointSliceCache) esDataChanged(serviceKey types.NamespacedName, sliceKey string, esData *endpointSliceData) bool {
|
||||||
if _, ok := cache.trackerByServiceMap[serviceKey]; ok {
|
if _, ok := cache.trackerByServiceMap[serviceKey]; ok {
|
||||||
appliedInfo, appliedOk := cache.trackerByServiceMap[serviceKey].applied[sliceKey]
|
appliedData, appliedOk := cache.trackerByServiceMap[serviceKey].applied[sliceKey]
|
||||||
pendingInfo, pendingOk := cache.trackerByServiceMap[serviceKey].pending[sliceKey]
|
pendingData, pendingOk := cache.trackerByServiceMap[serviceKey].pending[sliceKey]
|
||||||
|
|
||||||
// If there's already a pending value, return whether or not this would
|
// If there's already a pending value, return whether or not this would
|
||||||
// change that.
|
// change that.
|
||||||
if pendingOk {
|
if pendingOk {
|
||||||
return !reflect.DeepEqual(esInfo, pendingInfo)
|
return !reflect.DeepEqual(esData, pendingData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's already an applied value, return whether or not this would
|
// If there's already an applied value, return whether or not this would
|
||||||
// change that.
|
// change that.
|
||||||
if appliedOk {
|
if appliedOk {
|
||||||
return !reflect.DeepEqual(esInfo, appliedInfo)
|
return !reflect.DeepEqual(esData, appliedData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is marked for removal and does not exist in the cache, no changes
|
// If this is marked for removal and does not exist in the cache, no changes
|
||||||
// are necessary.
|
// are necessary.
|
||||||
if esInfo.Remove {
|
if esData.Remove {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,8 +373,8 @@ func endpointSliceCacheKeys(endpointSlice *discovery.EndpointSlice) (types.Names
|
|||||||
return types.NamespacedName{Namespace: endpointSlice.Namespace, Name: serviceName}, endpointSlice.Name, err
|
return types.NamespacedName{Namespace: endpointSlice.Namespace, Name: serviceName}, endpointSlice.Name, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// byAddress helps sort endpointInfo
|
// byAddress helps sort endpointData
|
||||||
type byAddress []*endpointInfo
|
type byAddress []*endpointData
|
||||||
|
|
||||||
func (e byAddress) Len() int {
|
func (e byAddress) Len() int {
|
||||||
return len(e)
|
return len(e)
|
||||||
|
@ -328,7 +328,7 @@ func TestEndpointInfoByServicePort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEsInfoChanged(t *testing.T) {
|
func TestEsDataChanged(t *testing.T) {
|
||||||
p80 := int32(80)
|
p80 := int32(80)
|
||||||
p443 := int32(443)
|
p443 := int32(443)
|
||||||
port80 := discovery.EndpointPort{Port: &p80, Name: ptr.To("http"), Protocol: ptr.To(v1.ProtocolTCP)}
|
port80 := discovery.EndpointPort{Port: &p80, Name: ptr.To("http"), Protocol: ptr.To(v1.ProtocolTCP)}
|
||||||
@ -454,11 +454,11 @@ func TestEsInfoChanged(t *testing.T) {
|
|||||||
t.Fatalf("Expected no error calling endpointSliceCacheKeys(): %v", err)
|
t.Fatalf("Expected no error calling endpointSliceCacheKeys(): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
esInfo := newEndpointSliceInfo(tc.updatedSlice, false)
|
esData := newEndpointSliceData(tc.updatedSlice, false)
|
||||||
changed := tc.cache.esInfoChanged(serviceKey, sliceKey, esInfo)
|
changed := tc.cache.esDataChanged(serviceKey, sliceKey, esData)
|
||||||
|
|
||||||
if tc.expectChanged != changed {
|
if tc.expectChanged != changed {
|
||||||
t.Errorf("Expected esInfoChanged() to return %t, got %t", tc.expectChanged, changed)
|
t.Errorf("Expected esDataChanged() to return %t, got %t", tc.expectChanged, changed)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmc.Check(t)
|
cmc.Check(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user