Skip to content

Correctly evaluate Docker credentials prerequisite state#5607

Merged
Neelabh94 merged 2 commits into
GoogleCloudPlatform:developfrom
scaliby:docker-check-fix
May 6, 2026
Merged

Correctly evaluate Docker credentials prerequisite state#5607
Neelabh94 merged 2 commits into
GoogleCloudPlatform:developfrom
scaliby:docker-check-fix

Conversation

@scaliby

@scaliby scaliby commented May 6, 2026

Copy link
Copy Markdown
Contributor

The Problem

When submitting a job via gcluster job submit, the prerequisite check for Docker credentials was getting stuck in a broken state.
If the user's Docker credentials were not configured, the code would correctly flag the missing prerequisite and populate the missing array. It would then update the in-memory state flag (state.DockerCredsConfigured = true). However, because the missing array was not empty, the function immediately returned an error and exited before saving the updated state to disk (~/.gcluster/job_prereq_state.json).

Furthermore, there was no actual logic to dynamically check the user's system to see if the credentials had been configured; it relied entirely on that state file flag. This meant the CLI could never detect if the user had actually run the gcloud auth configure-docker commands.

The Solution

  1. Introduced a new function, isDockerCredsConfigured(region string), which actively evaluates the user's system state.
  2. The function parses ~/.docker/config.json and verifies that the gcloud credential helper is configured globally via credsStore, or specifically for both "gcr.io" and "<region>-docker.pkg.dev" via credHelpers.
  3. Updated the ensurePrerequisites method to rely on this new dynamic check rather than the flawed state-flag mutation.

How to Test

  1. Remove the gcloud credential helpers from your ~/.docker/config.json.
  2. Clear your local state file: rm ~/.gcluster/job_prereq_state.json.
  3. Run a job submission. Ensure it fails with the correct prompt to run gcloud auth configure-docker.
  4. Run the suggested gcloud auth configure-docker ... commands.
  5. Re-run the job submission. The prerequisite check will now pass.

@scaliby scaliby requested a review from a team as a code owner May 6, 2026 10:31
@github-actions github-actions Bot added the external PR from external contributor label May 6, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug where the CLI incorrectly managed Docker credential prerequisites by relying on a static, often-stale state file. By implementing a dynamic check that parses the user's local Docker configuration, the CLI can now accurately determine if the required gcloud credential helpers are active, providing a more robust and reliable user experience during job submission.

Highlights

  • Dynamic Docker Credential Verification: Introduced the isDockerCredsConfigured function to actively inspect ~/.docker/config.json for valid gcloud credential helpers, replacing the unreliable state-flag approach.
  • Improved Prerequisite Logic: Updated ensurePrerequisites to perform a real-time check of the system's Docker configuration, ensuring users are correctly prompted only when necessary.
  • Comprehensive Testing: Added unit tests for isDockerCredsConfigured covering various scenarios, including missing files, corrupted configurations, and valid/invalid credential helper setups.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a more robust mechanism for verifying Docker credentials by directly inspecting the Docker configuration file. It adds the isDockerCredsConfigured function and comprehensive unit tests to validate various configuration scenarios. The review feedback highlights opportunities to improve configuration discovery by respecting the DOCKER_CONFIG environment variable, enhancing error diagnostics through logging during JSON unmarshaling, and ensuring robustness against empty region strings when generating prerequisite commands.

Comment thread cmd/job/prereq.go Outdated
Comment thread cmd/job/prereq.go
Comment thread cmd/job/prereq.go
@Neelabh94 Neelabh94 added the release-bugfix Added to release notes under the "Bug fixes" heading. label May 6, 2026

@Neelabh94 Neelabh94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Neelabh94

Copy link
Copy Markdown
Contributor

/gcbrun

@Neelabh94 Neelabh94 enabled auto-merge (squash) May 6, 2026 14:17
@Neelabh94 Neelabh94 merged commit 58e7838 into GoogleCloudPlatform:develop May 6, 2026
12 of 80 checks passed
Neelabh94 pushed a commit to Neelabh94/cluster-toolkit that referenced this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from external contributor release-bugfix Added to release notes under the "Bug fixes" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants