Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/google/adk/cli/cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ def to_gke(
image_name = f'gcr.io/{project}/{service_name}'
subprocess.run(
[
'gcloud',
_GCLOUD_CMD,
'builds',
'submit',
'--tag',
Expand Down Expand Up @@ -1466,7 +1466,7 @@ def to_gke(
click.echo(' - Getting cluster credentials...')
subprocess.run(
[
'gcloud',
_GCLOUD_CMD,
'container',
'clusters',
'get-credentials',
Expand Down
51 changes: 51 additions & 0 deletions tests/unittests/cli/utils/test_cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,57 @@ def mock_subprocess_run(*args, **kwargs):
assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path)


def test_to_gke_uses_gcloud_cmd_on_windows(
monkeypatch: pytest.MonkeyPatch,
agent_dir: Callable[[bool, bool], Path],
tmp_path: Path,
) -> None:
"""On Windows, `to_gke` must invoke gcloud via `_GCLOUD_CMD` (gcloud.cmd).

Regression test: the GKE deploy path spawns gcloud without a shell, so a bare
`gcloud` name is not resolved to the `gcloud.cmd` batch script on Windows and
the deploy fails. Both gcloud invocations must use `_GCLOUD_CMD`.
"""
src_dir = agent_dir(False, False)
run_recorder = _Recorder()

monkeypatch.setattr(cli_deploy, "_GCLOUD_CMD", "gcloud.cmd")

def mock_subprocess_run(*args, **kwargs):
run_recorder(*args, **kwargs)
command_list = args[0]
if command_list and command_list[0:2] == ["kubectl", "apply"]:
return types.SimpleNamespace(stdout="deployment created\nservice created")
return None

monkeypatch.setattr(subprocess, "run", mock_subprocess_run)
monkeypatch.setattr(shutil, "rmtree", _Recorder())

cli_deploy.to_gke(
agent_folder=str(src_dir),
project="gke-proj",
region="us-east1",
cluster_name="my-gke-cluster",
service_name="gke-svc",
app_name="agent",
temp_folder=str(tmp_path),
port=9090,
trace_to_cloud=False,
otel_to_cloud=False,
with_ui=False,
log_level="debug",
adk_version="1.2.0",
)

build_args = run_recorder.calls[0][0][0]
assert build_args[0] == "gcloud.cmd"
assert build_args[1:3] == ["builds", "submit"]

creds_args = run_recorder.calls[1][0][0]
assert creds_args[0] == "gcloud.cmd"
assert creds_args[1:4] == ["container", "clusters", "get-credentials"]


# _validate_agent_import tests
class TestValidateAgentImport:
"""Tests for the _validate_agent_import function."""
Expand Down
Loading