Sub-block targeting and validation#5405
Sub-block targeting and validation#5405SikaGrr wants to merge 3 commits intoGoogleCloudPlatform:developfrom
Conversation
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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) | ||
| } |
There was a problem hiding this comment.
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
- 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 != "") ? |
There was a problem hiding this comment.
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
- 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 != "") ? |
There was a problem hiding this comment.
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
- 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 != "") ? |
There was a problem hiding this comment.
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
- 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 != "") |
There was a problem hiding this comment.
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
- Code should be easy to understand, modify, and extend. (link)
Multiple sub-blocks can be specified. Validation (and url forming) only occurs if the variables are defined and super-slicing is enabled.