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
Changes from 3 commits
ee89f3e
603d929
612b791
a332d2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 static com.google.common.base.Preconditions.checkArgument; | ||
|
||
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 { | ||
checkArgument(!servers.isEmpty(), "No management server provided."); | ||
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. Might as well throw XdsInitializationException? 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. Sure. Fixed. |
||
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; | ||
} |
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); | ||
} | ||
} |
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.