From 251d23064d90f48a13b2a063e9aaca6570c542ef Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Mon, 6 Oct 2025 22:08:03 +0000 Subject: [PATCH] xds: Store weighted_clusters as a slice instead of a map inside the Route resource --- internal/xds/resolver/xds_resolver.go | 6 +- .../tests/federation_watchers_test.go | 2 +- .../xds/xdsclient/tests/rds_watchers_test.go | 20 +-- .../xdsclient/tests/resource_update_test.go | 4 +- .../xds/xdsclient/xdsresource/type_rds.go | 4 +- .../xdsresource/unmarshal_lds_test.go | 6 +- .../xdsclient/xdsresource/unmarshal_rds.go | 7 +- .../xdsresource/unmarshal_rds_test.go | 124 +++++++++++------- 8 files changed, 104 insertions(+), 69 deletions(-) diff --git a/internal/xds/resolver/xds_resolver.go b/internal/xds/resolver/xds_resolver.go index 4ed400c3c8e7..8bb960a6567f 100644 --- a/internal/xds/resolver/xds_resolver.go +++ b/internal/xds/resolver/xds_resolver.go @@ -357,14 +357,14 @@ func (r *xdsResolver) newConfigSelector() *configSelector { ci.cfg = xdsChildConfig{ChildPolicy: balancerConfig(r.currentRouteConfig.ClusterSpecifierPlugins[rt.ClusterSpecifierPlugin])} cs.clusters[clusterName] = ci } else { - for cluster, wc := range rt.WeightedClusters { - clusterName := clusterPrefix + cluster + for _, wc := range rt.WeightedClusters { + clusterName := clusterPrefix + wc.Name clusters.Add(&routeCluster{ name: clusterName, httpFilterConfigOverride: wc.HTTPFilterConfigOverride, }, int64(wc.Weight)) ci := r.addOrGetActiveClusterInfo(clusterName) - ci.cfg = xdsChildConfig{ChildPolicy: newBalancerConfig(cdsName, cdsBalancerConfig{Cluster: cluster})} + ci.cfg = xdsChildConfig{ChildPolicy: newBalancerConfig(cdsName, cdsBalancerConfig{Cluster: wc.Name})} cs.clusters[clusterName] = ci } } diff --git a/internal/xds/xdsclient/tests/federation_watchers_test.go b/internal/xds/xdsclient/tests/federation_watchers_test.go index 1bf0dc554ca4..2e844d5046ba 100644 --- a/internal/xds/xdsclient/tests/federation_watchers_test.go +++ b/internal/xds/xdsclient/tests/federation_watchers_test.go @@ -182,7 +182,7 @@ func (s) TestFederation_RouteConfigResourceContextParamOrder(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{"cluster-resource": {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: "cluster-resource", Weight: 100}}, }, }, }, diff --git a/internal/xds/xdsclient/tests/rds_watchers_test.go b/internal/xds/xdsclient/tests/rds_watchers_test.go index 3ec333ad8a24..e71dfbd36243 100644 --- a/internal/xds/xdsclient/tests/rds_watchers_test.go +++ b/internal/xds/xdsclient/tests/rds_watchers_test.go @@ -183,7 +183,7 @@ func (s) TestRDSWatch(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsName: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsName, Weight: 100}}, }, }, }, @@ -206,7 +206,7 @@ func (s) TestRDSWatch(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsNameNewStyle: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsNameNewStyle, Weight: 100}}, }, }, }, @@ -345,7 +345,7 @@ func (s) TestRDSWatch_TwoWatchesForSameResourceName(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsName: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsName, Weight: 100}}, }, }, }, @@ -361,7 +361,7 @@ func (s) TestRDSWatch_TwoWatchesForSameResourceName(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{"new-cds-resource": {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: "new-cds-resource", Weight: 100}}, }, }, }, @@ -383,7 +383,7 @@ func (s) TestRDSWatch_TwoWatchesForSameResourceName(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsNameNewStyle: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsNameNewStyle, Weight: 100}}, }, }, }, @@ -399,7 +399,7 @@ func (s) TestRDSWatch_TwoWatchesForSameResourceName(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{"new-cds-resource": {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: "new-cds-resource", Weight: 100}}, }, }, }, @@ -597,7 +597,7 @@ func (s) TestRDSWatch_ThreeWatchesForDifferentResourceNames(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsName: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsName, Weight: 100}}, }, }, }, @@ -688,7 +688,7 @@ func (s) TestRDSWatch_ResourceCaching(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsName: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsName, Weight: 100}}, }, }, }, @@ -819,7 +819,7 @@ func (s) TestRDSWatch_ValidResponseCancelsExpiryTimerBehavior(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsName: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsName, Weight: 100}}, }, }, }, @@ -983,7 +983,7 @@ func (s) TestRDSWatch_PartialValid(t *testing.T) { { Prefix: newStringP("/"), ActionType: xdsresource.RouteActionRoute, - WeightedClusters: map[string]xdsresource.WeightedCluster{cdsName: {Weight: 100}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: cdsName, Weight: 100}}, }, }, }, diff --git a/internal/xds/xdsclient/tests/resource_update_test.go b/internal/xds/xdsclient/tests/resource_update_test.go index 90517a90841d..298b152b7713 100644 --- a/internal/xds/xdsclient/tests/resource_update_test.go +++ b/internal/xds/xdsclient/tests/resource_update_test.go @@ -510,7 +510,7 @@ func (s) TestHandleRouteConfigResponseFromManagementServer(t *testing.T) { { Domains: []string{"lds-target-name"}, Routes: []*xdsresource.Route{{Prefix: newStringP(""), - WeightedClusters: map[string]xdsresource.WeightedCluster{"cluster-name": {Weight: 1}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: "cluster-name", Weight: 1}}, ActionType: xdsresource.RouteActionRoute}}, }, }, @@ -538,7 +538,7 @@ func (s) TestHandleRouteConfigResponseFromManagementServer(t *testing.T) { { Domains: []string{"lds-target-name"}, Routes: []*xdsresource.Route{{Prefix: newStringP(""), - WeightedClusters: map[string]xdsresource.WeightedCluster{"cluster-name": {Weight: 1}}, + WeightedClusters: []xdsresource.WeightedCluster{{Name: "cluster-name", Weight: 1}}, ActionType: xdsresource.RouteActionRoute}}, }, }, diff --git a/internal/xds/xdsclient/xdsresource/type_rds.go b/internal/xds/xdsclient/xdsresource/type_rds.go index 44bc27891f1b..0cde9738d5f1 100644 --- a/internal/xds/xdsclient/xdsresource/type_rds.go +++ b/internal/xds/xdsclient/xdsresource/type_rds.go @@ -146,7 +146,7 @@ type Route struct { // Only one of the following fields (WeightedClusters or // ClusterSpecifierPlugin) will be set for a route. - WeightedClusters map[string]WeightedCluster + WeightedClusters []WeightedCluster // ClusterSpecifierPlugin is the name of the Cluster Specifier Plugin that // this Route is linked to, if specified by xDS. ClusterSpecifierPlugin string @@ -154,6 +154,8 @@ type Route struct { // WeightedCluster contains settings for an xds ActionType.WeightedCluster. type WeightedCluster struct { + // Name is the name of the cluster. + Name string // Weight is the relative weight of the cluster. It will never be zero. Weight uint32 // HTTPFilterConfigOverride contains any HTTP filter config overrides for diff --git a/internal/xds/xdsclient/xdsresource/unmarshal_lds_test.go b/internal/xds/xdsclient/xdsresource/unmarshal_lds_test.go index b652c722781f..2560365d09e2 100644 --- a/internal/xds/xdsclient/xdsresource/unmarshal_lds_test.go +++ b/internal/xds/xdsclient/xdsresource/unmarshal_lds_test.go @@ -565,7 +565,11 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { InlineRouteConfig: &RouteConfigUpdate{ VirtualHosts: []*VirtualHost{{ Domains: []string{v3LDSTarget}, - Routes: []*Route{{Prefix: newStringP("/"), WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, ActionType: RouteActionRoute}}, + Routes: []*Route{{ + Prefix: newStringP("/"), + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, + ActionType: RouteActionRoute, + }}, }}}, MaxStreamDuration: time.Second, Raw: v3LisWithInlineRoute, diff --git a/internal/xds/xdsclient/xdsresource/unmarshal_rds.go b/internal/xds/xdsclient/xdsresource/unmarshal_rds.go index beab03ebb327..479d023f40ac 100644 --- a/internal/xds/xdsclient/xdsresource/unmarshal_rds.go +++ b/internal/xds/xdsclient/xdsresource/unmarshal_rds.go @@ -300,7 +300,6 @@ func routesProtoToSlice(routes []*v3routepb.Route, csps map[string]clusterspecif switch r.GetAction().(type) { case *v3routepb.Route_Route: - route.WeightedClusters = make(map[string]WeightedCluster) action := r.GetRoute() // Hash Policies are only applicable for a Ring Hash LB. @@ -312,7 +311,7 @@ func routesProtoToSlice(routes []*v3routepb.Route, csps map[string]clusterspecif switch a := action.GetClusterSpecifier().(type) { case *v3routepb.RouteAction_Cluster: - route.WeightedClusters[a.Cluster] = WeightedCluster{Weight: 1} + route.WeightedClusters = append(route.WeightedClusters, WeightedCluster{Name: a.Cluster, Weight: 1}) case *v3routepb.RouteAction_WeightedClusters: wcs := a.WeightedClusters var totalWeight uint64 @@ -325,13 +324,13 @@ func routesProtoToSlice(routes []*v3routepb.Route, csps map[string]clusterspecif if totalWeight > math.MaxUint32 { return nil, nil, fmt.Errorf("xds: total weight of clusters exceeds MaxUint32") } - wc := WeightedCluster{Weight: w} + wc := WeightedCluster{Name: c.GetName(), Weight: w} cfgs, err := processHTTPFilterOverrides(c.GetTypedPerFilterConfig()) if err != nil { return nil, nil, fmt.Errorf("route %+v, action %+v: %v", r, a, err) } wc.HTTPFilterConfigOverride = cfgs - route.WeightedClusters[c.GetName()] = wc + route.WeightedClusters = append(route.WeightedClusters, wc) } if totalWeight == 0 { return nil, nil, fmt.Errorf("route %+v, action %+v, has no valid cluster in WeightedCluster action", r, a) diff --git a/internal/xds/xdsclient/xdsresource/unmarshal_rds_test.go b/internal/xds/xdsclient/xdsresource/unmarshal_rds_test.go index 622ef7df0881..90d80c8be6b7 100644 --- a/internal/xds/xdsclient/xdsresource/unmarshal_rds_test.go +++ b/internal/xds/xdsclient/xdsresource/unmarshal_rds_test.go @@ -140,7 +140,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{ Prefix: newStringP("/"), - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, ActionType: RouteActionRoute, }}, HTTPFilterConfigOverride: cfgs, @@ -153,7 +153,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{Prefix: newStringP("/"), CaseInsensitive: true, - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, }, @@ -204,7 +204,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{ Prefix: newStringP("/"), - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, ActionType: RouteActionRoute, RetryConfig: rrc, }}, @@ -312,7 +312,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{Prefix: newStringP("/"), CaseInsensitive: true, - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, }, @@ -356,13 +356,13 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { { Domains: []string{uninterestingDomain}, Routes: []*Route{{Prefix: newStringP(""), - WeightedClusters: map[string]WeightedCluster{uninterestingClusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: uninterestingClusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, { Domains: []string{ldsTarget}, Routes: []*Route{{Prefix: newStringP(""), - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, }, @@ -394,7 +394,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { { Domains: []string{ldsTarget}, Routes: []*Route{{Prefix: newStringP("/"), - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, }, @@ -434,10 +434,10 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{ Prefix: newStringP("/"), - WeightedClusters: map[string]WeightedCluster{ - "a": {Weight: 2}, - "b": {Weight: 3}, - "c": {Weight: 5}, + WeightedClusters: []WeightedCluster{ + {Name: "a", Weight: 2}, + {Name: "b", Weight: 3}, + {Name: "c", Weight: 5}, }, ActionType: RouteActionRoute, }}, @@ -472,7 +472,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{ Prefix: newStringP("/"), - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, MaxStreamDuration: newDurationP(time.Second), ActionType: RouteActionRoute, }}, @@ -507,7 +507,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{ Prefix: newStringP("/"), - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, MaxStreamDuration: newDurationP(time.Second), ActionType: RouteActionRoute, }}, @@ -542,7 +542,7 @@ func (s) TestRDSGenerateRDSUpdateFromRouteConfiguration(t *testing.T) { Domains: []string{ldsTarget}, Routes: []*Route{{ Prefix: newStringP("/"), - WeightedClusters: map[string]WeightedCluster{clusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: clusterName, Weight: 1}}, MaxStreamDuration: newDurationP(0), ActionType: RouteActionRoute, }}, @@ -836,13 +836,13 @@ func (s) TestUnmarshalRouteConfig(t *testing.T) { { Domains: []string{uninterestingDomain}, Routes: []*Route{{Prefix: newStringP(""), - WeightedClusters: map[string]WeightedCluster{uninterestingClusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: uninterestingClusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, { Domains: []string{ldsTarget}, Routes: []*Route{{Prefix: newStringP(""), - WeightedClusters: map[string]WeightedCluster{v3ClusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: v3ClusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, }, @@ -858,13 +858,13 @@ func (s) TestUnmarshalRouteConfig(t *testing.T) { { Domains: []string{uninterestingDomain}, Routes: []*Route{{Prefix: newStringP(""), - WeightedClusters: map[string]WeightedCluster{uninterestingClusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: uninterestingClusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, { Domains: []string{ldsTarget}, Routes: []*Route{{Prefix: newStringP(""), - WeightedClusters: map[string]WeightedCluster{v3ClusterName: {Weight: 1}}, + WeightedClusters: []WeightedCluster{{Name: v3ClusterName, Weight: 1}}, ActionType: RouteActionRoute}}, }, }, @@ -913,9 +913,12 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { goodUpdateWithFilterConfigs = func(cfgs map[string]httpfilter.FilterConfig) []*Route { // Sets per-filter config in cluster "B" and in the route. return []*Route{{ - Prefix: newStringP("/"), - CaseInsensitive: true, - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60, HTTPFilterConfigOverride: cfgs}}, + Prefix: newStringP("/"), + CaseInsensitive: true, + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60, HTTPFilterConfigOverride: cfgs}, + {Name: "A", Weight: 40}, + }, HTTPFilterConfigOverride: cfgs, ActionType: RouteActionRoute, }} @@ -953,10 +956,13 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { }}}}, }}, wantRoutes: []*Route{{ - Prefix: newStringP("/"), - CaseInsensitive: true, - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, - ActionType: RouteActionRoute, + Prefix: newStringP("/"), + CaseInsensitive: true, + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, + ActionType: RouteActionRoute, }}, }, { @@ -1001,9 +1007,12 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { PrefixMatch: newStringP("tv"), }, }, - Fraction: newUInt32P(10000), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, - ActionType: RouteActionRoute, + Fraction: newUInt32P(10000), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, + ActionType: RouteActionRoute, }}, wantErr: false, }, @@ -1046,9 +1055,12 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { RegexMatch: func() *regexp.Regexp { return regexp.MustCompile("tv") }(), }, }, - Fraction: newUInt32P(10000), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, - ActionType: RouteActionRoute, + Fraction: newUInt32P(10000), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, + ActionType: RouteActionRoute, }}, wantErr: false, }, @@ -1091,9 +1103,12 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { StringMatch: &sm, }, }, - Fraction: newUInt32P(10000), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, - ActionType: RouteActionRoute, + Fraction: newUInt32P(10000), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, + ActionType: RouteActionRoute, }}, wantErr: false, }, @@ -1125,9 +1140,12 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { // Only one route in the result, because the second one with query // parameters is ignored. wantRoutes: []*Route{{ - Prefix: newStringP("/a/"), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, - ActionType: RouteActionRoute, + Prefix: newStringP("/a/"), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, + ActionType: RouteActionRoute, }}, wantErr: false, }, @@ -1285,9 +1303,12 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { }, }, wantRoutes: []*Route{{ - Prefix: newStringP("/a/"), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, - ActionType: RouteActionRoute, + Prefix: newStringP("/a/"), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, + ActionType: RouteActionRoute, }}, wantErr: false, }, @@ -1310,9 +1331,12 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { }, }, wantRoutes: []*Route{{ - Prefix: newStringP("/a/"), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 20}, "B": {Weight: 30}}, - ActionType: RouteActionRoute, + Prefix: newStringP("/a/"), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 30}, + {Name: "A", Weight: 20}, + }, + ActionType: RouteActionRoute, }}, wantErr: false, }, @@ -1362,8 +1386,11 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { PrefixMatch: newStringP("tv"), }, }, - Fraction: newUInt32P(10000), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, + Fraction: newUInt32P(10000), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, HashPolicies: []*HashPolicy{ {HashPolicyType: HashPolicyTypeChannelID}, }, @@ -1419,8 +1446,11 @@ func (s) TestRoutesProtoToSlice(t *testing.T) { PrefixMatch: newStringP("tv"), }, }, - Fraction: newUInt32P(10000), - WeightedClusters: map[string]WeightedCluster{"A": {Weight: 40}, "B": {Weight: 60}}, + Fraction: newUInt32P(10000), + WeightedClusters: []WeightedCluster{ + {Name: "B", Weight: 60}, + {Name: "A", Weight: 40}, + }, HashPolicies: []*HashPolicy{ {HashPolicyType: HashPolicyTypeHeader, HeaderName: ":path"},