Skip to content

Commit

Permalink
review: sort tags
Browse files Browse the repository at this point in the history
  • Loading branch information
rtribotte committed Aug 1, 2022
1 parent c164acc commit ef66aad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion pkg/provider/consulcatalog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"hash/fnv"
"net"
"sort"
"strings"

"github.com/hashicorp/consul/api"
Expand Down Expand Up @@ -299,7 +300,12 @@ func getName(i itemData) string {
return provider.Normalize(i.Name)
}

tags := make([]string, len(i.Tags))
copy(tags, i.Tags)

sort.Strings(tags)

hasher := fnv.New64()
hasher.Write([]byte(strings.Join(i.Tags, ",")))
hasher.Write([]byte(strings.Join(tags, ",")))
return provider.Normalize(fmt.Sprintf("%s-%d", i.Name, hasher.Sum64()))
}
2 changes: 0 additions & 2 deletions pkg/provider/consulcatalog/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package consulcatalog
import (
"context"
"fmt"
"sort"
"testing"

"github.com/hashicorp/consul/api"
Expand Down Expand Up @@ -2888,7 +2887,6 @@ func Test_buildConfiguration(t *testing.T) {
for k, v := range test.items[i].Labels {
tags = append(tags, fmt.Sprintf("%s=%s", k, v))
}
sort.Strings(tags)
test.items[i].Tags = tags
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/provider/nomad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"hash/fnv"
"net"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -273,7 +274,12 @@ func getName(i item) string {
return provider.Normalize(i.Name)
}

tags := make([]string, len(i.Tags))
copy(tags, i.Tags)

sort.Strings(tags)

hasher := fnv.New64()
hasher.Write([]byte(strings.Join(i.Tags, ",")))
hasher.Write([]byte(strings.Join(tags, ",")))
return provider.Normalize(fmt.Sprintf("%s-%d", i.Name, hasher.Sum64()))
}

0 comments on commit ef66aad

Please sign in to comment.