Skip to content

Sub-block targeting and validation#5405

Draft
SikaGrr wants to merge 3 commits intoGoogleCloudPlatform:developfrom
SikaGrr:origin/subblock
Draft

Sub-block targeting and validation#5405
SikaGrr wants to merge 3 commits intoGoogleCloudPlatform:developfrom
SikaGrr:origin/subblock

Conversation

@SikaGrr
Copy link
Copy Markdown
Contributor

@SikaGrr SikaGrr commented Mar 25, 2026

Multiple sub-blocks can be specified. Validation (and url forming) only occurs if the variables are defined and super-slicing is enabled.

@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 enhances the GKE node pool module by introducing the capability to target specific reservation sub-blocks. This allows for more granular control over resource allocation, particularly for advanced "super-slicing" topologies. The changes include new configuration variables, a data source to fetch sub-block information, and robust pre-conditions to validate that sub-block targeting is enabled correctly, has adequate capacity, and points to healthy resources.

Highlights

  • Sub-block Targeting: Implemented support for targeting specific reservation sub-blocks within GKE node pools, allowing for more granular resource allocation.
  • New Configuration Variables: Introduced new input variables reservation_block, reservation_sub_block, and enable_slice_controller to manage the configuration of sub-block targeting.
  • Enhanced Validation: Added comprehensive validation logic to ensure correct usage, sufficient capacity, and health of targeted reservation sub-blocks before node pool creation.
  • Dynamic Reservation URL Formation: Updated the logic for constructing reservation URLs to incorporate sub-block identifiers when the enable_slice_controller is active.
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 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 counter productive. 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.

Copy link
Copy Markdown
Contributor

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

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 support for GKE Slice Controller, reservation blocks, and reservation sub-blocks in the GKE node pool module. It adds new variables for reservation_block, reservation_sub_block, and enable_slice_controller, along with new data sources and updated logic to construct reservation resource names based on these new parameters. The review comments suggest an improvement opportunity to enhance readability and maintainability by extracting the complex conditional logic related to enable_slice_controller and reservation block/sub-block variables into a local variable, as this logic is repeated across multiple parts of the code.


locals {
requested_nodes = coalesce(var.static_node_count, var.initial_node_count, var.autoscaling_total_max_nodes, 0)
}
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.

medium

To improve readability and reduce repetition, consider extracting the complex conditional logic for enable_slice_controller and reservation block/sub-block variables into a local variable. This makes the code easier to understand and maintain.

This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6).

  requested_nodes = coalesce(var.static_node_count, var.initial_node_count, var.autoscaling_total_max_nodes, 0)
  is_sub_block_targeting_enabled = var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "" && var.reservation_sub_block != null && var.reservation_sub_block != ""
References
  1. Code should be easy to understand, modify, and extend. (link)


data "google_compute_reservation_sub_block" "this" {
for_each = (
(var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "" && var.reservation_sub_block != null && var.reservation_sub_block != "") ?
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.

medium

Using the newly introduced is_sub_block_targeting_enabled local variable here improves readability by abstracting the complex conditional logic. This makes the for_each condition more concise and easier to grasp at a glance.

This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6).

    local.is_sub_block_targeting_enabled ?
References
  1. Code should be easy to understand, modify, and extend. (link)

length(local.input_reservation_suffixes[i]) > 0 ?
format("%s%s", r.name, local.input_reservation_suffixes[i]) :
"projects/${r.project}/reservations/${r.name}"
(var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "" && var.reservation_sub_block != null && var.reservation_sub_block != "") ?
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.

medium

Using the is_sub_block_targeting_enabled local variable here enhances readability by simplifying the conditional expression for active_reservation_values. This reduces duplication and makes the intent clearer.

This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6).

    local.is_sub_block_targeting_enabled ?
References
  1. Code should be easy to understand, modify, and extend. (link)

specific_reservation_name = length(local.input_reservation_names) > 0 ? local.input_reservation_names[0] : ""
default_reservation_values = [
for zone in try(var.zones, []) :
(var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "" && var.reservation_sub_block != null && var.reservation_sub_block != "") ?
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.

medium

Replacing the repeated conditional logic with the is_sub_block_targeting_enabled local variable in default_reservation_values improves code clarity and maintainability. This helps in avoiding errors if the underlying logic needs to change in the future.

This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6).

    local.is_sub_block_targeting_enabled ?
References
  1. Code should be easy to understand, modify, and extend. (link)

error_message = "Spot consumption option only works with reservation_affinity consume_reservation_type NO_RESERVATION."
}
precondition {
condition = (var.reservation_sub_block == null || var.reservation_sub_block == "") || (var.enable_slice_controller && var.reservation_block != null && var.reservation_block != "")
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.

medium

Leveraging the is_sub_block_targeting_enabled local variable here simplifies the precondition's condition expression. This makes the validation logic more readable and consistent with other parts of the module where this complex condition is used.

This aligns with the repository's focus on "Maintainability: Code should be easy to understand, modify, and extend." (Repository Style Guide, line 6).

      condition     = (var.reservation_sub_block == null || var.reservation_sub_block == "") || local.is_sub_block_targeting_enabled
References
  1. Code should be easy to understand, modify, and extend. (link)

@github-actions github-actions bot added the external PR from external contributor label Mar 25, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant