Skip to content

Commit

Permalink
xdsclient: NACK endpoint resource if load_balancing_weight is specifi…
Browse files Browse the repository at this point in the history
…ed and is zero (#5568)
  • Loading branch information
easwars committed Aug 5, 2022
1 parent f9409d3 commit 6f34b7a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion internal/testutils/xds/e2e/clientresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ func DefaultEndpoint(clusterName string, host string, ports []uint32) *v3endpoin
PortSpecifier: &v3corepb.SocketAddress_PortValue{PortValue: port}},
}},
}},
LoadBalancingWeight: &wrapperspb.UInt32Value{Value: 1},
})
}
return &v3endpointpb.ClusterLoadAssignment{
Expand Down
3 changes: 0 additions & 3 deletions xds/internal/testutils/protos.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ func (clab *ClusterLoadAssignmentBuilder) AddLocality(subzone string, weight uin
lbe.LoadBalancingWeight = &wrapperspb.UInt32Value{Value: opts.Weight[i]}
}
}
if lbe.LoadBalancingWeight == nil {
lbe.LoadBalancingWeight = &wrapperspb.UInt32Value{Value: 1}
}
lbEndPoints = append(lbEndPoints, lbe)
}

Expand Down
12 changes: 9 additions & 3 deletions xds/internal/xdsclient/xdsresource/unmarshal_eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ func parseDropPolicy(dropPolicy *v3endpointpb.ClusterLoadAssignment_Policy_DropO
func parseEndpoints(lbEndpoints []*v3endpointpb.LbEndpoint) ([]Endpoint, error) {
endpoints := make([]Endpoint, 0, len(lbEndpoints))
for _, lbEndpoint := range lbEndpoints {
weight := lbEndpoint.GetLoadBalancingWeight().GetValue()
if weight == 0 {
return nil, fmt.Errorf("EDS response contains an endpoint with zero weight: %+v", lbEndpoint)
// If the load_balancing_weight field is specified, it must be set to a
// value of at least 1. If unspecified, each host is presumed to have
// equal weight in a locality.
weight := uint32(1)
if w := lbEndpoint.GetLoadBalancingWeight(); w != nil {
if w.GetValue() == 0 {
return nil, fmt.Errorf("EDS response contains an endpoint with zero weight: %+v", lbEndpoint)
}
weight = w.GetValue()
}
endpoints = append(endpoints, Endpoint{
HealthStatus: EndpointHealthStatus(lbEndpoint.GetHealthStatus()),
Expand Down

0 comments on commit 6f34b7a

Please sign in to comment.