Skip to content

Commit

Permalink
Improve sorting of internal state
Browse files Browse the repository at this point in the history
Configuration change is mostly performed on diff'ing old and new internal state, because of that all internal slices should be sorted.

This change improves two scenarios:

* Order of ingress with the same creation timestamp wasn't idempotent, added a fallback to namespace/name
* Users of a userlist wasn't sorted
  • Loading branch information
jcmoraisjr committed Oct 26, 2019
1 parent aee678a commit 5ed945e
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 5ed945e

Please sign in to comment.