Skip to content

Commit b891dc6

Browse files
committed
xds: reject ring_hash cluster with out-of-range or inverted ring size
1 parent 6d697e4 commit b891dc6

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

internal/xds/xdsclient/xdsresource/unmarshal_cds.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ func validateClusterAndConstructClusterUpdate(cluster *v3clusterpb.Cluster, serv
137137
if max := rhc.GetMaximumRingSize(); max != nil {
138138
maxSize = max.GetValue()
139139
}
140+
if minSize > ringHashSizeUpperBound {
141+
return ClusterUpdate{}, fmt.Errorf("ring_hash_lb_config.minimum_ring_size %d is greater than upper bound %d in response: %+v", minSize, ringHashSizeUpperBound, cluster)
142+
}
143+
if maxSize > ringHashSizeUpperBound {
144+
return ClusterUpdate{}, fmt.Errorf("ring_hash_lb_config.maximum_ring_size %d is greater than upper bound %d in response: %+v", maxSize, ringHashSizeUpperBound, cluster)
145+
}
146+
if minSize > maxSize {
147+
return ClusterUpdate{}, fmt.Errorf("ring_hash_lb_config.minimum_ring_size %d is greater than maximum_ring_size %d in response: %+v", minSize, maxSize, cluster)
148+
}
140149

141150
rhLBCfg := []byte(fmt.Sprintf("{\"minRingSize\": %d, \"maxRingSize\": %d}", minSize, maxSize))
142151
lbPolicy = []byte(fmt.Sprintf(`[{"ring_hash_experimental": %s}]`, rhLBCfg))

internal/xds/xdsclient/xdsresource/unmarshal_cds_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
166166
{
167167
name: "ring-hash-max-bound-greater-than-upper-bound",
168168
cluster: &v3clusterpb.Cluster{
169+
Name: clusterName,
170+
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
171+
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
172+
EdsConfig: &v3corepb.ConfigSource{
173+
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
174+
Ads: &v3corepb.AggregatedConfigSource{},
175+
},
176+
},
177+
ServiceName: serviceName,
178+
},
169179
LbPolicy: v3clusterpb.Cluster_RING_HASH,
170180
LbConfig: &v3clusterpb.Cluster_RingHashLbConfig_{
171181
RingHashLbConfig: &v3clusterpb.Cluster_RingHashLbConfig{
@@ -175,6 +185,29 @@ func (s) TestValidateCluster_Failure(t *testing.T) {
175185
},
176186
wantErr: true,
177187
},
188+
{
189+
name: "ring-hash-min-greater-than-max",
190+
cluster: &v3clusterpb.Cluster{
191+
Name: clusterName,
192+
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
193+
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
194+
EdsConfig: &v3corepb.ConfigSource{
195+
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
196+
Ads: &v3corepb.AggregatedConfigSource{},
197+
},
198+
},
199+
ServiceName: serviceName,
200+
},
201+
LbPolicy: v3clusterpb.Cluster_RING_HASH,
202+
LbConfig: &v3clusterpb.Cluster_RingHashLbConfig_{
203+
RingHashLbConfig: &v3clusterpb.Cluster_RingHashLbConfig{
204+
MinimumRingSize: wrapperspb.UInt64(5000),
205+
MaximumRingSize: wrapperspb.UInt64(100),
206+
},
207+
},
208+
},
209+
wantErr: true,
210+
},
178211
{
179212
name: "ring-hash-max-bound-greater-than-upper-bound-load-balancing-policy",
180213
cluster: &v3clusterpb.Cluster{

0 commit comments

Comments
 (0)