bazel: Use jarjar to avoid xds deps (#12243)

Avoiding so many deps will allow us to upgrade the protos without being
forced to upgrade to protobuf-java 4.x. It also removes the remaining
non-bzlmod dependencies.

It'd be really easy to get this wrong, so we do two things 1) mirror the
gradle configuration as much as possible, as that sees a lot of testing,
and 2) run the fake control plane with the _results_ of jarjar. There's
lots of classes that we could mess up, but that at least kicks the tires.

XdsTestUtils.buildRouteConfiguration() was moved to ControlPlaneRule to
stop the unnecessary circular dependency between the classes and to
avoid the many dependencies of XdsTestUtils.

I'm totally hacking java_grpc_library to improve the dependency
situation. Long-term, I think we will stop building Java libraries with
Bazel and require users to rely entirely on Maven Central. That seems to
be the direction Bazel is going and it will greatly simplify the
problems we've seen with protobuf having a single repository for many
languages. So while the hack isn't too bad, I hope we won't have to live
with it long-term.
This commit is contained in:
Eric Anderson 2025-07-28 00:00:39 -07:00 committed by GitHub
parent 42e1829b37
commit 8f09b96899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 384 additions and 192 deletions

View File

@ -102,6 +102,9 @@ jobs:
- name: Run bazel build
run: bazelisk build //... --enable_bzlmod=${{ matrix.bzlmod }}
- name: Run bazel test
run: bazelisk test //... --enable_bzlmod=${{ matrix.bzlmod }}
- name: Run example bazel build
run: bazelisk build //... --enable_bzlmod=${{ matrix.bzlmod }}
working-directory: ./examples

View File

@ -46,36 +46,16 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
]
# GRPC_DEPS_END
bazel_dep(name = "bazel_jar_jar", version = "0.1.7")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "googleapis", repo_name = "com_google_googleapis", version = "0.0.0-20240326-1c8d509c5")
# CEL Spec may be removed when cncf/xds MODULE is no longer using protobuf 27.x
bazel_dep(name = "cel-spec", repo_name = "dev_cel", version = "0.15.0")
bazel_dep(name = "grpc", repo_name = "com_github_grpc_grpc", version = "1.56.3.bcr.1")
bazel_dep(name = "grpc-proto", repo_name = "io_grpc_grpc_proto", version = "0.0.0-20240627-ec30f58")
bazel_dep(name = "protobuf", repo_name = "com_google_protobuf", version = "23.1")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_java", version = "5.3.5")
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.46.0")
bazel_dep(name = "rules_jvm_external", version = "6.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
non_module_deps = use_extension("//:repositories.bzl", "grpc_java_repositories_extension")
use_repo(
non_module_deps,
"com_github_cncf_xds",
"envoy_api",
)
grpc_repo_deps_ext = use_extension("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_repo_deps_ext")
use_repo(
grpc_repo_deps_ext,
"com_envoyproxy_protoc_gen_validate",
"opencensus_proto",
)
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
@ -202,7 +182,3 @@ maven.override(
coordinates = "io.grpc:grpc-util",
target = "@io_grpc_grpc_java//util",
)
switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)

View File

