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: fail to create xDS channel if no server with supported channel creds found #7400
Merged
voidzcy
merged 4 commits into
grpc:master
from
voidzcy:impl/fail_to_create_xds_channel_if_needed
Sep 19, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ee89f3e
Move XdsChannelFactory to its own file and improve tests.
voidzcy 603d929
Constructing XdsClient with channel injected.
voidzcy 612b791
Create the xDS channel outside XdsClient.
voidzcy a332d2d
Throw XdsInitializationException if the given server list to create t…
voidzcy File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2020 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc.xds; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import io.grpc.alts.GoogleDefaultChannelBuilder; | ||
import io.grpc.xds.Bootstrapper.ChannelCreds; | ||
import io.grpc.xds.Bootstrapper.ServerInfo; | ||
import io.grpc.xds.XdsClient.XdsChannel; | ||
import io.grpc.xds.XdsLogger.XdsLogLevel; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Factory for creating channels to xDS severs. | ||
*/ | ||
abstract class XdsChannelFactory { | ||
@VisibleForTesting | ||
static boolean experimentalV3SupportEnvVar = Boolean.parseBoolean( | ||
System.getenv("GRPC_XDS_EXPERIMENTAL_V3_SUPPORT")); | ||
|
||
private static final String XDS_V3_SERVER_FEATURE = "xds_v3"; | ||
private static final XdsChannelFactory DEFAULT_INSTANCE = new XdsChannelFactory() { | ||
/** | ||
* Creates a channel to the first server in the given list. | ||
*/ | ||
@Override | ||
XdsChannel createChannel(List<ServerInfo> servers) throws XdsInitializationException { | ||
if (servers.isEmpty()) { | ||
throw new XdsInitializationException("No server provided"); | ||
} | ||
XdsLogger logger = XdsLogger.withPrefix("xds-client-channel-factory"); | ||
ServerInfo serverInfo = servers.get(0); | ||
String serverUri = serverInfo.getServerUri(); | ||
logger.log(XdsLogLevel.INFO, "Creating channel to {0}", serverUri); | ||
List<ChannelCreds> channelCredsList = serverInfo.getChannelCredentials(); | ||
ManagedChannelBuilder<?> channelBuilder = null; | ||
// Use the first supported channel credentials configuration. | ||
for (ChannelCreds creds : channelCredsList) { | ||
switch (creds.getType()) { | ||
case "google_default": | ||
logger.log(XdsLogLevel.INFO, "Using channel credentials: google_default"); | ||
channelBuilder = GoogleDefaultChannelBuilder.forTarget(serverUri); | ||
break; | ||
case "insecure": | ||
logger.log(XdsLogLevel.INFO, "Using channel credentials: insecure"); | ||
channelBuilder = ManagedChannelBuilder.forTarget(serverUri).usePlaintext(); | ||
break; | ||
case "tls": | ||
logger.log(XdsLogLevel.INFO, "Using channel credentials: tls"); | ||
channelBuilder = ManagedChannelBuilder.forTarget(serverUri); | ||
break; | ||
default: | ||
} | ||
if (channelBuilder != null) { | ||
break; | ||
} | ||
} | ||
if (channelBuilder == null) { | ||
throw new XdsInitializationException("No server with supported channel creds found"); | ||
} | ||
|
||
ManagedChannel channel = channelBuilder | ||
.keepAliveTime(5, TimeUnit.MINUTES) | ||
.build(); | ||
boolean useProtocolV3 = experimentalV3SupportEnvVar | ||
&& serverInfo.getServerFeatures().contains(XDS_V3_SERVER_FEATURE); | ||
|
||
return new XdsChannel(channel, useProtocolV3); | ||
} | ||
}; | ||
|
||
static XdsChannelFactory getInstance() { | ||
return DEFAULT_INSTANCE; | ||
} | ||
|
||
/** | ||
* Creates a channel to one of the provided management servers. | ||
* | ||
* @throws XdsInitializationException if failed to create a channel with the given list of | ||
* servers. | ||
*/ | ||
abstract XdsChannel createChannel(List<ServerInfo> servers) throws XdsInitializationException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
|
||
package io.grpc.xds; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkState; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
@@ -25,29 +24,22 @@ | |
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import io.grpc.Status; | ||
import io.grpc.alts.GoogleDefaultChannelBuilder; | ||
import io.grpc.internal.ObjectPool; | ||
import io.grpc.xds.Bootstrapper.BootstrapInfo; | ||
import io.grpc.xds.Bootstrapper.ChannelCreds; | ||
import io.grpc.xds.Bootstrapper.ServerInfo; | ||
import io.grpc.xds.EnvoyProtoData.DropOverload; | ||
import io.grpc.xds.EnvoyProtoData.Locality; | ||
import io.grpc.xds.EnvoyProtoData.LocalityLbEndpoints; | ||
import io.grpc.xds.EnvoyProtoData.Route; | ||
import io.grpc.xds.EnvoyServerProtoData.Listener; | ||
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext; | ||
import io.grpc.xds.LoadStatsManager.LoadStatsStore; | ||
import io.grpc.xds.XdsLogger.XdsLogLevel; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
|
@@ -613,62 +605,6 @@ public synchronized XdsClient returnObject(Object object) { | |
} | ||
} | ||
|
||
/** | ||
* Factory for creating channels to xDS severs. | ||
*/ | ||
abstract static class XdsChannelFactory { | ||
@VisibleForTesting | ||
static boolean experimentalV3SupportEnvVar = Boolean.parseBoolean( | ||
System.getenv("GRPC_XDS_EXPERIMENTAL_V3_SUPPORT")); | ||
|
||
private static final String XDS_V3_SERVER_FEATURE = "xds_v3"; | ||
private static final XdsChannelFactory DEFAULT_INSTANCE = new XdsChannelFactory() { | ||
/** | ||
* Creates a channel to the first server in the given list. | ||
*/ | ||
@Override | ||
XdsChannel createChannel(List<ServerInfo> servers) { | ||
checkArgument(!servers.isEmpty(), "No management server provided."); | ||
XdsLogger logger = XdsLogger.withPrefix("xds-client-channel-factory"); | ||
ServerInfo serverInfo = servers.get(0); | ||
String serverUri = serverInfo.getServerUri(); | ||
logger.log(XdsLogLevel.INFO, "Creating channel to {0}", serverUri); | ||
List<ChannelCreds> channelCredsList = serverInfo.getChannelCredentials(); | ||
ManagedChannelBuilder<?> channelBuilder = null; | ||
// Use the first supported channel credentials configuration. | ||
// Currently, only "google_default" is supported. | ||
for (ChannelCreds creds : channelCredsList) { | ||
if (creds.getType().equals("google_default")) { | ||
logger.log(XdsLogLevel.INFO, "Using channel credentials: google_default"); | ||
channelBuilder = GoogleDefaultChannelBuilder.forTarget(serverUri); | ||
break; | ||
} | ||
} | ||
if (channelBuilder == null) { | ||
logger.log(XdsLogLevel.INFO, "Using default channel credentials"); | ||
channelBuilder = ManagedChannelBuilder.forTarget(serverUri); | ||
} | ||
|
||
ManagedChannel channel = channelBuilder | ||
.keepAliveTime(5, TimeUnit.MINUTES) | ||
.build(); | ||
boolean useProtocolV3 = experimentalV3SupportEnvVar | ||
&& serverInfo.getServerFeatures().contains(XDS_V3_SERVER_FEATURE); | ||
|
||
return new XdsChannel(channel, useProtocolV3); | ||
} | ||
}; | ||
|
||
static XdsChannelFactory getInstance() { | ||
return DEFAULT_INSTANCE; | ||
} | ||
|
||
/** | ||
* Creates a channel to one of the provided management servers. | ||
*/ | ||
abstract XdsChannel createChannel(List<ServerInfo> servers); | ||
} | ||
|
||
static final class XdsChannel { | ||
private final ManagedChannel managedChannel; | ||
private final boolean useProtocolV3; | ||
|
@@ -687,8 +623,4 @@ boolean isUseProtocolV3() { | |
return useProtocolV3; | ||
} | ||
} | ||
|
||
interface XdsClientPoolFactory { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More cleanup to be done to put RefCountedXdsClientObjectPool into its own file. |
||
ObjectPool<XdsClient> newXdsClientObjectPool(BootstrapInfo bootstrapInfo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This EDS-only codepath will be deleted in #7391.