Skip to content

Commit

Permalink
Merge pull request #423 from jcmoraisjr/jm-sort
Browse files Browse the repository at this point in the history
Improve sorting of internal state
  • Loading branch information
jcmoraisjr authored Oct 26, 2019
2 parents 77687d2 + 5ed945e commit c233335
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,13 @@ func (hc *HAProxyController) SyncIngress(item interface{}) error {
ingress = append(ingress, ing)
}
}
sort.SliceStable(ingress, func(i, j int) bool {
return ingress[i].CreationTimestamp.Before(&ingress[j].CreationTimestamp)
sort.Slice(ingress, func(i, j int) bool {
i1 := ingress[i]
i2 := ingress[j]
if i1.CreationTimestamp != i2.CreationTimestamp {
return i1.CreationTimestamp.Before(&i2.CreationTimestamp)
}
return i1.Namespace+"/"+i1.Name < i2.Namespace+"/"+i2.Name
})
var globalConfig map[string]string
if hc.configMap != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/haproxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ func (c *config) AddUserlist(name string, users []hatypes.User) *hatypes.Userlis
Name: name,
Users: users,
}
sort.Slice(users, func(i, j int) bool {
return users[i].Name < users[j].Name
})
c.userlists = append(c.userlists, userlist)
sort.Slice(c.userlists, func(i, j int) bool {
return c.userlists[i].Name < c.userlists[j].Name
Expand Down

0 comments on commit c233335

Please sign in to comment.