-
Notifications
You must be signed in to change notification settings - Fork 4k
xds: deletion only to watchers of same control plane #9896
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4b59a6c
xds: del events to watchers of same control plane
temawi 0a6e34d
Review feedback changes
temawi f18c9d9
Knock it off with all that verify()
temawi a3b120c
Remove extra logging
temawi 627d512
fluent ControlPlaneRule
temawi 35066cc
More review comment changes
temawi 1c1a388
TYPO
temawi 081251f
more test order, verify() shenanigans
temawi 9235944
return XdsClient to the pool
temawi 8364c01
Remove unnecessary XdsClient close()
temawi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
150 changes: 150 additions & 0 deletions
150
xds/src/test/java/io/grpc/xds/XdsClientFederationTest.java
This file contains hidden or 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,150 @@ | ||
| /* | ||
| * Copyright 2023 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 org.mockito.Mockito.timeout; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import io.grpc.internal.ObjectPool; | ||
| import io.grpc.xds.Filter.NamedFilterConfig; | ||
| import io.grpc.xds.XdsClient.ResourceWatcher; | ||
| import io.grpc.xds.XdsListenerResource.LdsUpdate; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| /** | ||
| * Tests for xDS control plane federation scenarios. | ||
| */ | ||
| @RunWith(JUnit4.class) | ||
| public class XdsClientFederationTest { | ||
|
|
||
| @Mock | ||
| private ResourceWatcher<LdsUpdate> mockDirectPathWatcher; | ||
|
|
||
| @Mock | ||
| private ResourceWatcher<LdsUpdate> mockWatcher; | ||
|
|
||
| @Rule | ||
| public ControlPlaneRule trafficdirector = new ControlPlaneRule().setServerHostName("test-server"); | ||
|
|
||
| @Rule | ||
| public ControlPlaneRule directpathPa = new ControlPlaneRule().setServerHostName( | ||
| "xdstp://server-one/envoy.config.listener.v3.Listener/test-server"); | ||
|
|
||
| private ObjectPool<XdsClient> xdsClientPool; | ||
| private XdsClient xdsClient; | ||
| private boolean originalFederationStatus; | ||
|
|
||
| @Before | ||
| public void setUp() throws XdsInitializationException { | ||
| MockitoAnnotations.initMocks(this); | ||
|
|
||
| originalFederationStatus = BootstrapperImpl.enableFederation; | ||
| BootstrapperImpl.enableFederation = true; | ||
|
|
||
| SharedXdsClientPoolProvider clientPoolProvider = new SharedXdsClientPoolProvider(); | ||
| clientPoolProvider.setBootstrapOverride(defaultBootstrapOverride()); | ||
| xdsClientPool = clientPoolProvider.getOrCreate(); | ||
| xdsClient = xdsClientPool.getObject(); | ||
| } | ||
|
|
||
| @After | ||
| public void cleanUp() throws InterruptedException { | ||
| BootstrapperImpl.enableFederation = originalFederationStatus; | ||
| xdsClientPool.returnObject(xdsClient); | ||
| } | ||
|
|
||
| /** | ||
| * Assures that resource deletions happening in one control plane do not trigger deletion events | ||
| * in watchers of resources on other control planes. | ||
| */ | ||
| @Test | ||
| public void isolatedResourceDeletions() throws InterruptedException { | ||
| trafficdirector.setLdsConfig(ControlPlaneRule.buildServerListener(), | ||
| ControlPlaneRule.buildClientListener("test-server")); | ||
| directpathPa.setLdsConfig(ControlPlaneRule.buildServerListener(), | ||
| ControlPlaneRule.buildClientListener( | ||
| "xdstp://server-one/envoy.config.listener.v3.Listener/test-server")); | ||
|
|
||
| xdsClient.watchXdsResource(XdsListenerResource.getInstance(), "test-server", mockWatcher); | ||
| xdsClient.watchXdsResource(XdsListenerResource.getInstance(), | ||
| "xdstp://server-one/envoy.config.listener.v3.Listener/test-server", mockDirectPathWatcher); | ||
|
|
||
| verify(mockWatcher, timeout(2000)).onChanged( | ||
| LdsUpdate.forApiListener( | ||
| HttpConnectionManager.forRdsName(0, "route-config.googleapis.com", ImmutableList.of( | ||
| new NamedFilterConfig("terminal-filter", RouterFilter.ROUTER_CONFIG))))); | ||
| verify(mockDirectPathWatcher, timeout(2000)).onChanged( | ||
| LdsUpdate.forApiListener( | ||
| HttpConnectionManager.forRdsName(0, "route-config.googleapis.com", ImmutableList.of( | ||
| new NamedFilterConfig("terminal-filter", RouterFilter.ROUTER_CONFIG))))); | ||
|
|
||
| // By setting the LDS config with a new server name we effectively make the old server to go | ||
| // away as it is not in the configuration anymore. This change in one control plane (here the | ||
| // "normal TrafficDirector" one) should not trigger an onResourceDoesNotExist() call on a | ||
| // watcher of another control plane (here the DirectPath one). | ||
| trafficdirector.setLdsConfig(ControlPlaneRule.buildServerListener(), | ||
| ControlPlaneRule.buildClientListener("new-server")); | ||
| verify(mockWatcher, timeout(20000)).onResourceDoesNotExist("test-server"); | ||
| verify(mockDirectPathWatcher, times(0)).onResourceDoesNotExist( | ||
| "xdstp://server-one/envoy.config.listener.v3.Listener/test-server"); | ||
| } | ||
|
|
||
| private Map<String, ?> defaultBootstrapOverride() { | ||
| return ImmutableMap.of( | ||
| "node", ImmutableMap.of( | ||
| "id", UUID.randomUUID().toString(), | ||
| "cluster", "cluster0"), | ||
| "xds_servers", ImmutableList.of( | ||
| ImmutableMap.of( | ||
| "server_uri", "localhost:" + trafficdirector.getServer().getPort(), | ||
| "channel_creds", Collections.singletonList( | ||
| ImmutableMap.of("type", "insecure") | ||
| ), | ||
| "server_features", Collections.singletonList("xds_v3") | ||
| ) | ||
| ), | ||
| "authorities", ImmutableMap.of( | ||
| "", ImmutableMap.of(), | ||
| "server-one", ImmutableMap.of( | ||
| "xds_servers", ImmutableList.of( | ||
| ImmutableMap.of( | ||
| "server_uri", "localhost:" + directpathPa.getServer().getPort(), | ||
| "channel_creds", Collections.singletonList( | ||
| ImmutableMap.of("type", "insecure") | ||
| ), | ||
| "server_features", Collections.singletonList("xds_v3") | ||
| ) | ||
| ) | ||
| ), | ||
| "server-two", ImmutableMap.of() | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.