Skip to content

pkg/virtctl/version: code cleanups and refactoring (#14085) #14104

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

Merged

Conversation

salawhaaat
Copy link
Contributor

@salawhaaat salawhaaat commented Mar 4, 2025

What this PR does

Before this PR:

  • virtctl version command contained unnecessary complexity.
  • Used fmt.Sprintf("%#v", value) redundantly.
  • Error handling could be improved for better debugging.
  • Used cobra.ExactArgs(0) instead of cobra.NoArgs.

After this PR:

  • Refactored usage() to use a multiline string for better readability.
  • Improved error handling using fmt.Errorf("%w", err) for better error wrapping.
  • Used cobra.NoArgs for idiomatic Go practices.
  • Removed unnecessary fmt.Sprintf("%#v", value) calls in printf.
  • Applied early return pattern to simplify the Run() function.

Fixes #14085

Why we need it and why it was done in this way

The following tradeoffs were made:

  • Improved code maintainability and readability without changing functionality.
  • Focused on Go best practices to align with idiomatic coding styles.

The following alternatives were considered:

  • Keeping the existing code but it was less readable.
  • Introducing a larger refactor, but that would be out of scope.

Links to places where the discussion took place: #14085

Special notes for your reviewer

  • Focus on readability improvements.
  • Ensure error wrapping changes align with best practices.

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

NONE

@kubevirt-bot kubevirt-bot added dco-signoff: no Indicates the PR's author has not DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 4, 2025
@kubevirt-bot
Copy link
Contributor

Hi @salawhaaat. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@salawhaaat salawhaaat marked this pull request as draft March 4, 2025 10:28
@kubevirt-bot kubevirt-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 4, 2025
@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 4, 2025
@salawhaaat salawhaaat force-pushed the chore/14085/refactor-version-command branch from 624bd29 to 80fb459 Compare March 4, 2025 10:34
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Mar 4, 2025
Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

Awesome, I have only two nits. Please address them and mark the PR ready for review/testing after.

@salawhaaat salawhaaat marked this pull request as ready for review March 4, 2025 11:02
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 4, 2025
@salawhaaat
Copy link
Contributor Author

Awesome, I have only two nits. Please address them and mark the PR ready for review/testing after.

Sweet, done. Thank you for quick response.

Copy link
Contributor

@mohit-nagaraj mohit-nagaraj left a comment

Choose a reason for hiding this comment

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

Looks good! 🙌
Could you also please rebase commits into a single commit for a cleaner git history as preferred! Thanks :)

@salawhaaat salawhaaat force-pushed the chore/14085/refactor-version-command branch 2 times, most recently from 65f8645 to 961114e Compare March 5, 2025 11:03
Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

/test all

@0xFelix
Copy link
Member

0xFelix commented Mar 5, 2025

Looks like you need to run make format and amend the changes to your commit.

@salawhaaat
Copy link
Contributor Author

Looks like you need to run make format and amend the changes to your commit.

thx, i will try 👍

…ability

Signed-off-by: salawhaaat <[email protected]>

nit: rename virCli to virtClient

Signed-off-by: salawhaaat <[email protected]>

remove comments

Signed-off-by: salawhaaat <[email protected]>

remove comments

Signed-off-by: salawhaaat <[email protected]>

make format

Signed-off-by: salawhaaat <[email protected]>
@salawhaaat salawhaaat force-pushed the chore/14085/refactor-version-command branch from 961114e to 5d20c0f Compare March 10, 2025 15:17
@salawhaaat
Copy link
Contributor Author

/retest

@kubevirt-bot
Copy link
Contributor

@salawhaaat: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@salawhaaat
Copy link
Contributor Author

/test all

@kubevirt-bot
Copy link
Contributor

@salawhaaat: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test all

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@salawhaaat
Copy link
Contributor Author

salawhaaat commented Mar 10, 2025

@0xFelix I am very sorry that it took long. The reason behind that, I couldn't start make process without docker, since I had docker issue.

@0xFelix
Copy link
Member

0xFelix commented Mar 10, 2025

No worries

/test all

@victortoso
Copy link
Member

Tests are happy too.
/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 11, 2025
Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

/approve

Thank you very much @salawhaaat

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 0xFelix

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 11, 2025
@kubevirt-commenter-bot
Copy link

Required labels detected, running phase 2 presubmits:
/test pull-kubevirt-e2e-windows2016
/test pull-kubevirt-e2e-kind-1.30-vgpu
/test pull-kubevirt-e2e-kind-sriov
/test pull-kubevirt-e2e-k8s-1.32-ipv6-sig-network
/test pull-kubevirt-e2e-k8s-1.30-sig-network
/test pull-kubevirt-e2e-k8s-1.30-sig-storage
/test pull-kubevirt-e2e-k8s-1.30-sig-compute
/test pull-kubevirt-e2e-k8s-1.30-sig-operator
/test pull-kubevirt-e2e-k8s-1.31-sig-network
/test pull-kubevirt-e2e-k8s-1.31-sig-storage
/test pull-kubevirt-e2e-k8s-1.31-sig-compute
/test pull-kubevirt-e2e-k8s-1.31-sig-operator

@salawhaaat
Copy link
Contributor Author

/approve

Thank you very much @salawhaaat

Yeaaaah, let's goo. I will be happy to continue on next open task.

@kubevirt-bot kubevirt-bot merged commit b8c1d7f into kubevirt:main Mar 11, 2025
38 checks passed
@salawhaaat salawhaaat deleted the chore/14085/refactor-version-command branch March 17, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/virtctl dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/compute size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg/virtctl/version: Further code cleanups
6 participants