Backport of NET-6943 - Replace usage of deprecated Envoy field envoy.config.router.v3.WeightedCluster.total_weight. into release/1.17.x (#20061)

* no-op commit due to failed cherry-picking

* NET-6943 - Replace usage of deprecated Envoy field envoy.config.router.v3.WeightedCluster.total_weight. (#20011)

---------

Co-authored-by: temp <temp@hashicorp.com>
Co-authored-by: John Murret <john.murret@hashicorp.com>
pull/20071/head
hc-github-team-consul-core 2024-01-02 11:31:51 -06:00 committed by GitHub
parent ce7e73bb3a
commit 4e1e51904b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 20 additions and 50 deletions

3
.changelog/20011.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
connect: replace usage of deprecated Envoy field `envoy.config.router.v3.WeightedCluster.total_weight`.
```

View File

@ -17,16 +17,14 @@ import (
"golang.org/x/exp/maps"
"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/consul/discoverychain"
"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/xds/config"
"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
@ -994,7 +992,6 @@ func (s *ResourceGenerator) makeRouteActionForSplitter(
forMeshGateway bool,
) (*envoy_route_v3.Route_Route, error) {
clusters := make([]*envoy_route_v3.WeightedCluster_ClusterWeight, 0, len(splits))
totalWeight := 0
for _, split := range splits {
nextNode := chain.Nodes[split.NextNode]
@ -1011,7 +1008,6 @@ func (s *ResourceGenerator) makeRouteActionForSplitter(
// The smallest representable weight is 1/10000 or .01% but envoy
// deals with integers so scale everything up by 100x.
weight := int(split.Weight * 100)
totalWeight += weight
cw := &envoy_route_v3.WeightedCluster_ClusterWeight{
Weight: response.MakeUint32Value(weight),
Name: clusterName,
@ -1027,18 +1023,11 @@ func (s *ResourceGenerator) makeRouteActionForSplitter(
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{
Route: &envoy_route_v3.RouteAction{
ClusterSpecifier: &envoy_route_v3.RouteAction_WeightedClusters{
WeightedClusters: &envoy_route_v3.WeightedCluster{
Clusters: clusters,
// this field is deprecated, and we should get the desired behavior with the front-end validation
TotalWeight: envoyWeightScale, // scaled up 100%
},
},
},

View File

@ -28,8 +28,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}

View File

@ -57,8 +57,7 @@
"name": "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 450
}
],
"totalWeight": 10000
]
}
}
}

View File

@ -360,8 +360,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},

View File

@ -85,8 +85,7 @@
],
"weight": 50
}
],
"totalWeight": 10000
]
}
}
}

View File

@ -58,8 +58,7 @@
"name": "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 450
}
],
"totalWeight": 10000
]
}
}
}

View File

@ -28,8 +28,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}

View File

@ -399,8 +399,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},

View File

@ -361,8 +361,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},

View File

@ -86,8 +86,7 @@
],
"weight": 50
}
],
"totalWeight": 10000
]
}
}
}

View File

@ -27,8 +27,7 @@
"name": "exported~db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 4000
}
],
"totalWeight": 10000
]
}
}
},

View File

@ -27,8 +27,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}

View File

@ -361,8 +361,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},

View File

@ -360,8 +360,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},

View File

@ -9,7 +9,6 @@ import (
envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_matcher_v3 "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3"
"google.golang.org/protobuf/types/known/wrapperspb"
"github.com/hashicorp/consul/agent/xds/response"
"github.com/hashicorp/consul/envoyextensions/xdscommon"
@ -266,22 +265,15 @@ func (pr *ProxyResources) makeEnvoyRouteActionFromProxystateRouteDestination(psR
case *pbproxystate.RouteDestination_WeightedClusters:
psWeightedClusters := psRouteDestination.GetWeightedClusters()
envoyClusters := make([]*envoy_route_v3.WeightedCluster_ClusterWeight, 0, len(psWeightedClusters.GetClusters()))
totalWeight := 0
for _, psCluster := range psWeightedClusters.GetClusters() {
clusters, _ := pr.makeClusters(psCluster.Name)
pr.envoyResources[xdscommon.ClusterType] = append(pr.envoyResources[xdscommon.ClusterType], clusters...)
totalWeight += int(psCluster.Weight.GetValue())
envoyClusters = append(envoyClusters, makeEnvoyClusterWeightFromProxystateWeightedCluster(psCluster))
}
var envoyWeightScale *wrapperspb.UInt32Value
if totalWeight == 10000 {
envoyWeightScale = response.MakeUint32Value(10000)
}
envoyRouteRoute.Route.ClusterSpecifier = &envoy_route_v3.RouteAction_WeightedClusters{
WeightedClusters: &envoy_route_v3.WeightedCluster{
Clusters: envoyClusters,
TotalWeight: envoyWeightScale,
Clusters: envoyClusters,
},
}
default:

View File

@ -174,8 +174,7 @@
"name": "backend2.default.dc1.internal.domain.consul",
"weight": 5000
}
],
"total_weight": 10000
]
}
}
}