From f47af8ef66b057d324c099c7d75185a2ab15ddb4 Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Fri, 5 Aug 2022 14:38:04 -0700 Subject: [PATCH] xdsclient: NACK endpoint resource if load_balancing_weight is specified and is zero --- internal/testutils/xds/e2e/clientresources.go | 1 - xds/internal/testutils/protos.go | 3 --- xds/internal/xdsclient/xdsresource/unmarshal_eds.go | 12 +++++++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/testutils/xds/e2e/clientresources.go b/internal/testutils/xds/e2e/clientresources.go index f5363aff91f..f3f7f6307c5 100644 --- a/internal/testutils/xds/e2e/clientresources.go +++ b/internal/testutils/xds/e2e/clientresources.go @@ -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{ diff --git a/xds/internal/testutils/protos.go b/xds/internal/testutils/protos.go index b9fbc7448e1..fc3cdf307fc 100644 --- a/xds/internal/testutils/protos.go +++ b/xds/internal/testutils/protos.go @@ -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) } diff --git a/xds/internal/xdsclient/xdsresource/unmarshal_eds.go b/xds/internal/xdsclient/xdsresource/unmarshal_eds.go index a2e8fd1c173..7d4b89dc9dc 100644 --- a/xds/internal/xdsclient/xdsresource/unmarshal_eds.go +++ b/xds/internal/xdsclient/xdsresource/unmarshal_eds.go @@ -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()),