-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7ffef9
commit ad3d5ca
Showing
17 changed files
with
932 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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,66 @@ | ||
# Copyright 2020 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_c6n.py --help | ||
# Run modes. | ||
./run.sh ./bin/run_test_server_c6n.py --mode=app_net | ||
./run.sh ./bin/run_test_server_c6n.py --mode=secure | ||
# Gamma run mode: uses HTTPRoute by default. | ||
./run.sh ./bin/run_test_server_c6n.py --mode=gamma | ||
# Gamma run mode: use GRPCRoute. | ||
./run.sh ./bin/run_test_server_c6n.py --mode=gamma --gamma_route_kind=grpc | ||
# Running multipler server replicas. | ||
./run.sh ./bin/run_test_server_c6n.py --server_replica_count=3 | ||
# Cleanup: make sure to set the same mode used to create. | ||
./run.sh ./bin/run_test_server_c6n.py --mode=gamma --cmd=cleanup | ||
""" | ||
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): | ||
if len(argv) > 1: | ||
raise app.UsageError("Too many command-line arguments.") | ||
|
||
xds_flags.set_socket_default_timeout_from_flag() | ||
|
||
run_kwargs = dict() | ||
server_runner = common.make_c6n_server_runner() | ||
server_runner.run(**run_kwargs) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(main) |
This file contains 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,93 @@ | ||
# Copyright 2024 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 logging | ||
|
||
from google.cloud import run_v2 | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CloudRunApiManager: | ||
project: str | ||
region: str | ||
_parent: str | ||
_client: run_v2.ServicesClient | ||
_service: run_v2.Service | ||
|
||
def __init__(self, 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.project = project | ||
self.region = region | ||
client_options = {"api_endpoint": f"{self.region}-run.googleapis.com"} | ||
self._client = run_v2.ServicesClient(client_options=client_options) | ||
self._parent = f"projects/{self.project}/locations/{self.region}" | ||
self._service = None | ||
|
||
def deploy_service(self, service_name: str, image_name: str): | ||
if not service_name: | ||
raise ValueError("service_name cannot be empty or None") | ||
if not image_name: | ||
raise ValueError("image_name cannot be empty or None") | ||
service_name = service_name[:49] | ||
|
||
service = run_v2.Service( | ||
template=run_v2.RevisionTemplate( | ||
containers=[ | ||
run_v2.Container( | ||
image=image_name, | ||
ports=[ | ||
run_v2.ContainerPort( | ||
name="http1", | ||
container_port=50051, | ||
), | ||
], | ||
) | ||
] | ||
), | ||
) | ||
|
||
request = run_v2.CreateServiceRequest( | ||
parent=self._parent, service=service, service_id=service_name | ||
) | ||
|
||
try: | ||
operation = self._client.create_service(request=request) | ||
self._service = operation.result(timeout=300) | ||
logger.info("Deployed service: %s", self._service.uri) | ||
return self._service.uri | ||
except Exception as e: | ||
logger.exception("Error deploying service: %s", e) | ||
raise | ||
|
||
def get_service_url(self): | ||
if self._service is None: | ||
raise RuntimeError("Cloud Run service not deployed yet.") | ||
return self._service.uri | ||
|
||
def delete_service(self, service_name: str): | ||
try: | ||
request = run_v2.DeleteServiceRequest( | ||
name=f"{self._parent}/services/{service_name}" | ||
) | ||
operation = self._client.delete_service(request=request) | ||
operation.result(timeout=300) | ||
logger.info("Deleted service: %s", service_name) | ||
except Exception as e: | ||
logger.exception("Error deleting service: %s", e) | ||
raise |
This file contains 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 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
Oops, something went wrong.