Skip to content

feat(validations): Add early required validation#5166

Open
AdarshK15 wants to merge 10 commits intoGoogleCloudPlatform:developfrom
AdarshK15:required-validator
Open

feat(validations): Add early required validation#5166
AdarshK15 wants to merge 10 commits intoGoogleCloudPlatform:developfrom
AdarshK15:required-validator

Conversation

@AdarshK15
Copy link
Member

@AdarshK15 AdarshK15 commented Feb 2, 2026

Summary

This PR introduces the required validator to the module-scoped validation framework. It allows enforcing the presence of mandatory settings or explicitly forbid specific settings (e.g., for deprecation) directly within metadata.yaml. By moving these checks into the metadata layer, these constraints are validated earlier in the deployment lifecycle.

Key Changes

New RequiredValidator: Implements a validator to enforce the presence or absence of module settings.

Functionality:

  • Required (Default): Validates that all variables in the provided list are "set".
  • Forbidden: When configured with forbidden: true, validates that none of the specified variables are "set". This is
    useful for preventing the use of deprecated variables or enforcing "must not be set" constraints.
  • Active: A variable is considered "set" if it is a non-empty string, a non-zero number, a true boolean, or a
    non-empty collection (list/map).

Testing

Added unit tests in pkg/validators/metadata_validators_test.go covering:

  • Pass/Fail scenarios for missing required variables.
  • Pass/Fail scenarios for present forbidden variables.

Documentation

Updated docs/blueprint-validation.md to include usage instructions and YAML examples for both enforcing required
variables and forbidding unwanted ones.

@AdarshK15 AdarshK15 added the release-chore To not include into release notes label Feb 2, 2026
@gemini-code-assist
Copy link
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-scoped validation capabilities by introducing a versatile 'required' validator. This new validator allows module authors to define precise constraints on input variables within their metadata.yaml files, ensuring that configurations meet necessary criteria or avoid deprecated settings. By integrating these checks earlier in the deployment process, the change aims to improve the robustness and reliability of module deployments.

Highlights

  • New RequiredValidator: Introduced a new RequiredValidator to the module-scoped validation framework, enabling enforcement of mandatory or forbidden settings directly within metadata.yaml files.
  • Flexible Validation Logic: The RequiredValidator supports two modes: 'required' (default) to ensure variables are set, and 'forbidden' to ensure variables are not set (useful for deprecation). A variable is considered 'set' if it's a non-empty string, non-zero number, true boolean, or non-empty collection.
  • Expanded Validation Coverage: Applied the new required validator to various metadata.yaml files across different modules to enforce the presence of critical variables (e.g., instance_image.project, zone) and to explicitly forbid deprecated variables (e.g., enable_smt, disable_smt, scopes, job_template_contents).
  • Comprehensive Testing: Added unit tests for the RequiredValidator in pkg/validators/metadata_validators_test.go, covering pass/fail scenarios for both required and forbidden variables, as well as custom error messages.
  • Updated Documentation: The docs/blueprint-validation.md file has been updated to include detailed usage instructions and YAML examples for the new RequiredValidator, demonstrating how to enforce required variables and forbid unwanted ones.
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
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 required validator, which is effectively used across several modules to enforce required settings and deprecate old ones. The implementation is solid, but I've identified a couple of logic issues in the new helper functions that could lead to incorrect validation behavior in edge cases. Specifically, the logic for determining if a variable is 'set' needs refinement for empty collections and numeric zero values. I've also noted a minor formatting issue in an error message. The accompanying documentation and test cases are a great start.

@AdarshK15 AdarshK15 marked this pull request as ready for review February 2, 2026 05:08
@AdarshK15 AdarshK15 requested review from a team and samskillman as code owners February 2, 2026 05:08
@AdarshK15 AdarshK15 changed the title Add required validators feat(validations): Add early required validation Feb 2, 2026
@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
Member Author

/gemini review

Copy link
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 required validator, enhancing the module validation framework. The implementation is solid, with comprehensive tests and clear documentation. I've suggested one refactoring in pkg/validators/metadata_validators.go to improve code consistency and maintainability by leveraging an existing helper function, which aligns with our goal for technical excellence and maintainable code.

arpit974
arpit974 previously approved these changes Feb 11, 2026
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