Appnet schema changes (#27874)

* Add back references and scope field

* Set scope in router

* Reverse order of cleanup

* Add router_scope flag

* Use router_scope flag to create Router

* I apparently don't know how to brain

* Yapf

* Yeah, that can't be the default

* Remove debug print

* Remove impossible todos

* And another

* Switch from router-scope to config-scope

* Implement schema changes

* Use backend service URL

* Use CLH reference format to backend service

* I am an idiot

* *internal screaming*

* Try project number

* Why is this all awful

* Go back to trying project name

* Try cleaning things up

* Agh

* Address review comments

* Remove superfluous Optional type
pull/27944/head
Richard Belleville 3 years ago committed by GitHub
parent 5c0df85ea8
commit b5217edca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      tools/run_tests/xds_k8s_test_driver/bin/run_test_client.py
  2. 19
      tools/run_tests/xds_k8s_test_driver/framework/infrastructure/gcp/network_services.py
  3. 17
      tools/run_tests/xds_k8s_test_driver/framework/infrastructure/traffic_director.py
  4. 3
      tools/run_tests/xds_k8s_test_driver/framework/test_app/client_app.py
  5. 4
      tools/run_tests/xds_k8s_test_driver/framework/xds_flags.py
  6. 4
      tools/run_tests/xds_k8s_test_driver/framework/xds_k8s_testcase.py
  7. 3
      tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client-secure.deployment.yaml
  8. 3
      tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client.deployment.yaml
  9. 8
      tools/run_tests/xds_k8s_test_driver/tests/app_net_test.py

@ -69,6 +69,7 @@ def main(argv):
gcp_service_account=gcp_service_account, gcp_service_account=gcp_service_account,
xds_server_uri=xds_flags.XDS_SERVER_URI.value, xds_server_uri=xds_flags.XDS_SERVER_URI.value,
network=xds_flags.NETWORK.value, network=xds_flags.NETWORK.value,
config_scope=xds_flags.ROUTER_SCOPE.value,
stats_port=xds_flags.CLIENT_PORT.value, stats_port=xds_flags.CLIENT_PORT.value,
reuse_namespace=_REUSE_NAMESPACE.value) reuse_namespace=_REUSE_NAMESPACE.value)

@ -60,6 +60,7 @@ class Router:
name: str name: str
url: str url: str
type: str type: str
scope: Optional[str]
network: Optional[str] network: Optional[str]
routes: Optional[List[str]] routes: Optional[List[str]]
@ -69,6 +70,7 @@ class Router:
name=name, name=name,
url=d["name"], url=d["name"],
type=d["type"], type=d["type"],
scope=d.get("scope"),
network=d.get("network"), network=d.get("network"),
routes=list(d["routes"]) if "routes" in d else None, routes=list(d["routes"]) if "routes" in d else None,
) )
@ -136,27 +138,30 @@ class GrpcRoute:
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class RouteAction: class RouteAction:
destination: Optional['Destination'] destinations: List['Destination']
drop: Optional[int] drop: Optional[int]
@classmethod @classmethod
def from_response(cls, d: Dict[str, Any]) -> 'RouteAction': def from_response(cls, d: Dict[str, Any]) -> 'RouteAction':
destinations = [
Destination.from_response(dest) for dest in d["destinations"]
] if "destinations" in d else []
return cls( return cls(
destination=Destination.from_response(d["destination"]) destinations=destinations,
if "destination" in d else None,
drop=d.get("drop"), drop=d.get("drop"),
) )
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class RouteRule: class RouteRule:
match: Optional['RouteMatch'] matches: List['RouteMatch']
action: 'RouteAction' action: 'RouteAction'
@classmethod @classmethod
def from_response(cls, d: Dict[str, Any]) -> 'RouteRule': def from_response(cls, d: Dict[str, Any]) -> 'RouteRule':
matches = [RouteMatch.from_response(m) for m in d["matches"]
] if "matches" in d else []
return cls( return cls(
match=RouteMatch.from_response(d["match"]) matches=matches,
if "match" in d else "",
action=RouteAction.from_response(d["action"]), action=RouteAction.from_response(d["action"]),
) )
@ -164,6 +169,7 @@ class GrpcRoute:
url: str url: str
hostnames: Tuple[str] hostnames: Tuple[str]
rules: Tuple['RouteRule'] rules: Tuple['RouteRule']
routers: Optional[Tuple[str]]
@classmethod @classmethod
def from_response(cls, name: str, d: Dict[str, Any]) -> 'RouteRule': def from_response(cls, name: str, d: Dict[str, Any]) -> 'RouteRule':
@ -172,6 +178,7 @@ class GrpcRoute:
url=d["name"], url=d["name"],
hostnames=tuple(d["hostnames"]), hostnames=tuple(d["hostnames"]),
rules=tuple(d["rules"]), rules=tuple(d["rules"]),
routers=None if d.get("routers") is None else tuple(d["routers"]),
) )

@ -556,6 +556,7 @@ class TrafficDirectorAppNetManager(TrafficDirectorManager):
project: str, project: str,
*, *,
resource_prefix: str, resource_prefix: str,
config_scope: str,
resource_suffix: Optional[str] = None, resource_suffix: Optional[str] = None,
network: str = 'default', network: str = 'default',
compute_api_version: str = 'v1'): compute_api_version: str = 'v1'):
@ -566,6 +567,8 @@ class TrafficDirectorAppNetManager(TrafficDirectorManager):
network=network, network=network,
compute_api_version=compute_api_version) compute_api_version=compute_api_version)
self.config_scope = config_scope
# API # API
self.netsvc = _NetworkServicesV1Alpha1(gcp_api_manager, project) self.netsvc = _NetworkServicesV1Alpha1(gcp_api_manager, project)
@ -578,8 +581,7 @@ class TrafficDirectorAppNetManager(TrafficDirectorManager):
logger.info("Creating Router %s", name) logger.info("Creating Router %s", name)
body = { body = {
"type": "PROXYLESS_GRPC", "type": "PROXYLESS_GRPC",
"routes": [self.grpc_route.url], "scope": self.config_scope,
"network": "default",
} }
resource = self.netsvc.create_router(name, body) resource = self.netsvc.create_router(name, body)
self.router = self.netsvc.get_router(name) self.router = self.netsvc.get_router(name)
@ -599,14 +601,17 @@ class TrafficDirectorAppNetManager(TrafficDirectorManager):
def create_grpc_route(self, src_host: str, src_port: int) -> GcpResource: def create_grpc_route(self, src_host: str, src_port: int) -> GcpResource:
host = f'{src_host}:{src_port}' host = f'{src_host}:{src_port}'
service_name = self.netsvc.resource_full_name(self.backend_service.name,
"backendServices")
body = { body = {
"routers": [self.router.url],
"hostnames": "hostnames":
host, host,
"rules": [{ "rules": [{
"action": { "action": {
"destination": { "destinations": [{
"serviceName": self.backend_service.name "serviceName": service_name
} }]
} }
}], }],
} }
@ -637,8 +642,8 @@ class TrafficDirectorAppNetManager(TrafficDirectorManager):
self.grpc_route = None self.grpc_route = None
def cleanup(self, *, force=False): def cleanup(self, *, force=False):
self.delete_router(force=force)
self.delete_grpc_route(force=force) self.delete_grpc_route(force=force)
self.delete_router(force=force)
super().cleanup(force=force) super().cleanup(force=force)

@ -238,6 +238,7 @@ class KubernetesClientRunner(base_runner.KubernetesBaseRunner):
gcp_service_account: str, gcp_service_account: str,
xds_server_uri=None, xds_server_uri=None,
network='default', network='default',
config_scope=None,
service_account_name=None, service_account_name=None,
stats_port=8079, stats_port=8079,
deployment_template='client.deployment.yaml', deployment_template='client.deployment.yaml',
@ -256,6 +257,7 @@ class KubernetesClientRunner(base_runner.KubernetesBaseRunner):
self.td_bootstrap_image = td_bootstrap_image self.td_bootstrap_image = td_bootstrap_image
self.xds_server_uri = xds_server_uri self.xds_server_uri = xds_server_uri
self.network = network self.network = network
self.config_scope = config_scope
self.deployment_template = deployment_template self.deployment_template = deployment_template
self.debug_use_port_forwarding = debug_use_port_forwarding self.debug_use_port_forwarding = debug_use_port_forwarding
self.enable_workload_identity = enable_workload_identity self.enable_workload_identity = enable_workload_identity
@ -327,6 +329,7 @@ class KubernetesClientRunner(base_runner.KubernetesBaseRunner):
td_bootstrap_image=self.td_bootstrap_image, td_bootstrap_image=self.td_bootstrap_image,
xds_server_uri=self.xds_server_uri, xds_server_uri=self.xds_server_uri,
network=self.network, network=self.network,
config_scope=self.config_scope,
stats_port=self.stats_port, stats_port=self.stats_port,
server_target=server_target, server_target=server_target,
rpc=rpc, rpc=rpc,

