Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds/bootstrap_config: add a string function to server config #5031

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions xds/internal/xdsclient/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type ServerConfig struct {
// Creds contains the credentials to be used while talking to the xDS
// server, as a grpc.DialOption.
Creds grpc.DialOption
// credsType is the type of the creds. It will be used to dedup servers.
credsType string
// CredsType is the type of the creds. It will be used to dedup servers.
CredsType string
// TransportAPI indicates the API version of xDS transport protocol to use.
// This describes the xDS gRPC endpoint and version of
// DiscoveryRequest/Response used on the wire.
Expand All @@ -86,6 +86,22 @@ type ServerConfig struct {
NodeProto proto.Message
}

// String returns the string representation of the ServerConfig.
//
// Note that it covers (almost) all the fields so the string can be used map
// keys. Except NodeProto because NodeProto isn't used by federation (and this
// is only used as key in federation).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the last line the comment:

// Except NodeProto because NodeProto isn't used by federation (and this
// is only used as key in federation)

You are saying it is not used by federation, but is used as a key in federation. Can you please clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment updated.

func (sc *ServerConfig) String() string {
var ver string
switch sc.TransportAPI {
case version.TransportV3:
ver = "xDSv3"
case version.TransportV2:
ver = "xDSv2"
}
return strings.Join([]string{sc.ServerURI, sc.CredsType, ver}, "-")
}

// UnmarshalJSON takes the json data (a list of servers) and unmarshals the
// first one in the list.
func (sc *ServerConfig) UnmarshalJSON(data []byte) error {
Expand All @@ -100,7 +116,7 @@ func (sc *ServerConfig) UnmarshalJSON(data []byte) error {
sc.ServerURI = xs.ServerURI
for _, cc := range xs.ChannelCreds {
// We stop at the first credential type that we support.
sc.credsType = cc.Type
sc.CredsType = cc.Type
if cc.Type == credsGoogleDefault {
sc.Creds = grpc.WithCredentialsBundle(google.NewDefaultCredentials())
break
Expand Down
22 changes: 11 additions & 11 deletions xds/internal/xdsclient/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ var (
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
credsType: "insecure",
CredsType: "insecure",
NodeProto: v2NodeProto,
},
ClientDefaultListenerResourceNameTemplate: "%s",
Expand All @@ -221,7 +221,7 @@ var (
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
NodeProto: v2NodeProto,
},
ClientDefaultListenerResourceNameTemplate: "%s",
Expand All @@ -230,7 +230,7 @@ var (
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV3,
NodeProto: v3NodeProto,
},
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestNewConfigV2ProtoSuccess(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
credsType: "insecure",
CredsType: "insecure",
NodeProto: &v2corepb.Node{
BuildVersion: gRPCVersion,
UserAgentName: gRPCUserAgentName,
Expand Down Expand Up @@ -665,7 +665,7 @@ func TestNewConfigWithCertificateProviders(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV3,
NodeProto: v3NodeProto,
},
Expand Down Expand Up @@ -759,7 +759,7 @@ func TestNewConfigWithServerListenerResourceNameTemplate(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV2,
NodeProto: v2NodeProto,
},
Expand Down Expand Up @@ -908,7 +908,7 @@ func TestNewConfigWithFederation(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV2,
NodeProto: v2NodeProto,
},
Expand All @@ -920,7 +920,7 @@ func TestNewConfigWithFederation(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "td.com",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV3,
NodeProto: v3NodeProto,
},
Expand All @@ -934,7 +934,7 @@ func TestNewConfigWithFederation(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV2,
NodeProto: v2NodeProto,
},
Expand All @@ -947,7 +947,7 @@ func TestNewConfigWithFederation(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV2,
NodeProto: v2NodeProto,
},
Expand All @@ -965,7 +965,7 @@ func TestNewConfigWithFederation(t *testing.T) {
XDSServer: &ServerConfig{
ServerURI: "trafficdirector.googleapis.com:443",
Creds: grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()),
credsType: "google_default",
CredsType: "google_default",
TransportAPI: version.TransportV2,
NodeProto: v2NodeProto,
},
Expand Down