Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/xds/resolver/xds_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/xds/xdsclient/tests/federation_watchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
},
},
Expand Down
20 changes: 10 additions & 10 deletions internal/xds/xdsclient/tests/rds_watchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
},
},
Expand All @@ -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}},
},
},
},
Expand Down Expand Up @@ -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}},
},
},
},
Expand All @@ -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}},
},
},
},
Expand All @@ -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}},
},
},
},
Expand All @@ -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}},
},
},
},
Expand Down Expand Up @@ -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}},
},
},
},
Expand Down Expand Up @@ -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}},
},
},
},
Expand Down Expand Up @@ -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}},
},
},
},
Expand Down Expand Up @@ -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}},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/xds/xdsclient/tests/resource_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
},
Expand Down Expand Up @@ -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}},
},
},
Expand Down
4 changes: 3 additions & 1 deletion internal/xds/xdsclient/xdsresource/type_rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ 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
}

// 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
Expand Down
6 changes: 5 additions & 1 deletion internal/xds/xdsclient/xdsresource/unmarshal_lds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions internal/xds/xdsclient/xdsresource/unmarshal_rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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)
Expand Down
Loading
Loading