MCPcopy Create free account
hub / github.com/zalando/skipper / Apply

Method Apply

loadbalancer/algorithm.go:200–210  ·  view source on GitHub ↗

Apply implements routing.LBAlgorithm with a consistent hash algorithm.

(ctx *routing.LBContext)

Source from the content-addressed store, hash-verified

198
199// Apply implements routing.LBAlgorithm with a consistent hash algorithm.
200func (ch *consistentHash) Apply(ctx *routing.LBContext) routing.LBEndpoint {
201 if len(ctx.LBEndpoints) == 1 {
202 return ctx.LBEndpoints[0]
203 }
204
205 // The index returned from this call is taken from hash ring which is built from data about
206 // all endpoints, including fading in, unhealthy, etc. ones. The index stored in hash ring is
207 // the index of the endpoint in the original list of endpoints.
208 choice := ch.chooseConsistentHashEndpoint(ctx)
209 return ctx.Route.LBEndpoints[choice]
210}
211
212func (ch *consistentHash) chooseConsistentHashEndpoint(ctx *routing.LBContext) int {
213 key, ok := ctx.Params[ConsistentHashKey].(string)

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected