Skip to content

feat: implement lean deployment modules by selective copying#5482

Merged
cboneti merged 5 commits into
GoogleCloudPlatform:developfrom
cboneti:feat/lean-deployment-modules
May 7, 2026
Merged

feat: implement lean deployment modules by selective copying#5482
cboneti merged 5 commits into
GoogleCloudPlatform:developfrom
cboneti:feat/lean-deployment-modules

Conversation

@cboneti

@cboneti cboneti commented Apr 10, 2026

Copy link
Copy Markdown
Member
  • Added dependency resolution in pkg/modulereader using tfconfig
  • Refactored modulewriter to copy only referenced embedded modules
  • Added unit tests and an integration test verifying terraform init

Submission Checklist

NOTE: Community submissions can take up to 2 weeks to be reviewed.

Please take the following actions before submitting this pull request.

  • Fork your PR branch from the Toolkit "develop" branch (not main)
  • Test all changes with pre-commit in a local branch #
  • Confirm that "make tests" passes all tests
  • Add or modify unit tests to cover code changes
  • Ensure that unit test coverage remains above 80%
  • Update all applicable documentation
  • Follow Cluster Toolkit Contribution guidelines #

@cboneti cboneti added the release-improvements Added to release notes under the "Improvements" heading. label Apr 10, 2026
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 4786b7f to 9404af1 Compare April 10, 2026 20:51
@cboneti

cboneti commented Apr 10, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 9404af1 to c2f8045 Compare April 10, 2026 20:55
@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 introduces a significant optimization to how embedded modules are handled during deployment. The system now intelligently resolves and copies only those embedded modules that are directly referenced or are transitive dependencies of referenced modules. This change aims to create leaner and more efficient deployment directories by avoiding the copying of unneeded modules.

Highlights

  • Dependency Resolution: Implemented dependency resolution for embedded modules using tfconfig in pkg/modulereader to identify all necessary local module dependencies.
  • Selective Module Copying: Refactored pkg/modulewriter to selectively copy only referenced embedded modules and their transitive dependencies, rather than copying all embedded modules.
  • Testing: Added comprehensive unit tests for the new dependency resolution logic and an integration test to verify terraform init with the selective copying mechanism.
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.

gemini-code-assist[bot]

This comment was marked as outdated.

@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from c2f8045 to c13330e Compare April 10, 2026 21:02
@cboneti

cboneti commented Apr 10, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 implements a 'lean deployment' strategy for embedded modules by resolving and copying only the necessary transitive local dependencies instead of the entire modules directory. It introduces GetLocalDependencies and ResolveDependencies in pkg/modulereader and refactors pkg/modulewriter to utilize these functions. Feedback suggests refactoring duplicated module loading logic in hcl_utils.go into a shared helper and suggests documenting that transitive dependency resolution is currently limited to embedded modules.

Comment thread pkg/modulereader/hcl_utils.go
Comment thread pkg/modulereader/resolver.go

@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 implements transitive local dependency resolution for modules, ensuring that all required local sub-modules are correctly identified and copied during deployment generation. Key changes include the addition of GetLocalDependencies and ResolveDependencies functions, refactoring the modulewriter to utilize these functions, and updating path manipulations to use filepath for better cross-platform compatibility. Comprehensive unit and integration tests have been added to validate the new functionality. Feedback suggests refactoring duplicated module loading logic in hcl_utils.go into a shared helper function to improve maintainability and prevent potential nil-pointer panics.

Comment thread pkg/modulereader/hcl_utils.go Outdated
Comment thread pkg/modulereader/hcl_utils.go Outdated
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from c13330e to 78fc42f Compare April 13, 2026 08:18
@cboneti

cboneti commented Apr 13, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 implements transitive dependency resolution for Terraform modules to optimize the deployment process. By introducing GetLocalDependencies and ResolveDependencies, the toolkit now identifies and copies only the specific embedded modules required by a blueprint, rather than copying the entire modules library. The changes include refactoring modulewriter to utilize this new logic, standardizing on filepath for local path operations, and adding comprehensive unit and integration tests. Review feedback recommends normalizing input module paths to ensure robust deduplication during dependency resolution and removing a redundant path cleaning operation.

Comment thread pkg/modulereader/resolver.go
Comment thread pkg/modulereader/resolver.go Outdated
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 78fc42f to b784b94 Compare April 14, 2026 18:01
@cboneti

cboneti commented Apr 14, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@cboneti cboneti marked this pull request as ready for review April 14, 2026 18:02
@cboneti cboneti requested review from a team and samskillman as code owners April 14, 2026 18:02
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from b784b94 to 518c544 Compare April 14, 2026 18:06

@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 implements selective copying of embedded modules by introducing a transitive dependency resolver. It refactors module loading to trace local dependencies and updates the deployment writer to copy only referenced embedded modules. Feedback highlights that dependency resolution is currently limited to embedded modules, suggesting this behavior be documented to clarify support for user-provided local modules.

Comment thread pkg/modulereader/resolver.go
@cboneti cboneti marked this pull request as draft April 14, 2026 18:07
@cboneti

cboneti commented Apr 14, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 implements a dependency-aware module copying process to ensure only necessary embedded modules are included in deployments. Key changes include the addition of a dependency resolver in pkg/modulereader, refactoring pkg/modulewriter to utilize transitive dependency information, and the introduction of comprehensive unit and integration tests. Review feedback highlights opportunities to clarify path documentation in GetLocalDependencies, optimize slice allocations for performance in copyGroupSources, and eliminate redundant copies of Packer modules to further streamline the deployment output.

Comment thread pkg/modulereader/hcl_utils.go Outdated
Comment thread pkg/modulewriter/modulewriter.go Outdated
Comment thread pkg/modulewriter/modulewriter.go Outdated
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 518c544 to 87a8973 Compare April 15, 2026 09:06
@cboneti

cboneti commented Apr 15, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 implements a dependency resolution mechanism for embedded modules to optimize the deployment generation process. Instead of copying the entire embedded modules directory, the toolkit now identifies and copies only the specific modules required by a blueprint and their transitive local dependencies. This is achieved through new functions GetLocalDependencies and ResolveDependencies in the modulereader package. Additionally, the PR refactors path handling across several files to prefer filepath over path for OS-level operations and adds comprehensive unit and integration tests. Feedback is provided regarding cross-platform path normalization on Windows and idiomatic usage of filepath.Join.

Comment thread pkg/modulereader/resolver.go
Comment thread pkg/modulewriter/modulewriter.go Outdated
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 87a8973 to d28f9a2 Compare April 16, 2026 11:27
@cboneti

cboneti commented Apr 16, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 optimizes the deployment process by introducing a dependency resolver that identifies and copies only the required transitive local dependencies for embedded modules. It also refactors path handling to use filepath for better cross-platform compatibility and improves error reporting during module loading. The review feedback suggests including the module source path in error messages to further improve debuggability.

Comment thread pkg/modulereader/hcl_utils.go Outdated
Comment thread pkg/modulereader/hcl_utils.go Outdated
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from d28f9a2 to c8223e9 Compare April 16, 2026 15:42
@cboneti

cboneti commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 introduces a shared directory mechanism for embedded modules, centralizing them within a _modules directory to handle transitive dependencies more effectively. Key updates include reserving specific group names, implementing a dependency resolver, and refactoring the module writer to support this new structure. Feedback suggests enhancing the robustness of module copying by ensuring parent directories are created and recommends using post-order traversal in the dependency resolver to ensure dependencies are listed before the modules that rely on them.

Comment thread pkg/modulewriter/modulewriter.go
Comment thread pkg/modulereader/resolver.go
@cboneti

cboneti commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review! Here is my response to the feedback points:

  1. Ensuring parent directories are created: I agree this is a good point for robustness. I will add os.MkdirAll to ensure parent directories exist before copying modules to the shared directory.
  2. Post-order traversal: I don't think this is necessary. Terraform reads all .tf files in the directory and builds its own dependency graph regardless of the order in which files are listed or copied. Order of file copying is also irrelevant. Therefore, the current traversal order should be sufficient.

I will implement the fix for point 1 shortly.

@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 8da6ecc to 5b1ac6d Compare April 30, 2026 15:23
@cboneti

cboneti commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@cboneti

cboneti commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

/gcbrun

@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 introduces a shared directory mechanism (_modules) for embedded modules to optimize the deployment structure and avoid redundant copies. It implements transitive dependency resolution for embedded modules and updates path handling to use filepath for improved cross-platform compatibility. Feedback suggests optimizing the module copying process by using a package-level map to track created directories, thereby reducing redundant os.MkdirAll calls.

Comment thread pkg/modulewriter/modulewriter.go
@cboneti cboneti marked this pull request as ready for review April 30, 2026 15:39
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 5b1ac6d to 791ea0b Compare April 30, 2026 15:55
@cboneti

cboneti commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

/gcbrun

1 similar comment
@cboneti

cboneti commented May 3, 2026

Copy link
Copy Markdown
Member Author

/gcbrun

@cboneti

cboneti commented May 3, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 restructures the deployment generation process to use a shared _modules directory for embedded modules, supported by new logic for resolving transitive local dependencies. This ensures that nested module references are correctly handled in the output. A review comment suggested an optimization to filter for Terraform modules during dependency collection to avoid redundant processing of Packer modules, which are managed separately.

Comment thread pkg/modulewriter/modulewriter.go
cboneti added 4 commits May 3, 2026 10:52
* Added dependency resolution in pkg/modulereader using tfconfig

* Refactored modulewriter to copy only referenced embedded modules

* Added unit tests and an integration test verifying terraform init
Fix cross-module file references by moving embedded modules to a shared directory at the deployment root instead of per-group directories.

Add validation to prevent deployment groups from using reserved names (.ghpc, _modules). Use a constant for the directory name to avoid hardcoding.

TAG=agy

CONV=ba441f3b-312a-4a96-a27a-dc531d793750
Fixes path failures in GCluster ML A3 Slurm blueprints. The path to long-prolog-slurm.conf.tpl inside the controller module etc/ directory was hardcoded as modules/embedded/.... Since all embedded modules are now stored under a single shared root directory _modules/embedded/ to fix cross-module references, these hardcoded paths in the blueprints must be updated to points to the new shared directory relative to the group directory (../_modules/embedded/...).

TAG=agy

CONV=ba441f3b-312a-4a96-a27a-dc531d793750
Packer modules are managed and copied separately, and they do not share HCL dependencies like Terraform modules. Filtering them out from the dependency collection loop prevents redundant processing and parsing attempts by the HCL resolver.

TAG=agy

CONV=ba441f3b-312a-4a96-a27a-dc531d793750
@cboneti cboneti force-pushed the feat/lean-deployment-modules branch from 222678a to 320422f Compare May 5, 2026 08:01
@cboneti

cboneti commented May 5, 2026

Copy link
Copy Markdown
Member Author

/gcbrun

@cboneti

cboneti commented May 5, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 introduces a shared directory structure (_modules) for embedded modules within deployments, enabling the resolution and inclusion of transitive local dependencies. Key changes include the implementation of a dependency resolver using depth-first search in pkg/modulereader, updates to the module writer to centralize embedded modules, and the reservation of the _modules name in group validation. Additionally, several files were refactored to use filepath instead of path for better cross-platform compatibility. Feedback is provided to ensure that parent directories are explicitly created when copying non-embedded modules to maintain consistency and prevent potential filesystem errors.

Comment thread pkg/modulewriter/modulewriter.go
Explicitly create parent directories using os.MkdirAll before copying non-embedded modules. This addresses code review feedback to ensure robustness and consistency with the shared embedded modules copying logic, preventing potential filesystem errors if the underlying loaders assume parent folders exist.

TAG=agy

CONV=ba441f3b-312a-4a96-a27a-dc531d793750
@cboneti

cboneti commented May 5, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 optimizes deployments by introducing a shared "_modules" directory for embedded modules, replacing the previous behavior of copying the entire modules library into each group. It includes a new dependency resolver that performs a depth-first search to identify and copy only the transitive local dependencies required by the blueprint. Additionally, the group name validation was updated to reserve ".ghpc" and "_modules". A suggestion was made to improve the consistency of string comparisons in the group name validation logic.

Comment thread pkg/config/config.go
@cboneti

cboneti commented May 5, 2026

Copy link
Copy Markdown
Member Author

In principle, babysit ran all the regression tests in the past 2 week.

@cboneti cboneti enabled auto-merge May 7, 2026 12:08
@cboneti cboneti merged commit be19b80 into GoogleCloudPlatform:develop May 7, 2026
14 of 80 checks passed
@cboneti cboneti deleted the feat/lean-deployment-modules branch May 7, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-improvements Added to release notes under the "Improvements" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants