Skip to content

Commit

Permalink
xds: remove support for v2 Transport API
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindbr8 committed Feb 8, 2023
1 parent d655f40 commit 0144c93
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 609 deletions.
13 changes: 2 additions & 11 deletions internal/testutils/xds/bootstrap/bootstrap.go
Expand Up @@ -34,10 +34,8 @@ var logger = grpclog.Component("internal/xds")
type TransportAPI int

const (
// TransportV2 refers to the v2 xDS transport protocol.
TransportV2 TransportAPI = iota
// TransportV3 refers to the v3 xDS transport protocol.
TransportV3
TransportV3 TransportAPI = iota
)

// Options wraps the parameters used to generate bootstrap configuration.
Expand Down Expand Up @@ -119,14 +117,7 @@ func Contents(opts Options) ([]byte, error) {
ClientDefaultListenerResourceNameTemplate: opts.ClientDefaultListenerResourceNameTemplate,
ServerListenerResourceNameTemplate: opts.ServerListenerResourceNameTemplate,
}
switch opts.Version {
case TransportV2:
// TODO: Add any v2 specific fields.
case TransportV3:
cfg.XdsServers[0].ServerFeatures = append(cfg.XdsServers[0].ServerFeatures, "xds_v3")
default:
return nil, fmt.Errorf("unsupported xDS transport protocol version: %v", opts.Version)
}
cfg.XdsServers[0].ServerFeatures = append(cfg.XdsServers[0].ServerFeatures, "xds_v3")

auths := make(map[string]authority)
if envconfig.XDSFederation {
Expand Down
37 changes: 2 additions & 35 deletions xds/csds/csds.go
Expand Up @@ -29,7 +29,7 @@ import (
"io"
"sync"

"github.com/golang/protobuf/proto"
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
internalgrpclog "google.golang.org/grpc/internal/grpclog"
Expand All @@ -39,8 +39,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"

v3adminpb "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
v2corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
v3statusgrpc "github.com/envoyproxy/go-control-plane/envoy/service/status/v3"
v3statuspb "github.com/envoyproxy/go-control-plane/envoy/service/status/v3"
)
Expand Down Expand Up @@ -126,7 +124,7 @@ func (s *ClientStatusDiscoveryServer) buildClientStatusRespForReq(req *v3statusp
ret := &v3statuspb.ClientStatusResponse{
Config: []*v3statuspb.ClientConfig{
{
Node: nodeProtoToV3(s.xdsClient.BootstrapConfig().XDSServer.NodeProto, s.logger),
Node: s.xdsClient.BootstrapConfig().XDSServer.NodeProto.(*v3corepb.Node),
GenericXdsConfigs: dumpToGenericXdsConfig(dump),
},
},
Expand All @@ -141,37 +139,6 @@ func (s *ClientStatusDiscoveryServer) Close() {
}
}

// nodeProtoToV3 converts the given proto into a v3.Node. n is from bootstrap
// config, it can be either v2.Node or v3.Node.
//
// If n is already a v3.Node, return it.
// If n is v2.Node, marshal and unmarshal it to v3.
// Otherwise, return nil.
//
// The default case (not v2 or v3) is nil, instead of error, because the
// resources in the response are more important than the node. The worst case is
// that the user will receive no Node info, but will still get resources.
func nodeProtoToV3(n proto.Message, logger *internalgrpclog.PrefixLogger) *v3corepb.Node {
var node *v3corepb.Node
switch nn := n.(type) {
case *v3corepb.Node:
node = nn
case *v2corepb.Node:
v2, err := proto.Marshal(nn)
if err != nil {
logger.Warningf("Failed to marshal node (%v): %v", n, err)
break
}
node = new(v3corepb.Node)
if err := proto.Unmarshal(v2, node); err != nil {
logger.Warningf("Failed to unmarshal node (%v): %v", v2, err)
}
default:
logger.Warningf("node from bootstrap is %#v, only v2.Node and v3.Node are supported", nn)
}
return node
}

func dumpToGenericXdsConfig(dump map[string]map[string]xdsresource.UpdateWithMD) []*v3statuspb.ClientConfig_GenericXdsConfig {
var ret []*v3statuspb.ClientConfig_GenericXdsConfig
for typeURL, updates := range dump {
Expand Down
38 changes: 4 additions & 34 deletions xds/internal/xdsclient/bootstrap/bootstrap.go
Expand Up @@ -41,7 +41,6 @@ import (
"google.golang.org/grpc/xds/bootstrap"
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource/version"

v2corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
)

Expand Down Expand Up @@ -126,13 +125,7 @@ type ServerConfig struct {
// content. It doesn't cover NodeProto because NodeProto isn't used by
// federation.
func (sc *ServerConfig) String() string {
var ver string
switch sc.TransportAPI {
case version.TransportV3:
ver = "xDSv3"
case version.TransportV2:
ver = "xDSv2"
}
var ver = "xDSv3"
return strings.Join([]string{sc.ServerURI, sc.CredsType, ver}, "-")
}

Expand Down Expand Up @@ -501,37 +494,14 @@ func (c *Config) updateNodeProto(node *v3corepb.Node) error {
v3.UserAgentVersionType = &v3corepb.Node_UserAgentVersion{UserAgentVersion: grpc.Version}
v3.ClientFeatures = append(v3.ClientFeatures, clientFeatureNoOverprovisioning, clientFeatureResourceWrapper)

v3bytes, err := proto.Marshal(v3)
if err != nil {
return fmt.Errorf("xds: proto.Marshal(%v): %v", v3, err)
}
v2 := &v2corepb.Node{}
if err := proto.Unmarshal(v3bytes, v2); err != nil {
return fmt.Errorf("xds: proto.Unmarshal(%v): %v", v3bytes, err)
}
// BuildVersion is deprecated, and is replaced by user_agent_name and
// user_agent_version. But the management servers are still using the old
// field, so we will keep both set.
v2.BuildVersion = gRPCVersion
v2.UserAgentVersionType = &v2corepb.Node_UserAgentVersion{UserAgentVersion: grpc.Version}

switch c.XDSServer.TransportAPI {
case version.TransportV2:
c.XDSServer.NodeProto = v2
case version.TransportV3:
c.XDSServer.NodeProto = v3
}
c.XDSServer.NodeProto = v3

for _, a := range c.Authorities {
if a.XDSServer == nil {
continue
}
switch a.XDSServer.TransportAPI {
case version.TransportV2:
a.XDSServer.NodeProto = v2
case version.TransportV3:
a.XDSServer.NodeProto = v3
}
a.XDSServer.NodeProto = v3

}

return nil
Expand Down

0 comments on commit 0144c93

Please sign in to comment.