Skip to content

Commit

Permalink
NET-6943 - Replace usage of deprecated Envoy field envoy.config.route…
Browse files Browse the repository at this point in the history
…r.v3.WeightedCluster.total_weight.
  • Loading branch information
jmurret committed Dec 22, 2023
1 parent b9ad0df commit d5af8c7
Show file tree
Hide file tree
Showing 21 changed files with 24 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .changelog/20011.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
xds: replace usage of deprecated Envoy field envoy.config.router.v3.WeightedCluster.total_weight`
```
2 changes: 1 addition & 1 deletion .github/workflows/nightly-test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ jobs:
consul-version: [ "1.16", "1.17"]
env:
CONSUL_LATEST_VERSION: ${{ matrix.consul-version }}
ENVOY_VERSION: "1.28.0"
ENVOY_VERSION: "1.25.4"
steps:
- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ jobs:
id-token: write # NOTE: this permission is explicitly required for Vault auth.
contents: read
env:
ENVOY_VERSION: "1.28.0"
ENVOY_VERSION: "1.25.4"
CONSUL_DATAPLANE_IMAGE: "docker.io/hashicorppreview/consul-dataplane:1.3-dev-ubi"
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ GO_BUILD_TAG?=consul-build-go
UI_BUILD_TAG?=consul-build-ui
BUILD_CONTAINER_NAME?=consul-builder
CONSUL_IMAGE_VERSION?=latest
ENVOY_VERSION?='1.28.0'
ENVOY_VERSION?='1.25.4'
CONSUL_DATAPLANE_IMAGE := $(or $(CONSUL_DATAPLANE_IMAGE),"docker.io/hashicorppreview/consul-dataplane:1.3-dev-ubi")
DEPLOYER_CONSUL_DATAPLANE_IMAGE := $(or $(DEPLOYER_CONSUL_DATAPLANE_IMAGE), "docker.io/hashicorppreview/consul-dataplane:1.3-dev")

Expand Down
15 changes: 2 additions & 13 deletions agent/xds/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1016,7 +1014,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]

Expand All @@ -1033,7 +1030,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,
Expand All @@ -1049,18 +1045,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%
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
"name": "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 450
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@
],
"weight": 50
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
"name": "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 450
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@
],
"weight": 50
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"name": "exported~db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 4000
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
9 changes: 1 addition & 8 deletions agent/xdsv2/route_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,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() {
pr.addEnvoyClustersAndEndpointsToEnvoyResources(psCluster.Name)

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:
Expand Down
3 changes: 1 addition & 2 deletions troubleshoot/proxy/testdata/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2241,8 +2241,7 @@
"name": "backend2.default.dc1.internal.7838b4bd-58b3-8117-3df1-60584910541b.consul",
"weight": 5000
}
],
"total_weight": 10000
]
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions troubleshoot/proxy/testdata/upstreams/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@
"name": "backend2.default.dc1.internal.domain.consul",
"weight": 5000
}
],
"total_weight": 10000
]
}
}
}
Expand Down

0 comments on commit d5af8c7

Please sign in to comment.