mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Merge pull request #108259 from carlosdamazio/refactor/roundrobin
pkg/proxy/userspace/roundrobin: Make `lb.services` nil check standardized
This commit is contained in:
commit
4a2391caf3
@ -96,7 +96,7 @@ func (lb *LoadBalancerRR) newServiceInternal(svcPort proxy.ServicePortName, affi
|
|||||||
ttlSeconds = int(v1.DefaultClientIPServiceAffinitySeconds) //default to 3 hours if not specified. Should 0 be unlimited instead????
|
ttlSeconds = int(v1.DefaultClientIPServiceAffinitySeconds) //default to 3 hours if not specified. Should 0 be unlimited instead????
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, exists := lb.services[svcPort]; !exists {
|
if state, exists := lb.services[svcPort]; !exists || state == nil {
|
||||||
lb.services[svcPort] = &balancerState{affinity: *newAffinityPolicy(affinityType, ttlSeconds)}
|
lb.services[svcPort] = &balancerState{affinity: *newAffinityPolicy(affinityType, ttlSeconds)}
|
||||||
klog.V(4).InfoS("LoadBalancerRR service does not exist, created", "servicePortName", svcPort)
|
klog.V(4).InfoS("LoadBalancerRR service does not exist, created", "servicePortName", svcPort)
|
||||||
} else if affinityType != "" {
|
} else if affinityType != "" {
|
||||||
@ -126,9 +126,10 @@ func (lb *LoadBalancerRR) ServiceHasEndpoints(svcPort proxy.ServicePortName) boo
|
|||||||
lb.lock.RLock()
|
lb.lock.RLock()
|
||||||
defer lb.lock.RUnlock()
|
defer lb.lock.RUnlock()
|
||||||
state, exists := lb.services[svcPort]
|
state, exists := lb.services[svcPort]
|
||||||
// TODO: while nothing ever assigns nil to the map, *some* of the code using the map
|
if !exists || state == nil {
|
||||||
// checks for it. The code should all follow the same convention.
|
return false
|
||||||
return exists && state != nil && len(state.endpoints) > 0
|
}
|
||||||
|
return len(state.endpoints) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// NextEndpoint returns a service endpoint.
|
// NextEndpoint returns a service endpoint.
|
||||||
@ -209,7 +210,7 @@ func (lb *LoadBalancerRR) removeStaleAffinity(svcPort proxy.ServicePortName, new
|
|||||||
}
|
}
|
||||||
|
|
||||||
state, exists := lb.services[svcPort]
|
state, exists := lb.services[svcPort]
|
||||||
if !exists {
|
if !exists || state == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, existingEndpoint := range state.endpoints {
|
for _, existingEndpoint := range state.endpoints {
|
||||||
@ -290,7 +291,7 @@ func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoint
|
|||||||
|
|
||||||
func (lb *LoadBalancerRR) resetService(svcPort proxy.ServicePortName) {
|
func (lb *LoadBalancerRR) resetService(svcPort proxy.ServicePortName) {
|
||||||
// If the service is still around, reset but don't delete.
|
// If the service is still around, reset but don't delete.
|
||||||
if state, ok := lb.services[svcPort]; ok {
|
if state, ok := lb.services[svcPort]; ok && state != nil {
|
||||||
if len(state.endpoints) > 0 {
|
if len(state.endpoints) > 0 {
|
||||||
klog.V(2).InfoS("LoadBalancerRR: Removing endpoints service", "servicePortName", svcPort)
|
klog.V(2).InfoS("LoadBalancerRR: Removing endpoints service", "servicePortName", svcPort)
|
||||||
state.endpoints = []string{}
|
state.endpoints = []string{}
|
||||||
@ -330,7 +331,7 @@ func (lb *LoadBalancerRR) CleanupStaleStickySessions(svcPort proxy.ServicePortNa
|
|||||||
defer lb.lock.Unlock()
|
defer lb.lock.Unlock()
|
||||||
|
|
||||||
state, exists := lb.services[svcPort]
|
state, exists := lb.services[svcPort]
|
||||||
if !exists {
|
if !exists || state == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for ip, affinity := range state.affinity.affinityMap {
|
for ip, affinity := range state.affinity.affinityMap {
|
||||||
|
Loading…
Reference in New Issue
Block a user