Skip to content

Commit

Permalink
[xds_fed_config_self] xds/resource: accept Self as LDS's RDS config s…
Browse files Browse the repository at this point in the history
…ource and CDS's EDS config source
  • Loading branch information
menghanl committed Jan 20, 2022
1 parent 6f54b5d commit 3da8288
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
4 changes: 2 additions & 2 deletions xds/internal/xdsclient/xdsresource/unmarshal_cds.go
Expand Up @@ -136,8 +136,8 @@ func validateClusterAndConstructClusterUpdate(cluster *v3clusterpb.Cluster) (Clu
// Validate and set cluster type from the response.
switch {
case cluster.GetType() == v3clusterpb.Cluster_EDS:
if cluster.GetEdsClusterConfig().GetEdsConfig().GetAds() == nil {
return ClusterUpdate{}, fmt.Errorf("unexpected edsConfig in response: %+v", cluster)
if configsource := cluster.GetEdsClusterConfig().GetEdsConfig(); configsource.GetAds() == nil && configsource.GetSelf() == nil {
return ClusterUpdate{}, fmt.Errorf("CDS's EDS config source is not ADS or Self: %+v", cluster)
}
ret.ClusterType = ClusterTypeEDS
ret.EDSServiceName = cluster.GetEdsClusterConfig().GetServiceName()
Expand Down
32 changes: 32 additions & 0 deletions xds/internal/xdsclient/xdsresource/unmarshal_cds_test.go
Expand Up @@ -1421,6 +1421,23 @@ func (s) TestUnmarshalCluster(t *testing.T) {
},
},
})

v3ClusterAnyWithEDSConfigSourceSelf = testutils.MarshalAny(&v3clusterpb.Cluster{
Name: v3ClusterName,
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
EdsConfig: &v3corepb.ConfigSource{
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{},
},
ServiceName: v3Service,
},
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
LrsServer: &v3corepb.ConfigSource{
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
Self: &v3corepb.SelfConfigSource{},
},
},
})
)
const testVersion = "test-version-cds"

Expand Down Expand Up @@ -1513,6 +1530,21 @@ func (s) TestUnmarshalCluster(t *testing.T) {
Version: testVersion,
},
},
{
name: "v3 cluster with EDS config source self",
resources: []*anypb.Any{v3ClusterAnyWithEDSConfigSourceSelf},
wantUpdate: map[string]ClusterUpdateErrTuple{
v3ClusterName: {Update: ClusterUpdate{
ClusterName: v3ClusterName,
EDSServiceName: v3Service, EnableLRS: true,
Raw: v3ClusterAnyWithEDSConfigSourceSelf,
}},
},
wantMD: UpdateMetadata{
Status: ServiceStatusACKed,
Version: testVersion,
},
},
{
name: "multiple clusters",
resources: []*anypb.Any{v2ClusterAny, v3ClusterAny},
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/xdsclient/xdsresource/unmarshal_lds.go
Expand Up @@ -102,8 +102,8 @@ func processClientSideListener(lis *v3listenerpb.Listener, logger *grpclog.Prefi

switch apiLis.RouteSpecifier.(type) {
case *v3httppb.HttpConnectionManager_Rds:
if apiLis.GetRds().GetConfigSource().GetAds() == nil {
return nil, fmt.Errorf("ConfigSource is not ADS: %+v", lis)
if configsource := apiLis.GetRds().GetConfigSource(); configsource.GetAds() == nil && configsource.GetSelf() == nil {
return nil, fmt.Errorf("LDS's RDS configSource is not ADS or Self: %+v", lis)
}
name := apiLis.GetRds().GetRouteConfigName()
if name == "" {
Expand Down
36 changes: 35 additions & 1 deletion xds/internal/xdsclient/xdsresource/unmarshal_lds_test.go
Expand Up @@ -204,6 +204,25 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) {
},
})
}

v3ListenerWithCDSConfigSourceSelf = testutils.MarshalAny(&v3listenerpb.Listener{
Name: v3LDSTarget,
ApiListener: &v3listenerpb.ApiListener{
ApiListener: testutils.MarshalAny(
&v3httppb.HttpConnectionManager{
RouteSpecifier: &v3httppb.HttpConnectionManager_Rds{
Rds: &v3httppb.Rds{
ConfigSource: &v3corepb.ConfigSource{
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{},
},
RouteConfigName: v3RouteConfigName,
},
},
HttpFilters: []*v3httppb.HttpFilter{emptyRouterFilter},
}),
},
})

errMD = UpdateMetadata{
Status: ServiceStatusNACKed,
Version: testVersion,
Expand Down Expand Up @@ -294,7 +313,22 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) {
wantErr: true,
},
{
name: "rds.ConfigSource in apiListener is not ADS",
name: "rds.ConfigSource in apiListener is Self",
resources: []*anypb.Any{v3ListenerWithCDSConfigSourceSelf},
wantUpdate: map[string]ListenerUpdateErrTuple{
v3LDSTarget: {Update: ListenerUpdate{
RouteConfigName: v3RouteConfigName,
HTTPFilters: []HTTPFilter{routerFilter},
Raw: v3ListenerWithCDSConfigSourceSelf,
}},
},
wantMD: UpdateMetadata{
Status: ServiceStatusACKed,
Version: testVersion,
},
},
{
name: "rds.ConfigSource in apiListener is not ADS or Self",
resources: []*anypb.Any{testutils.MarshalAny(&v3listenerpb.Listener{
Name: v3LDSTarget,
ApiListener: &v3listenerpb.ApiListener{
Expand Down

0 comments on commit 3da8288

Please sign in to comment.