From b5df3ee3982ee5210a785cab701e17ad8195d62c Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 3 Feb 2020 09:19:13 -0800 Subject: [PATCH] XdsClient: Generate error message when no supported creds types found. --- .../filters/client_channel/xds/xds_channel.cc | 3 ++- .../filters/client_channel/xds/xds_channel.h | 4 ++- .../client_channel/xds/xds_channel_secure.cc | 9 +++++-- .../filters/client_channel/xds/xds_client.cc | 26 +++++++++++-------- .../filters/client_channel/xds/xds_client.h | 3 +-- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/core/ext/filters/client_channel/xds/xds_channel.cc b/src/core/ext/filters/client_channel/xds/xds_channel.cc index d30cee047c9..a323e56dcc1 100644 --- a/src/core/ext/filters/client_channel/xds/xds_channel.cc +++ b/src/core/ext/filters/client_channel/xds/xds_channel.cc @@ -29,7 +29,8 @@ grpc_channel_args* ModifyXdsChannelArgs(grpc_channel_args* args) { } grpc_channel* CreateXdsChannel(const XdsBootstrap& bootstrap, - const grpc_channel_args& args) { + const grpc_channel_args& args, + grpc_error** error) { if (!bootstrap.server().channel_creds.empty()) return nullptr; return grpc_insecure_channel_create(bootstrap.server().server_uri.c_str(), &args, nullptr); diff --git a/src/core/ext/filters/client_channel/xds/xds_channel.h b/src/core/ext/filters/client_channel/xds/xds_channel.h index e2f1f102e00..f78c0ba9dd0 100644 --- a/src/core/ext/filters/client_channel/xds/xds_channel.h +++ b/src/core/ext/filters/client_channel/xds/xds_channel.h @@ -24,6 +24,7 @@ #include #include "src/core/ext/filters/client_channel/xds/xds_bootstrap.h" +#include "src/core/lib/iomgr/error.h" namespace grpc_core { @@ -36,7 +37,8 @@ namespace grpc_core { grpc_channel_args* ModifyXdsChannelArgs(grpc_channel_args* args); grpc_channel* CreateXdsChannel(const XdsBootstrap& bootstrap, - const grpc_channel_args& args); + const grpc_channel_args& args, + grpc_error** error); } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc b/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc index 56a55096de7..52d226ce74b 100644 --- a/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +++ b/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc @@ -64,7 +64,8 @@ grpc_channel_args* ModifyXdsChannelArgs(grpc_channel_args* args) { } grpc_channel* CreateXdsChannel(const XdsBootstrap& bootstrap, - const grpc_channel_args& args) { + const grpc_channel_args& args, + grpc_error** error) { grpc_channel_credentials* creds = nullptr; RefCountedPtr creds_to_unref; if (!bootstrap.server().channel_creds.empty()) { @@ -77,7 +78,11 @@ grpc_channel* CreateXdsChannel(const XdsBootstrap& bootstrap, break; } } - if (creds == nullptr) return nullptr; + if (creds == nullptr) { + *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "no supported credential types found"); + return nullptr; + } creds_to_unref.reset(creds); } else { creds = grpc_channel_credentials_find_in_args(&args); diff --git a/src/core/ext/filters/client_channel/xds/xds_client.cc b/src/core/ext/filters/client_channel/xds/xds_client.cc index ad3fcad37c9..ee965c01ee5 100644 --- a/src/core/ext/filters/client_channel/xds/xds_client.cc +++ b/src/core/ext/filters/client_channel/xds/xds_client.cc @@ -472,12 +472,10 @@ grpc_channel_args* BuildXdsChannelArgs(const grpc_channel_args& args) { } // namespace XdsClient::ChannelState::ChannelState(RefCountedPtr xds_client, - const grpc_channel_args& args) + grpc_channel* channel) : InternallyRefCounted(&grpc_xds_client_trace), - xds_client_(std::move(xds_client)) { - grpc_channel_args* new_args = BuildXdsChannelArgs(args); - channel_ = CreateXdsChannel(*xds_client_->bootstrap_, *new_args); - grpc_channel_args_destroy(new_args); + xds_client_(std::move(xds_client)), + channel_(channel) { GPR_ASSERT(channel_ != nullptr); StartConnectivityWatchLocked(); } @@ -1727,18 +1725,24 @@ XdsClient::XdsClient(Combiner* combiner, grpc_pollset_set* interested_parties, server_name_(server_name), service_config_watcher_(std::move(watcher)) { if (*error != GRPC_ERROR_NONE) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { - gpr_log(GPR_INFO, "[xds_client %p: failed to read bootstrap file: %s", - this, grpc_error_string(*error)); - } + gpr_log(GPR_ERROR, "[xds_client %p] failed to read bootstrap file: %s", + this, grpc_error_string(*error)); return; } if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { - gpr_log(GPR_INFO, "[xds_client %p: creating channel to %s", this, + gpr_log(GPR_INFO, "[xds_client %p] creating channel to %s", this, bootstrap_->server().server_uri.c_str()); } + grpc_channel_args* new_args = BuildXdsChannelArgs(channel_args); + grpc_channel* channel = CreateXdsChannel(*bootstrap_, *new_args, error); + grpc_channel_args_destroy(new_args); + if (*error != GRPC_ERROR_NONE) { + gpr_log(GPR_ERROR, "[xds_client %p] failed to create xds channel: %s", this, + grpc_error_string(*error)); + return; + } chand_ = MakeOrphanable( - Ref(DEBUG_LOCATION, "XdsClient+ChannelState"), channel_args); + Ref(DEBUG_LOCATION, "XdsClient+ChannelState"), channel); if (service_config_watcher_ != nullptr) { chand_->Subscribe(kLdsTypeUrl, std::string(server_name)); } diff --git a/src/core/ext/filters/client_channel/xds/xds_client.h b/src/core/ext/filters/client_channel/xds/xds_client.h index 0552440cd8c..4cf4bc8222e 100644 --- a/src/core/ext/filters/client_channel/xds/xds_client.h +++ b/src/core/ext/filters/client_channel/xds/xds_client.h @@ -134,8 +134,7 @@ class XdsClient : public InternallyRefCounted { class AdsCallState; class LrsCallState; - ChannelState(RefCountedPtr xds_client, - const grpc_channel_args& args); + ChannelState(RefCountedPtr xds_client, grpc_channel* channel); ~ChannelState(); void Orphan() override;