Skip to content

Commit

Permalink
xds: Return a null RouteAction when cluster has no cluster_specifier …
Browse files Browse the repository at this point in the history
…or route lookup is not enabled with a cluster_specifier_plugin.

We want to ignore the route in these situations, which is achieved by returning a null. The current behavior of returning an error triggers a NACK to the update.
  • Loading branch information
temawi committed Mar 24, 2022
1 parent 700afaf commit 6c00f00
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions xds/src/main/java/io/grpc/xds/ClientXdsClient.java
Expand Up @@ -1340,12 +1340,11 @@ static StructOrError<RouteAction> parseRouteAction(
return StructOrError.fromStruct(RouteAction.forClusterSpecifierPlugin(
namedPluginConfig, hashPolicies, timeoutNano, retryPolicy));
} else {
return StructOrError.fromError("Support for ClusterSpecifierPlugin not enabled");
return null;
}
case CLUSTERSPECIFIER_NOT_SET:
default:
return StructOrError.fromError(
"Unknown cluster specifier: " + proto.getClusterSpecifierCase());
return null;
}
}

Expand Down
25 changes: 25 additions & 0 deletions xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java
Expand Up @@ -17,6 +17,7 @@
package io.grpc.xds;

import static com.google.common.truth.Truth.assertThat;
import static io.envoyproxy.envoy.config.route.v3.RouteAction.ClusterSpecifierCase.CLUSTER_SPECIFIER_PLUGIN;

import com.github.udpa.udpa.type.v1.TypedStruct;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -801,6 +802,30 @@ public void parseRouteAction_withHashPolicies() {
assertThat(policies.get(1).isTerminal()).isFalse();
}

@Test
public void parseRouteAction_clusterSpecifier_routeLookupDisabled() {
ClientXdsClient.enableRouteLookup = false;
io.envoyproxy.envoy.config.route.v3.RouteAction proto =
io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder()
.setClusterSpecifierPlugin(CLUSTER_SPECIFIER_PLUGIN.name())
.build();
StructOrError<RouteAction> struct =
ClientXdsClient.parseRouteAction(proto, filterRegistry, false,
ImmutableMap.<String, PluginConfig>of());
assertThat(struct).isNull();
}

@Test
public void parseRouteAction_custerSpecifierNotSet() {
io.envoyproxy.envoy.config.route.v3.RouteAction proto =
io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder()
.build();
StructOrError<RouteAction> struct =
ClientXdsClient.parseRouteAction(proto, filterRegistry, false,
ImmutableMap.<String, PluginConfig>of());
assertThat(struct).isNull();
}

@Test
public void parseClusterWeight() {
io.envoyproxy.envoy.config.route.v3.WeightedCluster.ClusterWeight proto =
Expand Down

0 comments on commit 6c00f00

Please sign in to comment.