@ -36,6 +36,10 @@ RESOURCE_SUFFIX = flags.DEFINE_string(
NETWORK = flags.DEFINE_string("network", NETWORK = flags.DEFINE_string("network",
default="default", default="default",
help="GCP Network ID") help="GCP Network ID")
ROUTER_SCOPE = flags.DEFINE_string(
"config_scope",
default=None,
help="Scope specified in router if using AppNet APIs")
COMPUTE_API_VERSION = flags.DEFINE_string( COMPUTE_API_VERSION = flags.DEFINE_string(
"compute_api_version", "compute_api_version",
default='v1', default='v1',

@ -87,6 +87,7 @@ class XdsKubernetesTestCase(absltest.TestCase, metaclass=abc.ABCMeta):
# GCP # GCP
cls.project: str = xds_flags.PROJECT.value cls.project: str = xds_flags.PROJECT.value
cls.network: str = xds_flags.NETWORK.value cls.network: str = xds_flags.NETWORK.value
cls.config_scope: str = xds_flags.ROUTER_SCOPE.value
cls.gcp_service_account: str = xds_k8s_flags.GCP_SERVICE_ACCOUNT.value cls.gcp_service_account: str = xds_k8s_flags.GCP_SERVICE_ACCOUNT.value
cls.td_bootstrap_image = xds_k8s_flags.TD_BOOTSTRAP_IMAGE.value cls.td_bootstrap_image = xds_k8s_flags.TD_BOOTSTRAP_IMAGE.value
cls.xds_server_uri = xds_flags.XDS_SERVER_URI.value cls.xds_server_uri = xds_flags.XDS_SERVER_URI.value
@ -418,6 +419,7 @@ class RegularXdsKubernetesTestCase(XdsKubernetesTestCase):
gcp_service_account=self.gcp_service_account, gcp_service_account=self.gcp_service_account,
xds_server_uri=self.xds_server_uri, xds_server_uri=self.xds_server_uri,
network=self.network, network=self.network,
config_scope=self.config_scope,
debug_use_port_forwarding=self.debug_use_port_forwarding, debug_use_port_forwarding=self.debug_use_port_forwarding,
enable_workload_identity=self.enable_workload_identity, enable_workload_identity=self.enable_workload_identity,
stats_port=self.client_port, stats_port=self.client_port,
@ -457,6 +459,7 @@ class AppNetXdsKubernetesTestCase(RegularXdsKubernetesTestCase):
resource_prefix=self.resource_prefix, resource_prefix=self.resource_prefix,
resource_suffix=self.resource_suffix, resource_suffix=self.resource_suffix,
network=self.network, network=self.network,
config_scope=self.config_scope,
compute_api_version=self.compute_api_version) compute_api_version=self.compute_api_version)
@ -518,6 +521,7 @@ class SecurityXdsKubernetesTestCase(XdsKubernetesTestCase):
gcp_service_account=self.gcp_service_account, gcp_service_account=self.gcp_service_account,
xds_server_uri=self.xds_server_uri, xds_server_uri=self.xds_server_uri,
network=self.network, network=self.network,
config_scope=self.config_scope,
deployment_template='client-secure.deployment.yaml', deployment_template='client-secure.deployment.yaml',
stats_port=self.client_port, stats_port=self.client_port,
reuse_namespace=self.server_namespace == self.client_namespace, reuse_namespace=self.server_namespace == self.client_namespace,

@ -62,6 +62,9 @@ spec:
% if xds_server_uri: % if xds_server_uri:
- "--xds-server-uri=${xds_server_uri}" - "--xds-server-uri=${xds_server_uri}"
% endif % endif
% if config_scope:
- "--config-scope-experimental=${config_scope_experimental}"
% endif
- "--include-v3-features-experimental" - "--include-v3-features-experimental"
- "--include-psm-security-experimental" - "--include-psm-security-experimental"
resources: resources:

@ -62,6 +62,9 @@ spec:
% if xds_server_uri: % if xds_server_uri:
- "--xds-server-uri=${xds_server_uri}" - "--xds-server-uri=${xds_server_uri}"
% endif % endif
% if config_scope:
- "--config-scope-experimental=${config_scope}"
% endif
resources: resources:
limits: limits:
cpu: 100m cpu: 100m

@ -34,13 +34,13 @@ class AppNetTest(xds_k8s_testcase.AppNetXdsKubernetesTestCase):
with self.subTest('1_create_backend_service'): with self.subTest('1_create_backend_service'):
self.td.create_backend_service() self.td.create_backend_service()
with self.subTest('2_create_grpc_route'): with self.subTest('2_create_router'):
self.td.create_router()
with self.subTest('3_create_grpc_route'):
self.td.create_grpc_route(self.server_xds_host, self.td.create_grpc_route(self.server_xds_host,
self.server_xds_port) self.server_xds_port)
with self.subTest('3_create_router'):
self.td.create_router()
with self.subTest('4_start_test_server'): with self.subTest('4_start_test_server'):
test_server: _XdsTestServer = self.startTestServers( test_server: _XdsTestServer = self.startTestServers(
replica_count=1)[0] replica_count=1)[0]

Loading…
Cancel
Save