xds: require EDS service name in new-style CDS clusters (gRFC A47) (#6438)

This commit is contained in:
Doug Fawley 2023-07-11 08:52:37 -07:00 committed by GitHub
parent bf5b7aecd5
commit f0280f9d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import (
"fmt"
"net"
"strconv"
"strings"
"time"
v3clusterpb "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
@ -173,6 +174,9 @@ func validateClusterAndConstructClusterUpdate(cluster *v3clusterpb.Cluster) (Clu
}
ret.ClusterType = ClusterTypeEDS
ret.EDSServiceName = cluster.GetEdsClusterConfig().GetServiceName()
if strings.HasPrefix(ret.ClusterName, "xdstp:") && ret.EDSServiceName == "" {
return ClusterUpdate{}, fmt.Errorf("CDS's EDS service name is not set with a new-style cluster name: %+v", cluster)
}
return ret, nil
case cluster.GetType() == v3clusterpb.Cluster_LOGICAL_DNS:
if !envconfig.XDSAggregateAndDNS {

View File

@ -1347,6 +1347,23 @@ func (s) TestUnmarshalCluster(t *testing.T) {
Raw: v3ClusterAnyWithEDSConfigSourceSelf,
},
},
{
name: "xdstp cluster resource with unset EDS service name",
resource: testutils.MarshalAny(&v3clusterpb.Cluster{
Name: "xdstp:foo",
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
EdsConfig: &v3corepb.ConfigSource{
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
Ads: &v3corepb.AggregatedConfigSource{},
},
},
ServiceName: "",
},
}),
wantName: "xdstp:foo",
wantErr: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {