Sort peer list in expander (#20167)

This commit is contained in:
Ganesh S 2024-01-11 12:51:07 +05:30 committed by GitHub
parent 3fa4a21edd
commit 10baf87421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -5,6 +5,7 @@ package expander_ce
import ( import (
"context" "context"
"sort"
"github.com/hashicorp/consul/internal/controller" "github.com/hashicorp/consul/internal/controller"
expanderTypes "github.com/hashicorp/consul/internal/multicluster/internal/controllers/exportedservices/expander/types" expanderTypes "github.com/hashicorp/consul/internal/multicluster/internal/controllers/exportedservices/expander/types"
@ -28,15 +29,17 @@ func (sg *SamenessGroupExpander) Expand(consumers []*pbmulticluster.ExportedServ
for _, c := range consumers { for _, c := range consumers {
switch c.ConsumerTenancy.(type) { switch c.ConsumerTenancy.(type) {
case *pbmulticluster.ExportedServicesConsumer_Peer: case *pbmulticluster.ExportedServicesConsumer_Peer:
_, ok := peersMap[c.GetPeer()]
if !ok {
peers = append(peers, c.GetPeer())
peersMap[c.GetPeer()] = struct{}{} peersMap[c.GetPeer()] = struct{}{}
}
default: default:
panic("unexpected consumer tenancy type") panic("unexpected consumer tenancy type")
} }
} }
for peer := range peersMap {
peers = append(peers, peer)
}
sort.Strings(peers)
return &expanderTypes.ExpandedConsumers{ return &expanderTypes.ExpandedConsumers{
Peers: peers, Peers: peers,
}, nil }, nil