Only enable xds credentials if the target is an xDS target

This commit is contained in:
PapaCharlie 2024-01-23 14:40:42 -08:00
parent 0620352c14
commit 14ea019627
1 changed files with 8 additions and 3 deletions

View File

@ -635,9 +635,14 @@ func BlockingDial(ctx context.Context, network, address string, creds credential
} }
var err error var err error
creds, err = xdsCredentials.NewClientCredentials(xdsCredentials.ClientOptions{FallbackCreds: creds}) if strings.HasPrefix(address, "xds:///") {
if err != nil { // The xds:/// prefix is used to signal to the gRPC client to use an xDS server to resolve the
return nil, err // target. The relevant credentials will be automatically pulled from the GRPC_XDS_BOOTSTRAP or
// GRPC_XDS_BOOTSTRAP_CONFIG env vars.
creds, err = xdsCredentials.NewClientCredentials(xdsCredentials.ClientOptions{FallbackCreds: creds})
if err != nil {
return nil, err
}
} }
dialer := func(ctx context.Context, address string) (net.Conn, error) { dialer := func(ctx context.Context, address string) (net.Conn, error) {