Add sort-backends command line option
This commit is contained in:
parent
7c749ede0a
commit
8c3bb17f56
2 changed files with 17 additions and 4 deletions
|
@ -146,6 +146,7 @@ type Configuration struct {
|
||||||
UpdateStatus bool
|
UpdateStatus bool
|
||||||
ElectionID string
|
ElectionID string
|
||||||
UpdateStatusOnShutdown bool
|
UpdateStatusOnShutdown bool
|
||||||
|
SortBackends bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// newIngressController creates an Ingress controller
|
// newIngressController creates an Ingress controller
|
||||||
|
@ -737,6 +738,9 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
|
||||||
}
|
}
|
||||||
aUpstreams = append(aUpstreams, value)
|
aUpstreams = append(aUpstreams, value)
|
||||||
}
|
}
|
||||||
|
if ic.cfg.SortBackends {
|
||||||
|
sort.Sort(ingress.BackendByNameServers(aUpstreams))
|
||||||
|
}
|
||||||
|
|
||||||
aServers := make([]*ingress.Server, 0, len(servers))
|
aServers := make([]*ingress.Server, 0, len(servers))
|
||||||
for _, value := range servers {
|
for _, value := range servers {
|
||||||
|
@ -886,16 +890,21 @@ func (ic *GenericController) serviceEndpoints(svcKey, backendPort string,
|
||||||
glog.Warningf("service %v does not have any active endpoints", svcKey)
|
glog.Warningf("service %v does not have any active endpoints", svcKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ic.cfg.SortBackends {
|
||||||
|
sort.Sort(ingress.EndpointByAddrPort(endps))
|
||||||
|
}
|
||||||
upstreams = append(upstreams, endps...)
|
upstreams = append(upstreams, endps...)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !ic.cfg.SortBackends {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
for i := range upstreams {
|
for i := range upstreams {
|
||||||
j := rand.Intn(i + 1)
|
j := rand.Intn(i + 1)
|
||||||
upstreams[i], upstreams[j] = upstreams[j], upstreams[i]
|
upstreams[i], upstreams[j] = upstreams[j], upstreams[i]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return upstreams, nil
|
return upstreams, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,9 @@ func NewIngressController(backend ingress.Controller) *GenericController {
|
||||||
UpdateStatusOnShutdown = flags.Bool("update-status-on-shutdown", true, `Indicates if the
|
UpdateStatusOnShutdown = flags.Bool("update-status-on-shutdown", true, `Indicates if the
|
||||||
ingress controller should update the Ingress status IP/hostname when the controller
|
ingress controller should update the Ingress status IP/hostname when the controller
|
||||||
is being stopped. Default is true`)
|
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)
|
flags.AddGoFlagSet(flag.CommandLine)
|
||||||
|
@ -169,6 +172,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
|
||||||
Backend: backend,
|
Backend: backend,
|
||||||
ForceNamespaceIsolation: *forceIsolation,
|
ForceNamespaceIsolation: *forceIsolation,
|
||||||
UpdateStatusOnShutdown: *UpdateStatusOnShutdown,
|
UpdateStatusOnShutdown: *UpdateStatusOnShutdown,
|
||||||
|
SortBackends: *SortBackends,
|
||||||
}
|
}
|
||||||
|
|
||||||
ic := newIngressController(config)
|
ic := newIngressController(config)
|
||||||
|
|
Loading…
Reference in a new issue