From 10baf874216d1d4ae03e056aa3a5924918966c0c Mon Sep 17 00:00:00 2001 From: Ganesh S Date: Thu, 11 Jan 2024 12:51:07 +0530 Subject: [PATCH] Sort peer list in expander (#20167) --- .../expander/expander_ce/expander.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/multicluster/internal/controllers/exportedservices/expander/expander_ce/expander.go b/internal/multicluster/internal/controllers/exportedservices/expander/expander_ce/expander.go index 14a2caf624..23e4d6a6ed 100644 --- a/internal/multicluster/internal/controllers/exportedservices/expander/expander_ce/expander.go +++ b/internal/multicluster/internal/controllers/exportedservices/expander/expander_ce/expander.go @@ -5,6 +5,7 @@ package expander_ce import ( "context" + "sort" "github.com/hashicorp/consul/internal/controller" 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 { switch c.ConsumerTenancy.(type) { case *pbmulticluster.ExportedServicesConsumer_Peer: - _, ok := peersMap[c.GetPeer()] - if !ok { - peers = append(peers, c.GetPeer()) - peersMap[c.GetPeer()] = struct{}{} - } + peersMap[c.GetPeer()] = struct{}{} default: panic("unexpected consumer tenancy type") } } + + for peer := range peersMap { + peers = append(peers, peer) + } + sort.Strings(peers) + return &expanderTypes.ExpandedConsumers{ Peers: peers, }, nil