[Refactor]:simplify version info printing logic#5032
[Refactor]:simplify version info printing logic#5032feyounger wants to merge 5 commits intovolcano-sh:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello @feyounger, 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 focuses on refactoring the version information printing logic within the 'pkg/version' package. The primary goal is to enhance code readability, simplify the implementation, and improve maintainability by removing an unnecessary parameter and streamlining output formatting. These changes are purely internal and do not alter any user-facing behavior or functionality, addressing issue #5031. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors the version printing logic, which improves code clarity. However, it introduces a breaking change by modifying the signature of an exported function Info. This will break any external projects that rely on this function's signature. I have added a comment recommending to preserve backward compatibility if this package is used as a library.
|
|
||
| // Info returns an array of various service versions. | ||
| func Info(apiVersion string) []string { | ||
| func Info() []string { |
There was a problem hiding this comment.
Changing the signature of the exported function Info is a breaking API change. This will break any external projects that import this package and call this function. If this package is consumed as a library, this change should be reverted to maintain backward compatibility. A new function with the desired signature could be introduced instead if needed.
There was a problem hiding this comment.
Please create a new function instead.
|
Looks like a flaky e2e failure related to job lifecycle handling. |
hajnalmt
left a comment
There was a problem hiding this comment.
/priority low
We shouldn't break the existing API.
Please mark it as deprecated with a comment and create a new function. Also please don't forget to sign the DCO.
|
|
||
| // Info returns an array of various service versions. | ||
| func Info(apiVersion string) []string { | ||
| func Info() []string { |
There was a problem hiding this comment.
Please create a new function instead.
b9c2df5 to
a390eef
Compare
There was a problem hiding this comment.
Pull request overview
Refactors the pkg/version package’s version info printing/generation to reduce redundant formatting/parameter passing and make output more idiomatic.
Changes:
- Updated version printing to use
fmt.Printlnfor line-by-line output. - Introduced
GetInfo()helper and adjustedInfo()to delegate to it.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pkg/version/version.go
Outdated
| return GetInfo() | ||
| } | ||
|
|
||
| func GetInfo() []string { |
There was a problem hiding this comment.
Info(apiVersion string) now ignores its apiVersion argument and always returns info built from the package-level apiVersion. This is a behavior change for any callers that passed a custom value and also makes the signature misleading. Either remove the parameter (and update callers) or preserve backward compatibility by using the passed-in apiVersion when constructing the output (e.g., have the helper accept an argument).
| return GetInfo() | |
| } | |
| func GetInfo() []string { | |
| return buildInfo(apiVersion) | |
| } | |
| func GetInfo() []string { | |
| return buildInfo(apiVersion) | |
| } | |
| func buildInfo(apiVersion string) []string { |
pkg/version/version.go
Outdated
| func GetInfo() []string { | ||
| return []string{ |
There was a problem hiding this comment.
GetInfo is introduced as a new exported API but is only used internally in this package. Consider making it unexported (e.g., getInfo) to avoid expanding the public surface area, or document clearly why a new exported function is needed.
pkg/version/version.go
Outdated
| func GetInfo() []string { | ||
| return []string{ | ||
| fmt.Sprintf("API Version: %s", apiVersion), | ||
| fmt.Sprintf("API Version: %s", apiVersion), // 假设 apiVersion 已经在包级别定义了 |
There was a problem hiding this comment.
The inline comment is in Chinese and reads like an implementation assumption. To keep comments consistent and maintainable for all contributors, please remove it or rewrite it in concise English (ideally as a proper doc comment if it’s important).
| fmt.Sprintf("API Version: %s", apiVersion), // 假设 apiVersion 已经在包级别定义了 | |
| fmt.Sprintf("API Version: %s", apiVersion), |
There was a problem hiding this comment.
We can remove this whole line I think.
| @@ -34,16 +34,20 @@ var ( | |||
|
|
|||
| // PrintVersionAndExit prints versions from the array returned by Info() and exit. | |||
There was a problem hiding this comment.
The doc comment says this prints versions returned by Info(), but the implementation now iterates over GetInfo(). Please update the comment to match the current behavior (or switch back to calling Info if that’s the intended API).
| // PrintVersionAndExit prints versions from the array returned by Info() and exit. | |
| // PrintVersionAndExit prints versions from the array returned by GetInfo() and exits. |
There was a problem hiding this comment.
Copilot is right here, we need to modify this comment now.
3878b70 to
022cb8b
Compare
hajnalmt
left a comment
There was a problem hiding this comment.
Hello,
On a second thought, I tried to check around the code, and we don't set apiVersion anywhere and this is invoked only by us so it's safe to remove apiVersion in version.go everywhere. Sorry for the double round.
Please remove the variable in version.go file too, and we can stay with the old Info function name I think.
pkg/version/version.go
Outdated
| func GetInfo() []string { | ||
| return []string{ | ||
| fmt.Sprintf("API Version: %s", apiVersion), | ||
| fmt.Sprintf("API Version: %s", apiVersion), // 假设 apiVersion 已经在包级别定义了 |
There was a problem hiding this comment.
We can remove this whole line I think.
| @@ -34,16 +34,20 @@ var ( | |||
|
|
|||
| // PrintVersionAndExit prints versions from the array returned by Info() and exit. | |||
There was a problem hiding this comment.
Copilot is right here, we need to modify this comment now.
Signed-off-by: Aniket <[email protected]> Signed-off-by: feyounger <[email protected]>
Signed-off-by: caotuo721 <[email protected]> # Conflicts: # pkg/webhooks/admission/jobs/validate/admit_job_test.go Signed-off-by: feyounger <[email protected]>
Signed-off-by: feyounger <[email protected]>
Signed-off-by: feyounger <[email protected]>
Signed-off-by: feyounger <[email protected]>
Okay |
What type of PR is this?
Refactor / Code cleanup
What this PR does / why we need it:
This PR refactors the version printing and information generation logic to improve code readability, simplicity, and maintainability.
Key improvements include:
• Removing unnecessary parameter passing for apiVersion
• Simplifying output formatting using idiomatic Go patterns
• Cleaning up redundant variables and improving function signatures
There is no functional or behavior change introduced by this refactor.
Which issue(s) this PR fixes:
Fixes #5031
Special notes for your reviewer:
This is a non-functional refactor only.
No behavior change or user-facing impact is introduced.
Does this PR introduce a user-facing change?