mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 03:38:15 +00:00
Userspace Proxy: allow check for endpoints on svc
This commit adds a method to the `LoadBalancer` interface in the userspace proxy which allows consumers of the `LoadBalancer` to check if it thinks a given service has endpoints available.
This commit is contained in:
@@ -31,4 +31,5 @@ type LoadBalancer interface {
|
|||||||
NewService(service proxy.ServicePortName, sessionAffinityType api.ServiceAffinity, stickyMaxAgeMinutes int) error
|
NewService(service proxy.ServicePortName, sessionAffinityType api.ServiceAffinity, stickyMaxAgeMinutes int) error
|
||||||
DeleteService(service proxy.ServicePortName)
|
DeleteService(service proxy.ServicePortName)
|
||||||
CleanupStaleStickySessions(service proxy.ServicePortName)
|
CleanupStaleStickySessions(service proxy.ServicePortName)
|
||||||
|
ServiceHasEndpoints(service proxy.ServicePortName) bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,16 @@ func isSessionAffinity(affinity *affinityPolicy) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceHasEndpoints checks whether a service entry has endpoints.
|
||||||
|
func (lb *LoadBalancerRR) ServiceHasEndpoints(svcPort proxy.ServicePortName) bool {
|
||||||
|
lb.lock.Lock()
|
||||||
|
defer lb.lock.Unlock()
|
||||||
|
state, exists := lb.services[svcPort]
|
||||||
|
// TODO: while nothing ever assigns nil to the map, *some* of the code using the map
|
||||||
|
// checks for it. The code should all follow the same convention.
|
||||||
|
return exists && state != nil && len(state.endpoints) > 0
|
||||||
|
}
|
||||||
|
|
||||||
// NextEndpoint returns a service endpoint.
|
// NextEndpoint returns a service endpoint.
|
||||||
// The service endpoint is chosen using the round-robin algorithm.
|
// The service endpoint is chosen using the round-robin algorithm.
|
||||||
func (lb *LoadBalancerRR) NextEndpoint(svcPort proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error) {
|
func (lb *LoadBalancerRR) NextEndpoint(svcPort proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user