Skip to content

fix(cli): use _GCLOUD_CMD for gcloud calls in GKE deploy on Windows#6297

Open
anxkhn wants to merge 1 commit into
google:mainfrom
anxkhn:fix/gke-deploy-gcloud-windows
Open

fix(cli): use _GCLOUD_CMD for gcloud calls in GKE deploy on Windows#6297
anxkhn wants to merge 1 commit into
google:mainfrom
anxkhn:fix/gke-deploy-gcloud-windows

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 5, 2026

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

No existing issue; describing the change below (per CONTRIBUTING, non-doc PRs may
describe the bug directly in the PR following the issue template structure).

2. Or, if no issue exists, describe the change:

Problem:

adk deploy gke is broken on Windows. The GKE deploy path in
src/google/adk/cli/cli_deploy.py invokes gcloud via the bare name 'gcloud' in
two places:

  • the gcloud builds submit call, and
  • the gcloud container clusters get-credentials call.

On Windows the gcloud entrypoint is the gcloud.cmd batch script.
subprocess.run([...]) is called without a shell, and Python does not apply
PATHEXT to a bare command name in that case, so gcloud is not resolved to
gcloud.cmd. Both calls therefore raise FileNotFoundError and the deploy fails.

The module already defines, precisely for this reason:

_GCLOUD_CMD = 'gcloud.cmd' if _IS_WINDOWS else 'gcloud'

and uses it correctly in the Cloud Run deploy path. The Windows fix for Cloud Run
(#1597) introduced _GCLOUD_CMD but only updated the Cloud Run call sites; the two
GKE call sites were left as the literal 'gcloud'. This PR is the follow-up that
finishes the same fix for the GKE path.

Solution:

Point the two GKE gcloud invocations at the existing _GCLOUD_CMD constant,
mirroring the Cloud Run path. This is the smallest change that resolves the issue:
two lines. There is no behavior change on POSIX, where _GCLOUD_CMD == 'gcloud';
only Windows behavior changes (bare gcloud -> gcloud.cmd).

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added test_to_gke_uses_gcloud_cmd_on_windows in
tests/unittests/cli/utils/test_cli_deploy.py. It mirrors the existing
test_to_gke_happy_path, patches _GCLOUD_CMD to "gcloud.cmd" to simulate
Windows, and asserts that both gcloud invocations (builds submit and
container clusters get-credentials) use gcloud.cmd as argv[0]. The test is red
on the current code (AssertionError: assert 'gcloud' == 'gcloud.cmd') and green
with the fix.

pytest summary (CLI deploy suite):

$ pytest tests/unittests/cli/utils/test_cli_deploy.py \
         tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py \
         tests/unittests/cli/utils/test_cli_deploy_ignore.py \
         tests/unittests/cli/utils/test_cli_tools_click.py -q
92 passed

Manual End-to-End (E2E) Tests:

This is a Windows-only executable-resolution fix in an external gcloud
subprocess call, so a full GKE deploy is not reproducible in CI. The failure and
fix are demonstrated deterministically by the unit test above, which asserts the
exact argv[0] passed to subprocess.run for both gcloud calls. On POSIX there is
no change, since _GCLOUD_CMD already resolves to 'gcloud'.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end. (Not feasible without a
    Windows host + a real GKE project; covered by the deterministic unit test.)
  • Any dependent changes have been merged and published in downstream modules.

Additional context

This completes the Windows gcloud-invocation fix started for the Cloud Run path,
which introduced _GCLOUD_CMD but did not update the GKE call sites. After this
change, every gcloud subprocess invocation in cli_deploy.py (Cloud Run and GKE)
goes through _GCLOUD_CMD.


Diff summary (for reviewer reference; not part of the PR body)

  • src/google/adk/cli/cli_deploy.py (+2 / -2): 'gcloud' -> _GCLOUD_CMD at the
    to_gke builds submit site and the container clusters get-credentials site.
  • tests/unittests/cli/utils/test_cli_deploy.py (+51): new regression test
    test_to_gke_uses_gcloud_cmd_on_windows.

Total: 2 files, +53 / -2.

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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant