-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add bootstrap command and implement bootstrap functionality for Deckhouse modules #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… Deckhouse modules
…r improved flexibility - Modified `downloadAndExtractTemplate` and `moveExtractedContent` functions to accept a directory parameter. - Updated tests to reflect changes in function signatures and ensure correct directory handling during file operations.
- Updated `InitBootstrapFlagSet` to use shorthand flags for repository type, URL, and directory parameters, improving usability and flexibility.
…ction signature - Added validation to ensure a module name is provided when executing the bootstrap command. - Updated `RunBootstrap` function to accept the module name as a parameter. - Implemented `getModuleName` function to read and extract the module name from `module.yaml` file.
…unctionality - Added tests for `RunBootstrap`, `replaceModuleName`, and `replaceValuesModuleName` to ensure correct functionality. - Implemented logic to replace module names in files and update references in YAML configurations. - Enhanced error handling in tests for invalid scenarios, including file path and URL checks.
…ctionality - Renamed package from `bootstap` to `bootstrap` for consistency and clarity. - Updated `bootstrapCmdFunc` to utilize a structured `BootstrapConfig` for improved readability and maintainability. - Added comprehensive tests for `RunBootstrap` and related functions to ensure robust functionality and error handling.
- Updated the WriteProto method to use http.NewRequestWithContext for better context propagation. - Ensured that the HTTP request utilizes the provided context for improved request handling and cancellation support.
- Replaced assertions with require statements in bootstrap tests for better error handling and test clarity. - Updated file permission constants for consistency and security. - Enhanced the downloadFile function to limit file size, preventing potential DoS attacks. - Cleaned up test code by removing unused helper functions and ensuring proper directory restoration in tests.
- Added error logging for bootstrap command execution failures to enhance observability. - Implemented validation for repository types in RunBootstrap to ensure only valid types are processed. - Added directory creation logic if the specified directory does not exist, improving robustness. - Enhanced cleanup logic to remove unnecessary directories and files based on repository type.
- Modified downloadAndExtractTemplate function to accept BootstrapConfig instead of a directory string for improved flexibility. - Updated repository URL handling to utilize the config's RepositoryURL if provided. - Adjusted calls to moveExtractedContent to use the directory from the BootstrapConfig, enhancing code clarity and maintainability.
- Added tests for various bootstrap scenarios including GitLab repository type, invalid repository types, and non-existent directories. - Improved error handling tests for file operations, ensuring robustness against read/write errors and invalid paths. - Enhanced test coverage for the RunBootstrap function, validating expected outcomes and error messages.
- Introduced the bootstrap package with core functionalities for initializing modules. - Added tests for various scenarios including successful bootstraps, handling non-empty directories, and validating module name replacements. - Enhanced error handling in tests to cover edge cases such as invalid repository types and file operations. - Implemented logic for downloading and extracting templates, ensuring robust directory management and file operations.
- Added tests for the downloadFile function using a mock HTTP server to simulate various scenarios, including successful downloads, invalid URLs, and server errors. - Improved error assertions to ensure proper handling of download failures and file creation issues. - Updated existing tests to utilize the mock server for consistency and reliability in testing file downloads.
- Enhanced the TestDownloadFile function to include error handling for zip file creation and writing operations. - Updated assertions to use assert.Positive for better clarity in verifying downloaded file size. - Improved error handling in mock server responses to ensure robustness against potential failures during file operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new bootstrap
command to initialize Deckhouse modules from a template, including flag support, the core bootstrap logic, and comprehensive tests.
- Add
bootstrap
subcommand with flags for repository type, URL, and target directory - Implement bootstrap workflow in
internal/bootstrap
(download, extract, replace names, cleanup) - Integrate command in
cmd/dmt/root.go
and update flag definitions; minor HTTP client context improvement inpromremote.go
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
internal/promremote/promremote.go | Use NewRequestWithContext instead of Do(req.WithContext) |
internal/flags/flags.go | Add Bootstrap* globals and InitBootstrapFlagSet |
internal/bootstrap/bootstrap.go | Implement full bootstrap logic |
internal/bootstrap/bootstrap_test.go | Add tests covering bootstrap behavior and errors |
cmd/dmt/root.go | Register bootstrap command and handler |
Comments suppressed due to low confidence (2)
cmd/dmt/root.go:65
- [nitpick] The Long description is very generic; consider updating it to describe the command's purpose (e.g., "Initializes a new Deckhouse module from a template").
Long: `A lot of useful bootstraps`,
internal/flags/flags.go:70
- [nitpick] Consider enhancing this flag's help text to clarify the allowed values and default behavior; for example, note that the default repository type is GitHub.
bootstrap.StringVarP(&BootstrapRepositoryType, "repository-type", "t", "github", "repository type [github | gitlab]")
…tion - Skipped integration tests that require a real template archive with module.yaml for the TestRunBootstrap and TestRunBootstrapWithNonExistentDirectory functions. - Enhanced TestExtractZip to verify direct extraction of files without a root directory and added checks for module.yaml. - Adjusted error assertions in TestExtractZipNoRootDirectory to reflect changes in expected error messages. - Improved directory creation logic in extractZip to use consistent permissions.
- Added directory creation logic in TestExtractZip to ensure the extraction directory exists before extraction. - Enhanced assertions to verify the structure and content of extracted files, including checks for root directory and file contents. - Updated error assertions in TestExtractZipNoRootDirectory to reflect the correct expected error message. - Improved logging for extracted files to aid in debugging and verification of extraction results.
- Included reminders in the RunBootstrap function to inform users about necessary environment variables for CI/CD pipelines. - Enhanced user experience by providing clear instructions on required variables for external modules and registry configurations.
…validation - Added BootstrapModule flag to specify the module name during bootstrap. - Implemented validation for BootstrapRepositoryType to ensure it is either 'github' or 'gitlab'. - Updated bootstrap command logic to handle errors for missing module name and invalid repository type.
- Refactored the moveExtractedContent function to utilize moveFileOrDirectory for moving files and directories. - Implemented moveFileOrDirectory with a fallback to copy-and-remove for cross-filesystem compatibility. - Added copyAndRemove, copyDirectoryAndRemove, and copyFileAndRemove functions to handle file and directory copying and removal. - Enhanced error handling and logging for file operations to improve robustness and traceability.
…ory type - Updated the RunBootstrap function to display reminders for necessary CI/CD variables only when the repository type is GitLab. - Enhanced user guidance by ensuring relevant instructions are provided based on the selected repository configuration.
…rap tests - Deleted TestRunBootstrapWithInvalidRepositoryType as it was deemed unnecessary. - Focused on maintaining relevant test cases that align with current repository type validation logic.
- Updated error assertions in crds_test.go to create a map of expected error messages for easier comparison. - Implemented checks to ensure that all actual errors match expected errors, regardless of order. - Improved test robustness by ensuring unexpected errors are clearly reported.
…bootstrap Signed-off-by: Pavel Okhlopkov <[email protected]>
Signed-off-by: Pavel Okhlopkov <[email protected]>
…dation and run Signed-off-by: Pavel Okhlopkov <[email protected]>
Signed-off-by: Pavel Okhlopkov <[email protected]>
…ions Signed-off-by: Pavel Okhlopkov <[email protected]>
Signed-off-by: Pavel Okhlopkov <[email protected]>
Signed-off-by: Pavel Okhlopkov <[email protected]>
Signed-off-by: Pavel Okhlopkov <[email protected]>
This pull request introduces a new
bootstrap
command for Deckhouse modules, refactors the existinggen
command, and improves error handling and test validation in various parts of the codebase. The most significant changes include adding thebootstrap
command functionality, updating flag definitions, enhancing test assertions, and improving HTTP client behavior.PR Description: Add Bootstrap Command for Deckhouse Module Development
🎯 Overview
This PR introduces a new
bootstrap
command to the Deckhouse Module Tool (dmt), enabling developers to quickly scaffold new Deckhouse modules from an official template. This significantly streamlines the module development workflow by automating the initial setup process.🚀 Key Features
New Bootstrap Command
Multi-Platform CI/CD Support
Template Management
📋 Use Cases
1. Quick Module Development Setup
2. Enterprise/Custom Templates
# Use organization-specific template dmt bootstrap internal-tool --repository-url https://github.com/myorg/custom-template/archive/main.zip
3. Team Standardization
🔧 Technical Implementation
Command Structure
github
orgitlab
Template Processing
Smart String Replacement
.Values.templateName
to.Values.moduleName
(camelCase)templateName.internal
patterns🎛️ Configuration Options
--pipeline
-p
github
github
orgitlab
)--directory
-d
.
--repository-url
-r
📖 Post-Bootstrap Guidance
The command provides platform-specific setup instructions.
This bootstrap functionality dramatically reduces the time and effort required to start developing new Deckhouse modules, ensuring consistency and best practices across all module projects.