Skip to content
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
ad3d5ca
cloudrun server test
sourabhsinghs Nov 25, 2024
45f84dc
Merge branch 'main' into feature/cloudrun/server-test
sourabhsinghs Jan 28, 2025
6859957
cloudrun server test
sourabhsinghs Nov 25, 2024
39c5cbe
check patch
eshitachandwani Feb 11, 2025
87317ec
correct logging import and remove clourun server flag
eshitachandwani Feb 11, 2025
a9f88b0
client test not working
eshitachandwani Feb 17, 2025
0142857
changes
eshitachandwani Feb 21, 2025
579f782
running tests
eshitachandwani Feb 26, 2025
64cd9f1
run black and isort
eshitachandwani Feb 26, 2025
1a1c974
pylint error
eshitachandwani Feb 26, 2025
6d5e0de
pylint error
eshitachandwani Feb 26, 2025
bc64577
remove unwanted files
eshitachandwani Feb 27, 2025
b9be8ca
address comments
eshitachandwani Feb 28, 2025
521bf5e
pylint
eshitachandwani Feb 28, 2025
8455a1e
address comments
eshitachandwani Mar 6, 2025
d04238e
pylint
eshitachandwani Mar 6, 2025
10e9589
black
eshitachandwani Mar 6, 2025
91ddacc
working cloudrun_server test
eshitachandwani Mar 10, 2025
bc72f63
formatting
eshitachandwani Mar 10, 2025
a70ea9b
pylint
eshitachandwani Mar 10, 2025
2685397
pylint
eshitachandwani Mar 10, 2025
75184b9
address comments
eshitachandwani Mar 11, 2025
0b235ee
black
eshitachandwani Mar 11, 2025
486c554
add cloudrunlogs
eshitachandwani Mar 12, 2025
47447cf
flag file
eshitachandwani Mar 19, 2025
ab09f9c
test suit
eshitachandwani Mar 19, 2025
9af09ec
pull from main
eshitachandwani Mar 26, 2025
2c270c2
create_resource
eshitachandwani Mar 27, 2025
65f29bf
address comments
eshitachandwani Mar 27, 2025
54e9052
black
eshitachandwani Mar 27, 2025
e701237
minor changes
eshitachandwani Apr 1, 2025
cd54ed4
use gcpstandardresource
eshitachandwani Apr 3, 2025
5759ea6
neg changes
eshitachandwani Apr 8, 2025
8d0f40e
correct keyerror
eshitachandwani Apr 9, 2025
1ad1b42
change yaml
eshitachandwani Apr 9, 2025
7f2fe02
Merge branch 'main' into eshita_gke_cloudrun
eshitachandwani Apr 9, 2025
d25b162
comments
eshitachandwani Apr 9, 2025
32303e3
gerg
eshitachandwani Apr 9, 2025
3b3ae6a
common.py
eshitachandwani Apr 9, 2025
0917ffa
pylint
eshitachandwani Apr 9, 2025
aca0c15
pylint
eshitachandwani Apr 9, 2025
4a7feb9
comments
eshitachandwani Apr 11, 2025
d3d0ebe
Merge branch 'main' into eshita_gke_cloudrun
eshitachandwani Apr 11, 2025
8bc4940
comments
eshitachandwani Apr 11, 2025
9405c48
Merge branch 'eshita_gke_cloudrun' of https://github.com/eshitachandw…
eshitachandwani Apr 11, 2025
7fc75d3
Merge branch 'main' into eshita_gke_cloudrun
eshitachandwani Apr 14, 2025
224e2d8
address comments
eshitachandwani Apr 15, 2025
7bf2e26
Merge branch 'eshita_gke_cloudrun' of https://github.com/eshitachandw…
eshitachandwani Apr 15, 2025
aec4ad8
pulint
eshitachandwani Apr 15, 2025
f37e51b
Merge branch 'main' into eshita_gke_cloudrun
eshitachandwani Apr 15, 2025
74676f8
pulint
eshitachandwani Apr 15, 2025
4d3bb70
Merge branch 'eshita_gke_cloudrun' of https://github.com/eshitachandw…
eshitachandwani Apr 15, 2025
9660983
comments
eshitachandwani Apr 17, 2025
1e7c4a5
Moving is_trusted_xds_server_experimental to client deployment args
sergiitk Apr 17, 2025
5128b98
Specify supported cloud run langs/versions in is_supported
sergiitk Apr 17, 2025
984dd50
refactor deploy_service
eshitachandwani Apr 17, 2025
f45b383
deploy_services
eshitachandwani Apr 17, 2025
bedb294
deploy_services
eshitachandwani Apr 17, 2025
f9a9c20
fix test
eshitachandwani Apr 21, 2025
544c361
test
eshitachandwani Apr 21, 2025
97cbf2f
change test
eshitachandwani Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .kokoro/psm_interop_kokoro_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ psm::cloud_run::get_tests() {
#######################################
psm::cloud_run::run_test() {
local test_name="${1:?${FUNCNAME[0]} missing the test name argument}"

PSM_TEST_FLAGS+=(
"--flagfile=config/common-cloudrun.cfg"
)

psm::run::finalize_test_flags "${test_name}"
psm::tools::run_verbose python -m "tests.${test_name}" "${PSM_TEST_FLAGS[@]}"
}
Expand Down
21 changes: 21 additions & 0 deletions bin/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
from framework import xds_k8s_flags
from framework.infrastructure import gcp
from framework.infrastructure import k8s
from framework.infrastructure.gcp import cloud_run
from framework.test_app import client_app
from framework.test_app import server_app
from framework.test_app.runners.cloud_run import cloud_run_xds_server_runner
from framework.test_app.runners.k8s import gamma_server_runner
from framework.test_app.runners.k8s import k8s_xds_client_runner
from framework.test_app.runners.k8s import k8s_xds_server_runner
Expand All @@ -45,6 +47,7 @@
KubernetesClientRunner = k8s_xds_client_runner.KubernetesClientRunner
KubernetesServerRunner = k8s_xds_server_runner.KubernetesServerRunner
GammaServerRunner = gamma_server_runner.GammaServerRunner
CloudRunServerRunner = cloud_run_xds_server_runner.CloudRunServerRunner
_XdsTestServer = server_app.XdsTestServer
_XdsTestClient = client_app.XdsTestClient

Expand All @@ -59,6 +62,12 @@ def gcp_api_manager():
return gcp.api.GcpApiManager()


@functools.cache
def cloud_run_api_manager():
return cloud_run.CloudRunV2(project=xds_flags.PROJECT.value,
region=xds_flags.CLOUD_RUN_REGION.value,
api_manager=gcp_api_manager())

def td_attrs():
return dict(
gcp_api_manager=gcp_api_manager(),
Expand Down Expand Up @@ -155,6 +164,18 @@ def make_server_runner(

return server_runner(namespace, **runner_kwargs)

def make_cloud_run_server_runner() -> CloudRunServerRunner:
# CloudRunServerRunner arguments.
Comment thread
XuanWang-Amos marked this conversation as resolved.
runner_kwargs = dict(
project=xds_flags.PROJECT.value,
service_name=xds_flags.SERVER_NAME.value,
image_name=xds_k8s_flags.SERVER_IMAGE.value,
Comment thread
XuanWang-Amos marked this conversation as resolved.
network=xds_flags.NETWORK.value,
region=xds_flags.CLOUD_RUN_REGION.value,
gcp_api_manager=gcp.api.GcpApiManager(),
)
server_runner = CloudRunServerRunner
return server_runner(**runner_kwargs)

def _ensure_atexit(signum, frame):
"""Needed to handle signals or atexit handler won't be called."""
Expand Down
50 changes: 50 additions & 0 deletions bin/run_test_server_cloud_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2025 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.
"""
Run test xds server.

Typical usage examples:

# Help.
./run.sh ./bin/run_test_server_cloud_run.py --help

"""
import logging

from absl import app
from absl import flags

from bin.lib import common
from framework import xds_flags
from framework import xds_k8s_flags

logger = logging.getLogger(__name__)

flags.adopt_module_key_flags(xds_flags)
flags.adopt_module_key_flags(xds_k8s_flags)
flags.adopt_module_key_flags(common)


def main(argv):
Comment thread
sergiitk marked this conversation as resolved.
if len(argv) > 1:
raise app.UsageError("Too many command-line arguments.")

xds_flags.set_socket_default_timeout_from_flag()

server_runner = common.make_cloud_run_server_runner()
server_runner.run()


if __name__ == "__main__":
app.run(main)
2 changes: 2 additions & 0 deletions config/common-cloudrun.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Common config file for Cloudrun PSM tests.
--cloud_run_region=us-central1
1 change: 1 addition & 0 deletions framework/infrastructure/gcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from framework.infrastructure.gcp import api
from framework.infrastructure.gcp import cloud_run
from framework.infrastructure.gcp import compute
from framework.infrastructure.gcp import iam
from framework.infrastructure.gcp import network_security
Expand Down
22 changes: 18 additions & 4 deletions framework/infrastructure/gcp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ def networksecurity(self, version):

raise NotImplementedError(f"Network Security {version} not supported")

@functools.lru_cache(None)
def cloudrun(self, version):
api_name = "run"
if version == "v2":
return self._build_from_discovery_v2(api_name, version)
Comment thread
eshitachandwani marked this conversation as resolved.
raise NotImplementedError(f"Cloud Run {version} not supported")

@functools.lru_cache(None)
def networkservices(self, version):
api_name = "networkservices"
Expand Down Expand Up @@ -520,20 +527,27 @@ def parent(self, location: Optional[str] = GLOBAL_LOCATION):
location = self.GLOBAL_LOCATION
return f"projects/{self.project}/locations/{location}"

def resource_full_name(self, name, collection_name):
return f"{self.parent()}/{collection_name}/{name}"
def resource_full_name(
self, name: str, collection_name: str, location: str = GLOBAL_LOCATION
):
return f"{self.parent(location)}/{collection_name}/{name}"

def _create_resource(
self, collection: discovery.Resource, body: dict, **kwargs
self,
collection: discovery.Resource,
body: dict,
location: Optional[str] = None,
**kwargs,
):
logger.info(
"Creating %s resource:\n%s",
self.api_name,
self.resource_pretty_format(body),
)
create_req = collection.create(
parent=self.parent(), body=body, **kwargs
parent=self.parent(location), body=body, **kwargs
)

self._execute(create_req)

@property
Expand Down
93 changes: 93 additions & 0 deletions framework/infrastructure/gcp/cloud_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright 2025 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.
import abc
import dataclasses
import logging
from typing import Any, Final

from framework.infrastructure import gcp

logger = logging.getLogger(__name__)

Comment thread
sergiitk marked this conversation as resolved.
Outdated

@dataclasses.dataclass(frozen=True)
class CloudRunService:
service_name: str
url: str
Comment thread
sergiitk marked this conversation as resolved.
Outdated

@classmethod
def from_response(
cls, name: str, response: dict[str, Any]
) -> "CloudRunService":
return cls(
service_name=name,
url=response["uri"],
)


class CloudRunV2(gcp.api.GcpStandardCloudApiResource, metaclass=abc.ABCMeta):
"""Cloud Run API v2."""

SERVICES: Final[str] = "services"

region: str

def __init__(
self, api_manager: gcp.api.GcpApiManager, project: str, region: str
):
if not project:
raise ValueError("Project ID cannot be empty or None.")
if not region:
raise ValueError("Region cannot be empty or None.")
self.region = region
super().__init__(api_manager.cloudrun(self.api_version), project)
self._services_collection = self.api.projects().locations().services()

@property
def api_name(self) -> str:
"""Returns the API name for Cloud Run."""
return "Cloud Run"

@property
def api_version(self) -> str:
"""Returns the API version for Cloud Run."""
return "v2"

def create_service(self, service_name: str, body: dict) -> None:
return self._create_resource(
collection=self._services_collection,
location=self.region,
serviceId=service_name,
body=body,
)

def get_service(self, service_name: str) -> CloudRunService:
result = self._get_resource(
collection=self._services_collection,
full_name=self.resource_full_name(
service_name, self.SERVICES, self.region
),
)
return CloudRunService.from_response(
self.resource_full_name(service_name, self.SERVICES, self.region),
result,
)

def delete_service(self, service_name: str):
self._delete_resource(
self._services_collection,
full_name=self.resource_full_name(
service_name, self.SERVICES, self.region
),
)
Loading