Skip to content
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

Add sort-backends command line option #977

Merged
merged 1 commit into from
Jul 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions core/pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type Configuration struct {
UpdateStatus bool
ElectionID string
UpdateStatusOnShutdown bool
SortBackends bool
}

// newIngressController creates an Ingress controller
Expand Down Expand Up @@ -737,6 +738,9 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
}
aUpstreams = append(aUpstreams, value)
}
if ic.cfg.SortBackends {
sort.Sort(ingress.BackendByNameServers(aUpstreams))
}

aServers := make([]*ingress.Server, 0, len(servers))
for _, value := range servers {
Expand Down Expand Up @@ -886,15 +890,20 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string,
glog.Warningf("service %v does not have any active endpoints", svcKey)
}

if ic.cfg.SortBackends {
sort.Sort(ingress.EndpointByAddrPort(endps))
}
upstreams = append(upstreams, endps...)
break
}
}

rand.Seed(time.Now().UnixNano())
for i := range upstreams {
j := rand.Intn(i + 1)
upstreams[i], upstreams[j] = upstreams[j], upstreams[i]
if !ic.cfg.SortBackends {
rand.Seed(time.Now().UnixNano())
for i := range upstreams {
j := rand.Intn(i + 1)
upstreams[i], upstreams[j] = upstreams[j], upstreams[i]
}
}

return upstreams, nil
Expand Down
4 changes: 4 additions & 0 deletions core/pkg/ingress/controller/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func NewIngressController(backend ingress.Controller) *GenericController {
UpdateStatusOnShutdown = flags.Bool("update-status-on-shutdown", true, `Indicates if the
ingress controller should update the Ingress status IP/hostname when the controller
is being stopped. Default is true`)

SortBackends = flags.Bool("sort-backends", false,
`Defines if backends and it's endpoints should be sorted`)
)

flags.AddGoFlagSet(flag.CommandLine)
Expand Down Expand Up @@ -169,6 +172,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
Backend: backend,
ForceNamespaceIsolation: *forceIsolation,
UpdateStatusOnShutdown: *UpdateStatusOnShutdown,
SortBackends: *SortBackends,
}

ic := newIngressController(config)
Expand Down