xds: make channel creds required in bootstrap file#7396
Conversation
| String type = JsonUtil.getString(channelCreds, "type"); | ||
| if (type == null) { | ||
| throw new IOException("Invalid bootstrap: 'xds_servers' contains server with " | ||
| + "unknown type 'channel_creds'."); |
There was a problem hiding this comment.
This is the case of type not being set as opposed to "unknown type".
There was a problem hiding this comment.
What I mean here is for "type unspecified". Reading bootstrap file should not contain the logic for interpreting the type that gRPC supports, that should be done at the time when the channel creds is actually used.
Say the bootstrap file provides 100 channel creds options, the parser should not try to look up and check one by one. Only at the time this information is used, it would interpret it: going through the list to find the first one that gRPC supports. If none can be found, the gRPC client fails.
There was a problem hiding this comment.
It's confusing to see "unknown type" while type not provided.
"unknown type" sounds more like user provides a type but it's not recognized.
"with type unspecified" might be more clear.
There was a problem hiding this comment.
Sure, fixed the message.
| logger.log(XdsLogLevel.INFO, "Channel credentials option: {0}", type); | ||
| ChannelCreds creds = new ChannelCreds(type, JsonUtil.getObject(channelCreds, "config")); | ||
| channelCredsOptions.add(creds); | ||
| if (rawChannelCredsList == null) { |
There was a problem hiding this comment.
How about?
if (rawChannelCredsList == null || rawChannelCredsList.isEmpty())
There was a problem hiding this comment.
Sounds fair. Updated to not allow empty list.
|
I came across trying to slightly modify the parsing logic (e.g., require the This usage is very weird. You should just create a fake /cc @sanjaypujare |
Instead of making it a parsing check, you can make it a post parsing check of the parsed BootstrapInfo object. Isn't that the right thing to do?
Most tests in
|
Currently it is a post-parsing check: the resolver returns an error to the channel if it finds no xDS server to use when creating the XdsClient, after reading the bootstrap file. Since checking if
Tests in If you fixed your tests to not depend on how |
Mandatory fields etc should be semantic checks instead of syntax check for various reasons (e.g. you can reuse the logic for non-JSON input if-and-when needed) where the syntax checks should be limited to JSON syntax and JSON schema validation.
Yes I get the point and I'll modify the code to not use |
No, it's not. We are fine with existing changes in this PR. I just mean requiring |
This PR only adds validation to the bootstrap file to require users specify at least one channel creds configuration.
In a following up PR, creating the xDS channel will select the first supported channel creds and fail (e.g., an exception thrown) to create the channel if none is supported (instead of failing back to use parent channel's channel creds). Need to clean up the interfaces for creating XdsClient/Channel.
Also, Ideally I am thinking about having a
BootstrapException. UsingIOExceptionis not accurate here.