kubectl icon indicating copy to clipboard operation
kubectl copied to clipboard

kubectl powershell completion

Open rgembalik opened this issue 7 years ago • 24 comments

FEATURE REQUEST It would be great to see autocompletion support for PowerShell. Is it possible for Windows releases?

rgembalik avatar Mar 14 '19 22:03 rgembalik

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Jun 12 '19 23:06 fejta-bot

The following module offer tab completion of kubectl within PowerShell Core https://github.com/felixfbecker/PSKubectl

bergmeister avatar Jul 03 '19 20:07 bergmeister

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten

fejta-bot avatar Aug 02 '19 21:08 fejta-bot

/remove-lifecycle rotten /area kubectl /sig cli /kind feature

seans3 avatar Aug 02 '19 21:08 seans3

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Oct 31 '19 21:10 fejta-bot

/remove-lifecycle stale

seans3 avatar Oct 31 '19 23:10 seans3

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Jan 30 '20 00:01 fejta-bot

/remove-lifecycle stale

bgshacklett avatar Jan 31 '20 16:01 bgshacklett

I use kubectl every day, and it would be a great enhancement to have a powershell-native module (PS core, of course! cross platform et al). Right now we are stuck with the outdated cmd shell. For example, instead of returning yaml or json string on the stdout, the cmdlet could return rich objects that we could interact with easily.

RoguePointer80 avatar Mar 18 '20 13:03 RoguePointer80

@RoguePointer80 This is what you look for: https://github.com/felixfbecker/PSKubectl

bergmeister avatar Mar 18 '20 15:03 bergmeister

If you're looking for kubectl auto-completion in PowerShell you can have a look at PSKubectlCompletion module- https://www.powershellgallery.com/packages/PSKubectlCompletion

mziyabo avatar Apr 23 '20 00:04 mziyabo

/priority backlog

eddiezane avatar Jul 22 '20 16:07 eddiezane

It would be amazing if we can have the auto completion like on bash

For eg pod names. Namespaces etc

kingdevnl avatar Aug 12 '20 08:08 kingdevnl

I really like the way the WinGet team did it. I'm sure I've also seen this pattern elsewhere.

"complete" is a command on the cli tool itself, which handles the auto-completion. It can then we wrapped by any shell's auto-complete mechanism, will always be up-to-date with the application itself, and can probably re-use most of the code the cli tool already uses for determining commands.

It would also make the existing shell completions for BASH/ZSH simpler and easier to maintain, as they would now simply call the CLI itself. Also means the shell completions don't need to be updated when the CLI commands change.

Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)
        [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
        $Local:word = $wordToComplete.Replace('"', '""')
        $Local:ast = $commandAst.ToString().Replace('"', '""')
        winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        }
}

I presume the BASH completion function would become equally short, instead of the 13,000 lines it is now.

MartinSGill avatar Sep 29 '20 10:09 MartinSGill

There are two cool options listed in this issue, but I consider them both proofs of concept.

https://github.com/felixfbecker/PSKubectl requires you to use an entirely new command syntax, which is not desirable

https://www.powershellgallery.com/packages/PSKubectlCompletion is a good start, but does not support resource name completion as of yet (there's an open issue for it).

kbirger avatar Oct 01 '20 14:10 kbirger

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Dec 30 '20 15:12 fejta-bot

/remove-lifecycle stale

marckhouzam avatar Jan 04 '21 00:01 marckhouzam

As information, the next release of Cobra, the library beneath kubectl, will provide support for powershell completion: https://github.com/spf13/cobra/pull/1208

marckhouzam avatar Jan 04 '21 00:01 marckhouzam

That's dope.

kingdevnl avatar Jan 05 '21 06:01 kingdevnl

Cobra 1.1.3 has been released and provides full PowerShell completion support. Kubectl could start using it for commands and flags.

However, custom completions that are defined directly in kubectl (e.g., kubectl get [tab], kubectl describe pod [tab], etc) will only work for PowerShell if they are moved to Go completions which is done in kubernetes/kubernetes#96087

marckhouzam avatar Feb 20 '21 00:02 marckhouzam