@ -22,20 +22,19 @@ load("//:repositories.bzl", "grpc_java_repositories")
grpc_java_repositories()
load("@bazel_jar_jar//:jar_jar.bzl", "jar_jar_repositories")
jar_jar_repositories()
load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
load("@envoy_api//bazel:repositories.bzl", "api_dependencies")
api_dependencies()
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
name = "com_google_googleapis_imports",
java = True,
)
maven_install(

View File

@ -18,6 +18,7 @@ cc_binary(
java_library(
name = "java_grpc_library_deps__do_not_reference",
visibility = ["//xds:__pkg__"],
exports = [
"//api",
"//protobuf",

View File

@ -11,10 +11,6 @@ local_path_override(
path = "..",
)
switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
use_repo(maven, "maven")

View File

@ -28,6 +28,10 @@ load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
grpc_java_repositories()
load("@bazel_jar_jar//:jar_jar.bzl", "jar_jar_repositories")
jar_jar_repositories()
# Protobuf now requires C++14 or higher, which requires Bazel configuration
# outside the WORKSPACE. See .bazelrc in this directory.
load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS")
@ -35,15 +39,10 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
load("@envoy_api//bazel:repositories.bzl", "api_dependencies")
api_dependencies()
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
name = "com_google_googleapis_imports",
java = True,
)
maven_install(

View File

@ -147,6 +147,33 @@ _java_grpc_library = rule(
implementation = _java_rpc_library_impl,
)
# A copy of _java_grpc_library, except with a neverlink=1 _toolchain
INTERNAL_java_grpc_library_for_xds = rule(
attrs = {
"srcs": attr.label_list(
mandatory = True,
allow_empty = False,
providers = [ProtoInfo],
),
"deps": attr.label_list(
mandatory = True,
allow_empty = False,
providers = [JavaInfo],
),
"_toolchain": attr.label(
default = Label("//xds:java_grpc_library_toolchain"),
),
},
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"],
fragments = ["java"],
outputs = {
"jar": "lib%{name}.jar",
"srcjar": "lib%{name}-src.jar",
},
provides = [JavaInfo],
implementation = _java_rpc_library_impl,
)
_java_lite_grpc_library = rule(
attrs = {
"srcs": attr.label_list(

View File

@ -87,38 +87,11 @@ IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS = {
"io.grpc:grpc-util": "@io_grpc_grpc_java//util",
}
def grpc_java_repositories(bzlmod = False):
def grpc_java_repositories():
"""Imports dependencies for grpc-java."""
if not bzlmod and not native.existing_rule("dev_cel"):
http_archive(
name = "dev_cel",
strip_prefix = "cel-spec-0.15.0",
sha256 = "3ee09eb69dbe77722e9dee23dc48dc2cd9f765869fcf5ffb1226587c81791a0b",
urls = [
"https://github.com/google/cel-spec/archive/refs/tags/v0.15.0.tar.gz",
],
)
if not native.existing_rule("com_github_cncf_xds"):
http_archive(
name = "com_github_cncf_xds",
strip_prefix = "xds-2ac532fd44436293585084f8d94c6bdb17835af0",
sha256 = "790c4c83b6950bb602fec221f6a529d9f368cdc8852aae7d2592d0d04b015f37",
urls = [
"https://github.com/cncf/xds/archive/2ac532fd44436293585084f8d94c6bdb17835af0.tar.gz",
],
)
if not bzlmod and not native.existing_rule("com_github_grpc_grpc"):
http_archive(
name = "com_github_grpc_grpc",
strip_prefix = "grpc-1.46.0",
sha256 = "67423a4cd706ce16a88d1549297023f0f9f0d695a96dd684adc21e67b021f9bc",
urls = [
"https://github.com/grpc/grpc/archive/v1.46.0.tar.gz",
],
)
if not bzlmod and not native.existing_rule("com_google_protobuf"):
if not native.existing_rule("com_google_protobuf"):
com_google_protobuf()
if not bzlmod and not native.existing_rule("com_google_googleapis"):
if not native.existing_rule("com_google_googleapis"):
http_archive(
name = "com_google_googleapis",
sha256 = "49930468563dd48283e8301e8d4e71436bf6d27ac27c235224cc1a098710835d",
@ -127,25 +100,14 @@ def grpc_java_repositories(bzlmod = False):
"https://github.com/googleapis/googleapis/archive/ca1372c6d7bcb199638ebfdb40d2b2660bab7b88.tar.gz",
],
)
if not bzlmod and not native.existing_rule("io_bazel_rules_go"):
http_archive(
name = "io_bazel_rules_go",
sha256 = "ab21448cef298740765f33a7f5acee0607203e4ea321219f2a4c85a6e0fb0a27",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.32.0/rules_go-v0.32.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.32.0/rules_go-v0.32.0.zip",
],
)
if not native.existing_rule("io_grpc_grpc_proto"):
io_grpc_grpc_proto()
if not native.existing_rule("envoy_api"):
if not native.existing_rule("bazel_jar_jar"):
http_archive(
name = "envoy_api",
sha256 = "ecf71817233eba19cc8b4ee14e126ffd5838065d5b5a92b2506258a42ac55199",
strip_prefix = "data-plane-api-0bc95493c5e88b7b07e62758d23b39341813a827",
urls = [
"https://github.com/envoyproxy/data-plane-api/archive/0bc95493c5e88b7b07e62758d23b39341813a827.tar.gz",
],
name = "bazel_jar_jar",
sha256 = "3117f913c732142a795551f530d02c9157b9ea895e6b2de0fbb5af54f03040a5",
strip_prefix = "bazel_jar_jar-0.1.6",
url = "https://github.com/bazeltools/bazel_jar_jar/releases/download/v0.1.6/bazel_jar_jar-v0.1.6.tar.gz",
)
def com_google_protobuf():
@ -166,8 +128,3 @@ def io_grpc_grpc_proto():
strip_prefix = "grpc-proto-4f245d272a28a680606c0739753506880cf33b5f",
urls = ["https://github.com/grpc/grpc-proto/archive/4f245d272a28a680606c0739753506880cf33b5f.zip"],
)
def _grpc_java_repositories_extension(_):
grpc_java_repositories(bzlmod = True)
grpc_java_repositories_extension = module_extension(implementation = _grpc_java_repositories_extension)

20
testing-proto/BUILD.bazel Normal file
View File

@ -0,0 +1,20 @@
load("//:java_grpc_library.bzl", "java_grpc_library")
proto_library(
name = "simpleservice_proto",
srcs = ["src/main/proto/io/grpc/testing/protobuf/simpleservice.proto"],
strip_import_prefix = "src/main/proto/",
)
java_proto_library(
name = "simpleservice_java_proto",
visibility = ["//xds:__pkg__"],
deps = [":simpleservice_proto"],
)
java_grpc_library(
name = "simpleservice_java_grpc",
srcs = [":simpleservice_proto"],
visibility = ["//xds:__pkg__"],
deps = [":simpleservice_java_proto"],
)

View File

@ -1,5 +1,6 @@
load("@bazel_jar_jar//:jar_jar.bzl", "jar_jar")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:java_grpc_library.bzl", "java_grpc_library")
load("//:java_grpc_library.bzl", "INTERNAL_java_grpc_library_for_xds", "java_grpc_library", "java_rpc_toolchain")
# Mirrors the dependencies included in the artifact on Maven Central for usage
# with maven_install's override_targets. Should only be used as a dep for
@ -13,25 +14,11 @@ java_library(
],
)
# Ordinary deps for :xds
java_library(
name = "xds",
srcs = glob(
[
"src/main/java/**/*.java",
"third_party/zero-allocation-hashing/main/java/**/*.java",
],
exclude = ["src/main/java/io/grpc/xds/orca/**"],
),
resources = glob([
"src/main/resources/**",
]),
visibility = ["//visibility:public"],
deps = [
":envoy_service_discovery_v3_java_grpc",
":envoy_service_load_stats_v3_java_grpc",
":envoy_service_status_v3_java_grpc",
name = "xds_deps_depend",
exports = [
":orca",
":xds_protos_java",
"//:auto_value_annotations",
"//alts",
"//api",
@ -43,7 +30,6 @@ java_library(
"//services:metrics_internal",
"//stub",
"//util",
"@com_google_googleapis//google/rpc:rpc_java_proto",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@maven//:com_google_auth_google_auth_library_oauth2_http",
@ -58,70 +44,89 @@ java_library(
artifact("io.netty:netty-handler"),
artifact("io.netty:netty-transport"),
],
)
java_proto_library(
name = "xds_protos_java",
deps = [
"@com_github_cncf_xds//udpa/type/v1:pkg",
"@com_github_cncf_xds//xds/type/v3:pkg",
"@envoy_api//envoy/admin/v3:pkg",
"@envoy_api//envoy/config/cluster/v3:pkg",
"@envoy_api//envoy/config/core/v3:pkg",
"@envoy_api//envoy/config/endpoint/v3:pkg",
"@envoy_api//envoy/config/listener/v3:pkg",
"@envoy_api//envoy/config/rbac/v3:pkg",
"@envoy_api//envoy/config/route/v3:pkg",
"@envoy_api//envoy/extensions/clusters/aggregate/v3:pkg",
"@envoy_api//envoy/extensions/filters/common/fault/v3:pkg",
"@envoy_api//envoy/extensions/filters/http/fault/v3:pkg",
"@envoy_api//envoy/extensions/filters/http/gcp_authn/v3:pkg",
"@envoy_api//envoy/extensions/filters/http/rbac/v3:pkg",
"@envoy_api//envoy/extensions/filters/http/router/v3:pkg",
"@envoy_api//envoy/extensions/filters/network/http_connection_manager/v3:pkg",
"@envoy_api//envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3:pkg",
"@envoy_api//envoy/extensions/load_balancing_policies/least_request/v3:pkg",
"@envoy_api//envoy/extensions/load_balancing_policies/pick_first/v3:pkg",
"@envoy_api//envoy/extensions/load_balancing_policies/ring_hash/v3:pkg",
"@envoy_api//envoy/extensions/load_balancing_policies/round_robin/v3:pkg",
"@envoy_api//envoy/extensions/load_balancing_policies/wrr_locality/v3:pkg",
"@envoy_api//envoy/extensions/transport_sockets/http_11_proxy/v3:pkg",
"@envoy_api//envoy/extensions/transport_sockets/tls/v3:pkg",
"@envoy_api//envoy/service/discovery/v3:pkg",
"@envoy_api//envoy/service/load_stats/v3:pkg",
"@envoy_api//envoy/service/status/v3:pkg",
"@envoy_api//envoy/type/matcher/v3:pkg",
"@envoy_api//envoy/type/v3:pkg",
runtime_deps = [
"//compiler:java_grpc_library_deps__do_not_reference",
],
)
java_grpc_library(
name = "envoy_service_discovery_v3_java_grpc",
srcs = ["@envoy_api//envoy/service/discovery/v3:pkg"],
deps = [":xds_protos_java"],
java_library(
name = "xds_deps_depend_neverlink",
neverlink = 1,
exports = [":xds_deps_depend"],
)
java_grpc_library(
name = "envoy_service_load_stats_v3_java_grpc",
srcs = ["@envoy_api//envoy/service/load_stats/v3:pkg"],
deps = [":xds_protos_java"],
# Deps to be combined into the :xds jar itself
java_library(
name = "xds_deps_embed",
exports = [
":envoy_java_grpc",
":envoy_java_proto",
":googleapis_rpc_java_proto",
":xds_java_proto",
],
)
java_grpc_library(
name = "envoy_service_status_v3_java_grpc",
srcs = ["@envoy_api//envoy/service/status/v3:pkg"],
deps = [":xds_protos_java"],
java_binary(
name = "xds_notjarjar",
srcs = glob(
[
"src/main/java/**/*.java",
"third_party/zero-allocation-hashing/main/java/**/*.java",
],
exclude = ["src/main/java/io/grpc/xds/orca/**"],
),
main_class = "unused",
resources = glob([
"src/main/resources/**",
]),
deps = [
# Do not add additional dependencies here; add them to one of these two deps instead
":xds_deps_depend_neverlink",
":xds_deps_embed",
],
)
JAR_JAR_RULES = [
"zap com.google.protobuf.**", # Drop codegen dep
# Keep in sync with build.gradle's shadowJar
"rule com.github.udpa.** io.grpc.xds.shaded.com.github.udpa.@1",
"rule com.github.xds.** io.grpc.xds.shaded.com.github.xds.@1",
"rule com.google.api.expr.** io.grpc.xds.shaded.com.google.api.expr.@1",
"rule com.google.security.** io.grpc.xds.shaded.com.google.security.@1",
"rule dev.cel.expr.** io.grpc.xds.shaded.dev.cel.expr.@1",
"rule envoy.annotations.** io.grpc.xds.shaded.envoy.annotations.@1",
"rule io.envoyproxy.** io.grpc.xds.shaded.io.envoyproxy.@1",
"rule udpa.annotations.** io.grpc.xds.shaded.udpa.annotations.@1",
"rule xds.annotations.** io.grpc.xds.shaded.xds.annotations.@1",
]
jar_jar(
name = "xds_jarjar",
inline_rules = JAR_JAR_RULES,
input_jar = ":xds_notjarjar_deploy.jar",
)
java_library(
name = "orca",
srcs = glob([
"src/main/java/io/grpc/xds/orca/*.java",
]),
name = "xds",
visibility = ["//visibility:public"],
exports = [":xds_jarjar"],
runtime_deps = [":xds_deps_depend"],
)
java_proto_library(
name = "googleapis_rpc_java_proto",
deps = [
":orca_protos_java",
":xds_service_orca_v3_java_grpc",
"@com_google_googleapis//google/rpc:code_proto",
"@com_google_googleapis//google/rpc:status_proto",
],
)
# Ordinary deps for :orca
java_library(
name = "orca_deps_depend",
exports = [
":xds_orca_java_grpc",
":xds_orca_java_proto",
"//api",
"//context",
"//core:internal",
@ -136,16 +141,222 @@ java_library(
],
)
java_proto_library(
name = "orca_protos_java",
deps = [
"@com_github_cncf_xds//xds/data/orca/v3:pkg",
"@com_github_cncf_xds//xds/service/orca/v3:pkg",
java_library(
name = "orca_deps_depend_neverlink",
neverlink = 1,
exports = [":orca_deps_depend"],
)
# Deps to be combined into the :orca jar itself
java_library(
name = "orca_deps_embed",
exports = [
":xds_orca_java_grpc",
":xds_orca_java_proto",
],
)
java_grpc_library(
name = "xds_service_orca_v3_java_grpc",
srcs = ["@com_github_cncf_xds//xds/service/orca/v3:pkg"],
deps = [":orca_protos_java"],
java_binary(
name = "orca_notjarjar",
srcs = glob([
"src/main/java/io/grpc/xds/orca/*.java",
]),
main_class = "unused",
visibility = ["//visibility:public"],
deps = [
# Do not add additional dependencies here; add them to one of these two deps instead
":orca_deps_depend_neverlink",
":orca_deps_embed",
],
)
jar_jar(
name = "orca_jarjar",
inline_rules = JAR_JAR_RULES,
input_jar = ":orca_notjarjar_deploy.jar",
)
java_library(
name = "orca",
visibility = ["//visibility:public"],
exports = [":orca_jarjar"],
runtime_deps = [":orca_deps_depend"],
)
java_proto_library(
name = "orca_java_proto",
deps = [":xds_proto"],
)
java_grpc_library(
name = "orca_java_grpc",
srcs = [":xds_proto"],
deps = [":orca_java_proto"],
)
proto_library(
name = "cel_spec_proto",
srcs = glob(["third_party/cel-spec/src/main/proto/**/*.proto"]),
strip_import_prefix = "third_party/cel-spec/src/main/proto/",
deps = [
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
proto_library(
name = "envoy_proto",
srcs = glob(["third_party/envoy/src/main/proto/**/*.proto"]),
strip_import_prefix = "third_party/envoy/src/main/proto/",
deps = [
":googleapis_proto",
":protoc_gen_validate_proto",
":xds_proto",
"@com_google_googleapis//google/api:annotations_proto",
"@com_google_googleapis//google/rpc:status_proto",
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:wrappers_proto",
],
)
java_proto_library(
name = "envoy_java_proto",
deps = [":envoy_proto"],
)
INTERNAL_java_grpc_library_for_xds(
name = "envoy_java_grpc",
srcs = [":envoy_proto"],
deps = [":envoy_java_proto"],
)
proto_library(
name = "googleapis_proto",
srcs = glob(["third_party/googleapis/src/main/proto/**/*.proto"]),
strip_import_prefix = "third_party/googleapis/src/main/proto/",
deps = [
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
proto_library(
name = "protoc_gen_validate_proto",
srcs = glob(["third_party/protoc-gen-validate/src/main/proto/**/*.proto"]),
strip_import_prefix = "third_party/protoc-gen-validate/src/main/proto/",
deps = [
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
proto_library(
name = "xds_proto",
srcs = glob(
["third_party/xds/src/main/proto/**/*.proto"],
exclude = [
"third_party/xds/src/main/proto/xds/data/orca/v3/*.proto",
"third_party/xds/src/main/proto/xds/service/orca/v3/*.proto",
],
),
strip_import_prefix = "third_party/xds/src/main/proto/",
deps = [
":cel_spec_proto",
":googleapis_proto",
":protoc_gen_validate_proto",
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:wrappers_proto",
],
)
java_proto_library(
name = "xds_java_proto",
deps = [":xds_proto"],
)
proto_library(
name = "xds_orca_proto",
srcs = glob([
"third_party/xds/src/main/proto/xds/data/orca/v3/*.proto",
"third_party/xds/src/main/proto/xds/service/orca/v3/*.proto",
]),
strip_import_prefix = "third_party/xds/src/main/proto/",
deps = [
":protoc_gen_validate_proto",
"@com_google_protobuf//:duration_proto",
],
)
java_proto_library(
name = "xds_orca_java_proto",
deps = [":xds_orca_proto"],
)
java_grpc_library(
name = "xds_orca_java_grpc",
srcs = [":xds_orca_proto"],
deps = [":xds_orca_java_proto"],
)
java_rpc_toolchain(
name = "java_grpc_library_toolchain",
plugin = "//compiler:grpc_java_plugin",
runtime = [":java_grpc_library_deps"],
)
java_library(
name = "java_grpc_library_deps",
neverlink = 1,
exports = ["//compiler:java_grpc_library_deps__do_not_reference"],
)
java_library(
name = "testlib",
testonly = 1,
srcs = [
"src/test/java/io/grpc/xds/ControlPlaneRule.java",
"src/test/java/io/grpc/xds/DataPlaneRule.java",
"src/test/java/io/grpc/xds/FakeControlPlaneXdsIntegrationTest.java",
"src/test/java/io/grpc/xds/MetadataLoadBalancerProvider.java",
"src/test/java/io/grpc/xds/XdsTestControlPlaneService.java",
"src/test/java/io/grpc/xds/XdsTestLoadReportingService.java",
],
deps = [
":envoy_java_grpc",
":envoy_java_proto",
":xds",
":xds_java_proto",
"//api",
"//core:internal",
"//stub",
"//testing",
"//testing-proto:simpleservice_java_grpc",
"//testing-proto:simpleservice_java_proto",
"//util",
"@com_google_protobuf//java/core",
"@maven//:com_google_code_findbugs_jsr305",
"@maven//:com_google_guava_guava",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
],
)
java_test(
name = "FakeControlPlaneXdsIntegrationTest",
size = "small",
test_class = "io.grpc.xds.FakeControlPlaneXdsIntegrationTest",
runtime_deps = [":testlib"],
)

View File

@ -17,12 +17,11 @@ sourceSets {
srcDir "${projectDir}/third_party/zero-allocation-hashing/main/java"
}
proto {
srcDir 'third_party/cel-spec/src/main/proto'
srcDir 'third_party/envoy/src/main/proto'
srcDir 'third_party/googleapis/src/main/proto'
srcDir 'third_party/protoc-gen-validate/src/main/proto'
srcDir 'third_party/xds/src/main/proto'
srcDir 'third_party/cel-spec/src/main/proto'
srcDir 'third_party/googleapis/src/main/proto'
srcDir 'third_party/istio/src/main/proto'
}
}
main {
@ -186,6 +185,7 @@ tasks.named("shadowJar").configure {
include(project(':grpc-xds'))
}
// Relocated packages commonly need exclusions in jacocoTestReport and javadoc
// Keep in sync with BUILD.bazel's JAR_JAR_RULES
relocate 'com.github.udpa', "${prefixName}.shaded.com.github.udpa"
relocate 'com.github.xds', "${prefixName}.shaded.com.github.xds"
relocate 'com.google.api.expr', "${prefixName}.shaded.com.google.api.expr"

View File

@ -24,6 +24,7 @@ import static io.grpc.xds.XdsTestControlPlaneService.ADS_TYPE_URL_RDS;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.protobuf.Any;
import com.google.protobuf.BoolValue;
import com.google.protobuf.Message;
import com.google.protobuf.UInt32Value;
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
@ -44,6 +45,7 @@ import io.envoyproxy.envoy.config.listener.v3.FilterChainMatch;
import io.envoyproxy.envoy.config.listener.v3.Listener;
import io.envoyproxy.envoy.config.route.v3.NonForwardingAction;
import io.envoyproxy.envoy.config.route.v3.Route;
import io.envoyproxy.envoy.config.route.v3.RouteAction;
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration;
import io.envoyproxy.envoy.config.route.v3.RouteMatch;
import io.envoyproxy.envoy.config.route.v3.VirtualHost;
@ -237,7 +239,25 @@ public class ControlPlaneRule extends TestWatcher {
* Builds a new default RDS configuration.
*/
static RouteConfiguration buildRouteConfiguration(String authority) {
return XdsTestUtils.buildRouteConfiguration(authority, RDS_NAME, CLUSTER_NAME);
return buildRouteConfiguration(authority, RDS_NAME, CLUSTER_NAME);
}
static RouteConfiguration buildRouteConfiguration(String authority, String rdsName,
String clusterName) {
io.envoyproxy.envoy.config.route.v3.VirtualHost.Builder vhBuilder =
io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder()
.setName(rdsName)
.addDomains(authority)
.addRoutes(
Route.newBuilder()
.setMatch(
RouteMatch.newBuilder().setPrefix("/").build())
.setRoute(
RouteAction.newBuilder().setCluster(clusterName)
.setAutoHostRewrite(BoolValue.newBuilder().setValue(true).build())
.build()));
io.envoyproxy.envoy.config.route.v3.VirtualHost virtualHost = vhBuilder.build();
return RouteConfiguration.newBuilder().setName(rdsName).addVirtualHosts(virtualHost).build();
}
/**

View File

@ -30,7 +30,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.Any;
import com.google.protobuf.BoolValue;
import com.google.protobuf.Message;
import com.google.protobuf.util.Durations;
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
@ -38,10 +37,7 @@ import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment;
import io.envoyproxy.envoy.config.endpoint.v3.ClusterStats;
import io.envoyproxy.envoy.config.listener.v3.ApiListener;
import io.envoyproxy.envoy.config.listener.v3.Listener;
import io.envoyproxy.envoy.config.route.v3.Route;
import io.envoyproxy.envoy.config.route.v3.RouteAction;
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration;
import io.envoyproxy.envoy.config.route.v3.RouteMatch;
import io.envoyproxy.envoy.extensions.clusters.aggregate.v3.ClusterConfig;
import io.envoyproxy.envoy.extensions.filters.http.router.v3.Router;
import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter;
@ -306,20 +302,7 @@ public class XdsTestUtils {
static RouteConfiguration buildRouteConfiguration(String authority, String rdsName,
String clusterName) {
io.envoyproxy.envoy.config.route.v3.VirtualHost.Builder vhBuilder =
io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder()
.setName(rdsName)
.addDomains(authority)
.addRoutes(
Route.newBuilder()
.setMatch(
RouteMatch.newBuilder().setPrefix("/").build())
.setRoute(
RouteAction.newBuilder().setCluster(clusterName)
.setAutoHostRewrite(BoolValue.newBuilder().setValue(true).build())
.build()));
io.envoyproxy.envoy.config.route.v3.VirtualHost virtualHost = vhBuilder.build();
return RouteConfiguration.newBuilder().setName(rdsName).addVirtualHosts(virtualHost).build();
return ControlPlaneRule.buildRouteConfiguration(authority, rdsName, clusterName);
}
static Cluster buildAggCluster(String name, List<String> childNames) {