Skip to content
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

[v2.8]Fix controller generation to add test session to generated controllers #237

Conversation

floatingman
Copy link
Contributor

Refactor test session related functions in codegen

The code has been refactored to generalize the function of adding test sessions to different controllers. The functions for importing test session in each controller were renamed and refactored into a unified function, which is now called inside each controller-specific function. This approach aims to reduce code repetition and complexity.

Add session to struct and function in generated files

Expanded the appendSessionToStructInFile function to appendNewlineToBlockInFile, which generalizes line additions to the end of any struct or function block. This update improves code reusability. Utilized this function to add a session to multiple generated interface files.

Add session to struct in management controllers

A new function has been implemented to append a session to a struct in the management controllers. The function reads a file, locates a given struct, and then adds a new session prior to the closing brace of the struct. This change will be beneficial for the management of sessions within the struct.

Refactor import addition function for error handling

Updated the addImport function in codegen/main.go to handle and return errors instead of triggering panic. This change also includes verification of the import path and logic adjustments for adding a new import to the parsed file. These updates ensure more robust and error-resistant code execution.

Add 'session' import to controller files

This commit introduces additional functions to automatically add 'session' imports into controller files. Functions have been added to process and add this import into management, apps, and core controller files specifically. The new functions will walk the respective directory's file-paths and add the specified import to all 'interface.go' files.

Refactor factory method parameter replacement in codegen

The factory methods in the code generator have been refactored. The parameters passed into these methods have been modified to include the timestamp (TS) option. Also, excess white space in the code has been removed to adhere to clean coding principles.

This commit updates the interfaces for ClusterRepo and App controllers in the catalog.cattle.io package. The old methods have been replaced with more abstract methods from the wrangler v2 package. The codebase has been simplified significantly, making it easier to add methods in the future. In addition, the copyright year has been updated to 2024.

Added documentation

Refactor test session related functions in codegen

The code has been refactored to generalize the function of adding test sessions to different controllers. The functions for importing test session in each controller were renamed and refactored into a unified function, which is now called inside each controller-specific function. This approach aims to reduce code repetition and complexity.

Add session to struct and function in generated files

Expanded the appendSessionToStructInFile function to appendNewlineToBlockInFile, which generalizes line additions to the end of any struct or function block. This update improves code reusability. Utilized this function to add a session to multiple generated interface files.

Add session to struct in management controllers

A new function has been implemented to append a session to a struct in the management controllers. The function reads a file, locates a given struct, and then adds a new session prior to the closing brace of the struct. This change will be beneficial for the management of sessions within the struct.

Refactor import addition function for error handling

Updated the addImport function in codegen/main.go to handle and return errors instead of triggering panic. This change also includes verification of the import path and logic adjustments for adding a new import to the parsed file. These updates ensure more robust and error-resistant code execution.

Add 'session' import to controller files

This commit introduces additional functions to automatically add 'session' imports into controller files. Functions have been added to process and add this import into management, apps, and core controller files specifically. The new functions will walk the respective directory's file-paths and add the specified import to all 'interface.go' files.

Refactor factory method parameter replacement in codegen

The factory methods in the code generator have been refactored. The parameters passed into these methods have been modified to include the timestamp (TS) option. Also, excess white space in the code has been removed to adhere to clean coding principles.
@floatingman floatingman force-pushed the updates/v2.8-fix-controller-generation-code branch from 92fa531 to a66b4c1 Compare July 24, 2024 00:58
@floatingman floatingman requested a review from a team July 24, 2024 01:01
@floatingman
Copy link
Contributor Author

Most of the file changes are due to me running generate, which wasn't run in a long time, and dates were updated. The rest of the changes are because I corrected the formatting.

The main.go and generate.go files are the two files where I made most of the logic and function changes.

Copy link

@igomez06 igomez06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@floatingman floatingman merged commit 6b00b57 into rancher:release/v2.8 Jul 24, 2024
1 check passed
@floatingman floatingman deleted the updates/v2.8-fix-controller-generation-code branch July 24, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants