Skip to content

feat(validations): Add early conditional validation#5160

Merged
AdarshK15 merged 12 commits intoGoogleCloudPlatform:developfrom
AdarshK15:conditional-validators
Feb 11, 2026
Merged

feat(validations): Add early conditional validation#5160
AdarshK15 merged 12 commits intoGoogleCloudPlatform:developfrom
AdarshK15:conditional-validators

Conversation

@AdarshK15
Copy link
Copy Markdown
Member

@AdarshK15 AdarshK15 commented Jan 30, 2026

Summary

This PR introduces the conditional validator to the module-scoped validation framework. This validator allows module settings to be validated based on the state or value of another "trigger" setting and ensures that constraints are caught earlier in the deployment lifecycle.

Key Changes

New ConditionalValidator: Implements a logic-based validator that enforces that a dependent variable is set or matches a specific value only when a trigger variable condition is met. This is useful for cross-variable dependencies (e.g., if feature X is enabled, setting Y is required).

Functionality:

  • If trigger_value or dependent_value is omitted, the validator checks if the variable is simply "set" (non-null, true bool, positive integer, and non-empty list/tuple/map).
  • If a value is provided, it must match exactly. This also supports matching against null to check if a variable is explicitly omitted.
  • Optional Handling: Respects the optional flag to skip validation if the trigger variable is not found in the blueprint.

Testing

Added comprehensive unit tests covering:

  • Trigger scenarios: checking both "is set" logic and "exact match" logic.
  • Dependent enforcement: validating that variables are either set or match expected values when conditions are met.
  • Verification of error messages to ensure they correctly report mismatched values.

Documentation

Updated docs/blueprint-validation.md to include usage instructions and examples for the new conditional validator.

@AdarshK15 AdarshK15 added the release-chore To not include into release notes label Jan 30, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AdarshK15, 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 significantly enhances the module validation capabilities by introducing a conditional validator. This new feature allows for the definition of rules where the validity of one configuration setting is dependent on the value or presence of another, ensuring that complex inter-variable constraints are enforced early in the deployment lifecycle. This improves the robustness and reliability of module configurations by preventing invalid states.

Highlights

  • New Conditional Validator: Introduced a new ConditionalValidator to the module-scoped validation framework, enabling validation of settings based on the state or value of other 'trigger' settings.
  • Flexible Condition Logic: The validator supports checking if a variable is simply 'set' (non-null, true, positive number, non-empty collection) or if it matches an exact specified value, including null.
  • Enhanced Error Handling and Helper Functions: Added utility functions like isVarSet, convertToCty, ValuesMatch, and formatValue to facilitate robust conditional logic and clear error messages within the validation system.
  • Expanded Validation Rules: Applied the new conditional validator to several metadata.yaml files, including nodeset_tpu, slurm_files, and gke-node-pool, to enforce specific inter-variable dependencies.
  • Comprehensive Testing and Documentation: Included extensive unit tests for the new validator's logic and updated docs/blueprint-validation.md with usage instructions and examples.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 a valuable conditional validator, enhancing the module validation capabilities by allowing cross-variable dependency checks. The implementation is robust, covering various scenarios for trigger and dependent variables. The inclusion of comprehensive unit tests and clear documentation is excellent and aligns with the project's standards for quality and maintainability. I've found one potential issue in the helper logic that could affect scenarios with empty lists, which I've detailed in a specific comment. Overall, this is a great addition to the toolkit.

@AdarshK15 AdarshK15 marked this pull request as ready for review January 30, 2026 10:44
@AdarshK15 AdarshK15 requested review from a team and samskillman as code owners January 30, 2026 10:44
@AdarshK15 AdarshK15 force-pushed the conditional-validators branch from a196509 to d541839 Compare February 5, 2026 04:50
@AdarshK15 AdarshK15 added release-key-new-features Added to release notes under the "Key New Features" heading. and removed release-chore To not include into release notes labels Feb 5, 2026
@AdarshK15
Copy link
Copy Markdown
Member Author

/gemini review

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 a new conditional validator, which is an excellent feature for enforcing dependencies between module settings. The implementation is well-structured, following Go best practices, and is supported by comprehensive unit tests and clear documentation. The immediate adoption of this new validator in several modules demonstrates its utility. The overall quality of the change is high. I have one minor suggestion to improve a comment for future maintainability.

@AdarshK15 AdarshK15 merged commit 8a5e0db into GoogleCloudPlatform:develop Feb 11, 2026
12 of 78 checks passed
@AdarshK15 AdarshK15 deleted the conditional-validators branch March 15, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-key-new-features Added to release notes under the "Key New Features" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants