|
|
@ -17,16 +17,14 @@ import ( |
|
|
|
"golang.org/x/exp/maps" |
|
|
|
"golang.org/x/exp/maps" |
|
|
|
"golang.org/x/exp/slices" |
|
|
|
"golang.org/x/exp/slices" |
|
|
|
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/proto" |
|
|
|
|
|
|
|
"google.golang.org/protobuf/types/known/durationpb" |
|
|
|
|
|
|
|
"google.golang.org/protobuf/types/known/wrapperspb" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/connect" |
|
|
|
"github.com/hashicorp/consul/agent/connect" |
|
|
|
"github.com/hashicorp/consul/agent/consul/discoverychain" |
|
|
|
"github.com/hashicorp/consul/agent/consul/discoverychain" |
|
|
|
"github.com/hashicorp/consul/agent/proxycfg" |
|
|
|
"github.com/hashicorp/consul/agent/proxycfg" |
|
|
|
"github.com/hashicorp/consul/agent/structs" |
|
|
|
"github.com/hashicorp/consul/agent/structs" |
|
|
|
"github.com/hashicorp/consul/agent/xds/config" |
|
|
|
"github.com/hashicorp/consul/agent/xds/config" |
|
|
|
"github.com/hashicorp/consul/agent/xds/response" |
|
|
|
"github.com/hashicorp/consul/agent/xds/response" |
|
|
|
|
|
|
|
"google.golang.org/protobuf/proto" |
|
|
|
|
|
|
|
"google.golang.org/protobuf/types/known/durationpb" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// routesFromSnapshot returns the xDS API representation of the "routes" in the
|
|
|
|
// routesFromSnapshot returns the xDS API representation of the "routes" in the
|
|
|
@ -1016,7 +1014,6 @@ func (s *ResourceGenerator) makeRouteActionForSplitter( |
|
|
|
forMeshGateway bool, |
|
|
|
forMeshGateway bool, |
|
|
|
) (*envoy_route_v3.Route_Route, error) { |
|
|
|
) (*envoy_route_v3.Route_Route, error) { |
|
|
|
clusters := make([]*envoy_route_v3.WeightedCluster_ClusterWeight, 0, len(splits)) |
|
|
|
clusters := make([]*envoy_route_v3.WeightedCluster_ClusterWeight, 0, len(splits)) |
|
|
|
totalWeight := 0 |
|
|
|
|
|
|
|
for _, split := range splits { |
|
|
|
for _, split := range splits { |
|
|
|
nextNode := chain.Nodes[split.NextNode] |
|
|
|
nextNode := chain.Nodes[split.NextNode] |
|
|
|
|
|
|
|
|
|
|
@ -1033,7 +1030,6 @@ func (s *ResourceGenerator) makeRouteActionForSplitter( |
|
|
|
// The smallest representable weight is 1/10000 or .01% but envoy
|
|
|
|
// The smallest representable weight is 1/10000 or .01% but envoy
|
|
|
|
// deals with integers so scale everything up by 100x.
|
|
|
|
// deals with integers so scale everything up by 100x.
|
|
|
|
weight := int(split.Weight * 100) |
|
|
|
weight := int(split.Weight * 100) |
|
|
|
totalWeight += weight |
|
|
|
|
|
|
|
cw := &envoy_route_v3.WeightedCluster_ClusterWeight{ |
|
|
|
cw := &envoy_route_v3.WeightedCluster_ClusterWeight{ |
|
|
|
Weight: response.MakeUint32Value(weight), |
|
|
|
Weight: response.MakeUint32Value(weight), |
|
|
|
Name: clusterName, |
|
|
|
Name: clusterName, |
|
|
@ -1049,18 +1045,11 @@ func (s *ResourceGenerator) makeRouteActionForSplitter( |
|
|
|
return nil, fmt.Errorf("number of clusters in splitter must be > 0; got %d", len(clusters)) |
|
|
|
return nil, fmt.Errorf("number of clusters in splitter must be > 0; got %d", len(clusters)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var envoyWeightScale *wrapperspb.UInt32Value |
|
|
|
|
|
|
|
if totalWeight == 10000 { |
|
|
|
|
|
|
|
envoyWeightScale = response.MakeUint32Value(10000) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return &envoy_route_v3.Route_Route{ |
|
|
|
return &envoy_route_v3.Route_Route{ |
|
|
|
Route: &envoy_route_v3.RouteAction{ |
|
|
|
Route: &envoy_route_v3.RouteAction{ |
|
|
|
ClusterSpecifier: &envoy_route_v3.RouteAction_WeightedClusters{ |
|
|
|
ClusterSpecifier: &envoy_route_v3.RouteAction_WeightedClusters{ |
|
|
|
WeightedClusters: &envoy_route_v3.WeightedCluster{ |
|
|
|
WeightedClusters: &envoy_route_v3.WeightedCluster{ |
|
|
|
Clusters: clusters, |
|
|
|
Clusters: clusters, |
|
|
|
// this field is deprecated, and we should get the desired behavior with the front-end validation
|
|
|
|
|
|
|
|
TotalWeight: envoyWeightScale, // scaled up 100%
|
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|