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

Add completion in kubectl debug #130033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ardaguclu
Copy link
Member

@ardaguclu ardaguclu commented Feb 7, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds resource completion for kubectl debug command.

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1711

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Adding resource completion in kubectl debug command

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 7, 2025
@ardaguclu
Copy link
Member Author

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 7, 2025
@ardaguclu ardaguclu force-pushed the completion-use-restclientgetter branch from d675e6a to 533a121 Compare February 7, 2025 11:10
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 7, 2025
@ardaguclu ardaguclu changed the title WIP: Add completion in kubectl debug command for pods and nodes WIP: Add completion in kubectl debug Feb 7, 2025
@ardaguclu ardaguclu changed the title WIP: Add completion in kubectl debug Add completion in kubectl debug Feb 7, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 7, 2025
@@ -383,6 +383,8 @@ func NewKubectlCommand(o KubectlOptions) *cobra.Command {
// Avoid import cycle by setting ValidArgsFunction here instead of in NewCmdGet()
getCmd := get.NewCmdGet("kubectl", f, o.IOStreams)
getCmd.ValidArgsFunction = utilcomp.ResourceTypeAndNameCompletionFunc(f)
debugCmd := debug.NewCmdDebug(f, o.IOStreams)
Copy link
Member

Choose a reason for hiding this comment

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

Are there import cycles for the debug command also? If not I suggest putting the ValidArgsFunction in the debug.go file where the debug command is being declared.

The get command is the only exception to that pattern because the completion code calls the get code back.

Copy link
Member Author

Choose a reason for hiding this comment

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

debug command (just like with the other newer commands) expects restClientGetter not factory

func NewCmdDebug(restClientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command {
. But completion util expects Factory (to pass through get command invocation).

This is the only place where we actually have Factory.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can cast it in debug.go like;

f, ok := restClientGetter.(Factory); ok {
validargs = completion(f)
}

which would be alternative.

Copy link
Member

Choose a reason for hiding this comment

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

I haven’t paid attention to the evolution of the code recently, so whatever you feel is best.

Copy link
Member

Choose a reason for hiding this comment

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

It's probably OK for this PR, but it seems like a problem that we can't define completions inside of a command that uses RESTClientGetter instead of Factory.

The root of the problem seems to be that get.Run() requires a Factory. I wonder how hard it would be to change get to use RESTClientGetter instread of Factory... 🤔

Then, all the functions in completions.go can be changed to use RESTClientGetter, making it more flexible to be used in other commands.

Like I said, I don't think it needs to be part of this PR, but it is probably something worth thinking about.

(BTW, I don't think we should try to cast restClientGetter to a Factory in debug.go... it might be fine for kubectl, but if someone else is using the debug command with a different implementation of the RESTClientGetter interface, they would be surprised by this).

Copy link
Member Author

Choose a reason for hiding this comment

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

The root of the problem seems to be that get.Run() requires a Factory. I wonder how hard it would be to change get to use RESTClientGetter instread of Factory...

I attempted multiple times but I failed all of them (because I agree that this is the correct path). get requires concrete Factory as it relies on openapi functions (and some more) inside it.

@ardaguclu
Copy link
Member Author

unrelated
/retest

@ardaguclu
Copy link
Member Author

/cc @soltysh

@k8s-ci-robot k8s-ci-robot requested a review from soltysh February 7, 2025 12:17
@ardaguclu
Copy link
Member Author

/hold
to prevent accidental merges

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 7, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ardaguclu, brianpursley

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

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/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

kubectl debug autocompletion isn't working
4 participants