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

Implementing autocompletion for karmadactl #5533

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

zhzhuang-zju
Copy link
Contributor

What type of PR is this?
/kind feature

What this PR does / why we need it:
Implementing autocompletion for karmadactl, which can save you a lot of typing.

Which issue(s) this PR fixes:
Parts of #5477

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

`karmadactl`: Implementing autocompletion for karmadactl to save a lot of typing

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 12, 2024
@karmada-bot karmada-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 12, 2024
@codecov-commenter
Copy link

codecov-commenter commented Sep 12, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 1.46699% with 403 lines in your changes missing coverage. Please review.

Project coverage is 33.93%. Comparing base (4ac95b9) to head (a684edd).
Report is 46 commits behind head on master.

Files with missing lines Patch % Lines
pkg/karmadactl/util/completion/completion.go 1.19% 248 Missing and 1 partial ⚠️
pkg/karmadactl/get/get.go 0.00% 41 Missing ⚠️
pkg/karmadactl/completion/completion.go 0.00% 38 Missing ⚠️
pkg/karmadactl/karmadactl.go 0.00% 9 Missing ⚠️
pkg/karmadactl/exec/exec.go 0.00% 6 Missing ⚠️
pkg/karmadactl/attach/attach.go 0.00% 5 Missing ⚠️
pkg/karmadactl/describe/describe.go 0.00% 5 Missing ⚠️
pkg/karmadactl/apply/apply.go 0.00% 4 Missing ⚠️
pkg/karmadactl/cordon/cordon.go 0.00% 4 Missing ⚠️
pkg/karmadactl/explain/explain.go 0.00% 4 Missing ⚠️
... and 16 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5533      +/-   ##
==========================================
+ Coverage   32.45%   33.93%   +1.48%     
==========================================
  Files         643      645       +2     
  Lines       44497    44857     +360     
==========================================
+ Hits        14440    15223     +783     
+ Misses      28962    28478     -484     
- Partials     1095     1156      +61     
Flag Coverage Δ
unittests 33.93% <1.46%> (+1.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RainbowMango
Copy link
Member

Looks great! Can't wait to try it!
Hi @ahorine , I guess you might like it.

@zhzhuang-zju
Copy link
Contributor Author

Looks great! Can't wait to try it!
Hi @ahorine , I guess you might like it.

The introduction of karmadactl completion this time significantly reduces the amount of typing required during routine operations. Compared to kubectl completion, karmadactl completion has made extensive adaptations for karmadactl. I will put together a guide on how to use karmadactl completion to enhance the operational experience. Everyone is welcome to give it a try~ @ahorine @RainbowMango @mohamedawnallah

@zhzhuang-zju
Copy link
Contributor Author

Currently, karmadactl completion support output shell completion code for the specified shell:

  • zsh
    source <(karmadactl completion zsh)
  • bash
    source <(karmadactl completion bash)
    Theoretically, it should also support fish and powershell, though this hasn't been verified yet. Verification and implementation can be done in subsequent steps.

Here are the autocompletion capabilities provided by karmadactl completion:

  • Autocomplete karmadactl
    By typing k and pressing the tab key, karmadactl can be autocompleted.
$ k
... karmadactl ... kubectl ...
  • Autocomplete karmadactl subcommands
    By typing karmadactl and pressing the tab key, the subcommands supported by karmadactl can be autocompleted.
$ karmadactl 
addons         -- Enable or disable a Karmada addon
annotate       -- Update the annotations on a resource
api-resources  -- Print the supported API resources on the server
  • Autocomplete flags
    Currently supports autocompletion for flags namespace, cluster, clusters, karmada-context, and operation-scope.
    The values autocompleted for operation-scope vary depending on the command. For example, the get command supports operation-scope values of karmada, members, and all, so these options will be available for selection during autocompletion. However, when autocompleting the operation-scope flag for the exec command, only karmada and members will appear.
$ karmadactl exec --operation-scope 
karmada  members
$ karmadactl get --operation-scope 
all      karmada  members
  • Autocomplete resources that can be operated on by commands
    For example, for the get command:
$ karmadactl get 
apiservices.apiregistration.k8s.io                            endpoints                                                     nodes.metrics.k8s.io                                          resourceregistries.search.karmada.io                        
...
$ karmadactl get pods 
nginx  pod1 

Highlights

  • The autocompletion content varies depending on the command. For example, the operation-scope flag. This not only helps complete the content but also assists users in entering the correct values.
  • When autocompleting resources for commands, it takes into account the flags operation-scope, cluster, and clusters.

Using the get command as an example:

  • karmadactl get pods will autocomplete the list of pods in the Karmada control plane.
  • karmadactl get pods --operation-scope all will autocomplete the list of pods in the Karmada control plane and all member clusters.
  • karmadactl get pods --operation-scope members will autocomplete the list of pods in all member clusters.
  • karmadactl get pods --operation-scope members --clusters member1,member2 will autocomplete the list of pods in member clusters member1 and member2.

@Vacant2333
Copy link
Contributor

its a great improvement for karmadactl, do u need update autocompletion to the karmada docs?

@zhzhuang-zju
Copy link
Contributor Author

its a great improvement for karmadactl, do u need update autocompletion to the karmada docs?

yes, we can publish a guidance document as long as this pr is merged. Are you willing to submit a pr for this?

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

Just some nits, otherwise LGTM.

pkg/karmadactl/completion/completion.go Outdated Show resolved Hide resolved
pkg/karmadactl/completion/completion.go Outdated Show resolved Hide resolved
pkg/karmadactl/completion/completion.go Outdated Show resolved Hide resolved
pkg/karmadactl/completion/completion.go Outdated Show resolved Hide resolved
pkg/karmadactl/top/top_pods.go Outdated Show resolved Hide resolved
pkg/karmadactl/top/top_node.go Outdated Show resolved Hide resolved
pkg/karmadactl/taint/taint.go Outdated Show resolved Hide resolved
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
Great job!

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 20, 2024
@karmada-bot karmada-bot merged commit b8edec1 into karmada-io:master Sep 20, 2024
12 checks passed
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants