Skip to content

cleanup(gke): remove redundant switch in GenerateGKENodeSelectorLabel#5846

Open
kadupoornima wants to merge 1 commit into
GoogleCloudPlatform:developfrom
kadupoornima:fix/redundant-gke-switch
Open

cleanup(gke): remove redundant switch in GenerateGKENodeSelectorLabel#5846
kadupoornima wants to merge 1 commit into
GoogleCloudPlatform:developfrom
kadupoornima:fix/redundant-gke-switch

Conversation

@kadupoornima

@kadupoornima kadupoornima commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Simplify GenerateGKENodeSelectorLabel by Removing Redundant Switch.

The Problem

The GenerateGKENodeSelectorLabel function maps accelerator types to GKE node selector labels. It contains a hardcoded fallback switch statement for "direct values":

// Fallback for direct values
switch resolvedLower {
case "nvidia-tesla-a100", "tpu-v4-podslice", "tpu-v6e-slice", "tpu-v5p-slice", "tpu-v5-lite-podslice":
    return acceleratorType
}

This switch statement is completely redundant. If any of these values (or their prefixes) are passed to the function, they do not match any keys in the machineFamilyToLabelMap. As a result, the function naturally falls through all checks and returns acceleratorType unmodified at the end of the function anyway.

Maintaining this hardcoded list of direct values in a switch statement in addition to the map increases maintenance overhead and leads to duplication.

The Solution

Remove the redundant switch block entirely. Let the function rely on its natural fall-through behavior, which already returns the input string if no map keys match.

The Impact

  • Code Simplicity: Reduces the size and complexity of the function, making it easier to read and maintain.
  • Maintainability: Eliminates the risk of developers forgetting to keep the switch statement in sync with the map when adding new accelerators.

@kadupoornima kadupoornima requested a review from a team as a code owner June 24, 2026 11:43
@kadupoornima kadupoornima added the release-chore To not include into release notes label Jun 24, 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 cleans up the GKE job orchestrator by removing an unnecessary switch block that handled direct accelerator values. Since the function already defaults to returning the input string when no map matches are found, the switch was redundant. The change simplifies the codebase and improves maintainability, supported by newly added unit tests to verify the expected behavior.

Highlights

  • Code Simplification: Removed a redundant switch statement in GenerateGKENodeSelectorLabel that was unnecessary due to the function's existing fall-through logic.
  • Test Coverage: Added a comprehensive suite of unit tests for GenerateGKENodeSelectorLabel to ensure correct behavior for mapped families, unmapped values, and case sensitivity.
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.

@kadupoornima kadupoornima enabled auto-merge (squash) June 24, 2026 11:44

@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 removes a redundant fallback switch block from the GenerateGKENodeSelectorLabel function in gke_job_orchestrator.go and introduces a comprehensive unit test suite TestGenerateGKENodeSelectorLabel in gke_job_orchestrator_test.go to verify the label generation logic under various scenarios (including mapped families, old switch fallbacks, unmapped values, and case insensitivity). There are no review comments, and I have no additional feedback to provide.

return g.ApplyManifest(gkeManifestContent, outputManifestPath, opts.WorkloadName)
}

// TODO Use a map

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.

nit: Can you please remove this stray TODO as well.
LGTM otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-chore To not include into release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants