-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Randomize endpoints function for the router template : bz1447115 #14008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"math/rand" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
@@ -310,6 +311,21 @@ func genCertificateHostName(hostname string, wildcard bool) string { | |
return hostname | ||
} | ||
|
||
// Returns the list of endpoints for the given route's service | ||
// action argument further processes the list e.g. shuffle | ||
// The default action is in-order traversal of internal data structure that stores | ||
// the endpoints (does not change the return order if the data structure did not mutate) | ||
func processEndpointsForAlias(alias ServiceAliasConfig, svc ServiceUnit, action string) []Endpoint { | ||
endpoints := endpointsForAlias(alias, svc) | ||
if strings.ToLower(action) == "shuffle" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason for "shuffle" over "random" or something like that? Also are there docs somewhere that describe how you use ROUTER_BACKEND_PROCESS_ENDPOINTS, or is that just a normal pod definition environment variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a normal end var to be defined in the deployment config. No docs yet. It's likely an experiment right now. Both random and shuffle are probably fine. I felt shuffle leaves less chance of misinterpretation. |
||
for i := len(endpoints) - 1; i >= 0; i-- { | ||
rIndex := rand.Intn(i + 1) | ||
endpoints[i], endpoints[rIndex] = endpoints[rIndex], endpoints[i] | ||
} | ||
} | ||
return endpoints | ||
} | ||
|
||
func endpointsForAlias(alias ServiceAliasConfig, svc ServiceUnit) []Endpoint { | ||
if len(alias.PreferPort) == 0 { | ||
return svc.EndpointTable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document what the default behavior is please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done