-
Notifications
You must be signed in to change notification settings - Fork 992
Introduce an extension point for specifying custom ConfigSource
#6747
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 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
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
153 changes: 153 additions & 0 deletions
153
it/xds-client/src/test/java/com/linecorp/armeria/xds/it/PathConfigSourceTest.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,153 @@ | ||
| /* | ||
| * Copyright 2026 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you 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: | ||
| * | ||
| * https://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 com.linecorp.armeria.xds.it; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.awaitility.Awaitility.await; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| import com.linecorp.armeria.xds.ClusterSnapshot; | ||
| import com.linecorp.armeria.xds.SnapshotWatcher; | ||
| import com.linecorp.armeria.xds.XdsBootstrap; | ||
|
|
||
| import io.envoyproxy.envoy.config.bootstrap.v3.Bootstrap; | ||
|
|
||
| class PathConfigSourceTest { | ||
|
|
||
| @TempDir | ||
| Path tempDir; | ||
|
|
||
| @Test | ||
| void clusterFromJsonPathConfigSource() throws Exception { | ||
| //language=JSON | ||
| final String json = """ | ||
| { | ||
| "typeUrl": "type.googleapis.com/envoy.config.cluster.v3.Cluster", | ||
| "resources": [ | ||
| { | ||
| "@type": "type.googleapis.com/envoy.config.cluster.v3.Cluster", | ||
| "name": "path-cluster", | ||
| "type": "STATIC", | ||
| "loadAssignment": { | ||
| "clusterName": "path-cluster", | ||
| "endpoints": [ | ||
| { | ||
| "lbEndpoints": [ | ||
| { | ||
| "endpoint": { | ||
| "address": { | ||
| "socketAddress": { | ||
| "address": "127.0.0.1", | ||
| "portValue": 8080 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "versionInfo": "1" | ||
| } | ||
| """; | ||
|
|
||
| final Path targetFile = tempDir.resolve("clusters.json"); | ||
| Files.writeString(targetFile, json); | ||
|
|
||
| //language=YAML | ||
| final String bootstrapYaml = | ||
| """ | ||
| dynamic_resources: | ||
| cds_config: | ||
| path_config_source: | ||
| path: %s | ||
| """.formatted(targetFile); | ||
|
|
||
| verifyClusterFromPathConfigSource(bootstrapYaml); | ||
| } | ||
|
|
||
| @Test | ||
| void clusterFromYamlPathConfigSource() throws Exception { | ||
| //language=YAML | ||
| final String yaml = """ | ||
| typeUrl: "type.googleapis.com/envoy.config.cluster.v3.Cluster" | ||
| resources: | ||
| - "@type": "type.googleapis.com/envoy.config.cluster.v3.Cluster" | ||
| name: path-cluster | ||
| type: STATIC | ||
| loadAssignment: | ||
| clusterName: path-cluster | ||
| endpoints: | ||
| - lbEndpoints: | ||
| - endpoint: | ||
| address: | ||
| socketAddress: | ||
| address: 127.0.0.1 | ||
| portValue: 8080 | ||
| versionInfo: "1" | ||
| """; | ||
|
|
||
| final Path targetFile = tempDir.resolve("clusters.yaml"); | ||
| Files.writeString(targetFile, yaml); | ||
|
|
||
| //language=YAML | ||
| final String bootstrapYaml = | ||
| """ | ||
| dynamic_resources: | ||
| cds_config: | ||
| path_config_source: | ||
| path: %s | ||
| """.formatted(targetFile); | ||
|
|
||
| verifyClusterFromPathConfigSource(bootstrapYaml); | ||
| } | ||
|
|
||
| private static void verifyClusterFromPathConfigSource(String bootstrapYaml) { | ||
| final Bootstrap bootstrap = XdsResourceReader.fromYaml(bootstrapYaml, Bootstrap.class); | ||
| final AtomicReference<ClusterSnapshot> snapshotRef = new AtomicReference<>(); | ||
| final AtomicReference<Throwable> errorRef = new AtomicReference<>(); | ||
| final SnapshotWatcher<Object> watcher = (snapshot, t) -> { | ||
| if (t != null) { | ||
| errorRef.set(t); | ||
| return; | ||
| } | ||
| if (snapshot instanceof ClusterSnapshot) { | ||
| snapshotRef.set((ClusterSnapshot) snapshot); | ||
| } | ||
| }; | ||
|
|
||
| try (XdsBootstrap xdsBootstrap = XdsBootstrap.builder(bootstrap) | ||
| .defaultSnapshotWatcher(watcher) | ||
| .build()) { | ||
| xdsBootstrap.clusterRoot("path-cluster"); | ||
| await().untilAsserted(() -> { | ||
| assertThat(errorRef.get()).isNull(); | ||
| assertThat(snapshotRef.get()).isNotNull(); | ||
| assertThat(snapshotRef.get().xdsResource().resource().getName()) | ||
| .isEqualTo("path-cluster"); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
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,12 @@ | ||
| dependencies { | ||
| // Use the vanilla java-control-plane api protos instead of Armeria's xds-api. | ||
| // This verifies that the xds module works when custom_config_source is not present. | ||
| configurations.configureEach { | ||
| exclude group: 'com.linecorp.armeria', module: 'xds-api' | ||
| } | ||
|
|
||
| testImplementation project(':xds') | ||
| testImplementation libs.controlplane.server | ||
| testImplementation libs.controlplane.cache | ||
| testImplementation libs.protobuf.java.util | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.