Skip to content

Commit fe69e2f

Browse files
committed
fix(cli): use _GCLOUD_CMD for gcloud calls in GKE deploy on Windows
The GKE deploy path (`adk deploy gke`) still invoked gcloud via the bare name `gcloud` in two places: the `builds submit` call and the `container clusters get-credentials` call. On Windows, gcloud is the `gcloud.cmd` batch script, and subprocess.run() without a shell does not apply PATHEXT to a bare name, so both calls raise FileNotFoundError and the deploy fails. The module already defines `_GCLOUD_CMD = 'gcloud.cmd' if _IS_WINDOWS else 'gcloud'` for exactly this reason and uses it in the Cloud Run path, but the two GKE call sites were missed. Point them at `_GCLOUD_CMD` too. No behavior change on POSIX. Add a regression test that patches `_GCLOUD_CMD` to simulate Windows and asserts both GKE gcloud invocations use `gcloud.cmd`.
1 parent e6df097 commit fe69e2f

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/google/adk/cli/cli_deploy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ def to_gke(
13961396
image_name = f'gcr.io/{project}/{service_name}'
13971397
subprocess.run(
13981398
[
1399-
'gcloud',
1399+
_GCLOUD_CMD,
14001400
'builds',
14011401
'submit',
14021402
'--tag',
@@ -1466,7 +1466,7 @@ def to_gke(
14661466
click.echo(' - Getting cluster credentials...')
14671467
subprocess.run(
14681468
[
1469-
'gcloud',
1469+
_GCLOUD_CMD,
14701470
'container',
14711471
'clusters',
14721472
'get-credentials',

tests/unittests/cli/utils/test_cli_deploy.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,57 @@ def mock_subprocess_run(*args, **kwargs):
442442
assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path)
443443

444444

445+
def test_to_gke_uses_gcloud_cmd_on_windows(
446+
monkeypatch: pytest.MonkeyPatch,
447+
agent_dir: Callable[[bool, bool], Path],
448+
tmp_path: Path,
449+
) -> None:
450+
"""On Windows, `to_gke` must invoke gcloud via `_GCLOUD_CMD` (gcloud.cmd).
451+
452+
Regression test: the GKE deploy path spawns gcloud without a shell, so a bare
453+
`gcloud` name is not resolved to the `gcloud.cmd` batch script on Windows and
454+
the deploy fails. Both gcloud invocations must use `_GCLOUD_CMD`.
455+
"""
456+
src_dir = agent_dir(False, False)
457+
run_recorder = _Recorder()
458+
459+
monkeypatch.setattr(cli_deploy, "_GCLOUD_CMD", "gcloud.cmd")
460+
461+
def mock_subprocess_run(*args, **kwargs):
462+
run_recorder(*args, **kwargs)
463+
command_list = args[0]
464+
if command_list and command_list[0:2] == ["kubectl", "apply"]:
465+
return types.SimpleNamespace(stdout="deployment created\nservice created")
466+
return None
467+
468+
monkeypatch.setattr(subprocess, "run", mock_subprocess_run)
469+
monkeypatch.setattr(shutil, "rmtree", _Recorder())
470+
471+
cli_deploy.to_gke(
472+
agent_folder=str(src_dir),
473+
project="gke-proj",
474+
region="us-east1",
475+
cluster_name="my-gke-cluster",
476+
service_name="gke-svc",
477+
app_name="agent",
478+
temp_folder=str(tmp_path),
479+
port=9090,
480+
trace_to_cloud=False,
481+
otel_to_cloud=False,
482+
with_ui=False,
483+
log_level="debug",
484+
adk_version="1.2.0",
485+
)
486+
487+
build_args = run_recorder.calls[0][0][0]
488+
assert build_args[0] == "gcloud.cmd"
489+
assert build_args[1:3] == ["builds", "submit"]
490+
491+
creds_args = run_recorder.calls[1][0][0]
492+
assert creds_args[0] == "gcloud.cmd"
493+
assert creds_args[1:4] == ["container", "clusters", "get-credentials"]
494+
495+
445496
# _validate_agent_import tests
446497
class TestValidateAgentImport:
447498
"""Tests for the _validate_agent_import function."""

0 commit comments

Comments
 (0)