Skip to content

Commit 1c83e22

Browse files
authored
xds/e2e: Use Metadata field from BackendOptions only when it is non-nil (#8619)
Fixes: #8545 Check BackendOptions.Metadata field before assigning it to `v3corepb.Metadata`. RELEASE NOTES: N/A
1 parent 44475a5 commit 1c83e22

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

internal/testutils/xds/e2e/clientresources.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,7 @@ func EndpointResourceWithOptions(opts EndpointOptions) *v3endpointpb.ClusterLoad
712712
},
713713
}
714714
}
715-
metadata, err := structpb.NewStruct(b.Metadata)
716-
if err != nil {
717-
panic(err)
718-
}
719-
lbEndpoints = append(lbEndpoints, &v3endpointpb.LbEndpoint{
715+
lbEndpoint := &v3endpointpb.LbEndpoint{
720716
HostIdentifier: &v3endpointpb.LbEndpoint_Endpoint{Endpoint: &v3endpointpb.Endpoint{
721717
Address: &v3corepb.Address{Address: &v3corepb.Address_SocketAddress{
722718
SocketAddress: &v3corepb.SocketAddress{
@@ -729,12 +725,20 @@ func EndpointResourceWithOptions(opts EndpointOptions) *v3endpointpb.ClusterLoad
729725
}},
730726
HealthStatus: b.HealthStatus,
731727
LoadBalancingWeight: &wrapperspb.UInt32Value{Value: b.Weight},
732-
Metadata: &v3corepb.Metadata{
728+
}
729+
730+
if b.Metadata != nil {
731+
metadata, err := structpb.NewStruct(b.Metadata)
732+
if err != nil {
733+
panic(fmt.Sprintf("failed to marshal metadata: %v", err))
734+
}
735+
lbEndpoint.Metadata = &v3corepb.Metadata{
733736
FilterMetadata: map[string]*structpb.Struct{
734737
"envoy.lb": metadata,
735738
},
736-
},
737-
})
739+
}
740+
}
741+
lbEndpoints = append(lbEndpoints, lbEndpoint)
738742
}
739743

740744
l := locality.Locality

0 commit comments

Comments
 (0)