krew icon indicating copy to clipboard operation
krew copied to clipboard

Feature request: Allow spaces in plugin names in order to enable sub-commands

Open dhague opened this issue 2 months ago • 6 comments

kubectl allows plugins with spaces in the name to provide the user experience of sub-commands:

a plugin that wishes to be invoked whenever the command kubectl foo bar baz is invoked by the user, would have the filename of kubectl-foo-bar-baz

krew does not allow for this option, because it uses .metadata.name for the plugin name, and this cannot have spaces. Any hyphens in the name get translated to underscores in the filename, which kubectl translates back to hyphens in the command name.

This could be resolved by having an optional field in the Plugin YAML, .spec.command which could be set to an array of strings much like the spec.containers.command field in a Kubernetes Pod. For example:

apiVersion: krew.googlecontainertools.github.com/v1alpha3
kind: Plugin
metadata:
  name: foo-bar-baz
spec:
  command: ["foo", "bar", "baz"]

dhague avatar Oct 07 '25 17:10 dhague

Whats your need for this?This is an intentional design choice because we install a single symlink.

I don't understand why would you install a subcommand just by itself instead of installing the main command itself.

ahmetb avatar Oct 09 '25 03:10 ahmetb

The main rationale for this is that krew should be able to manage any valid kubectl plugin, which is currently not the case.

My specific need is that we have developed a set of plugins based on subcommands of kubectl node - so, kubectl node pods to get the pods running on a node, kubectl node os to show the operating system, etc. Each plugin is a separate script, and we would like to manage these plugins with krew. This is only possible by implementing this feature request.

dhague avatar Oct 09 '25 07:10 dhague

Which "kubectl node" command are you referring to? Does the kubectl core now allow adding plugins to arbitrary builtin subcommands?

ahmetb avatar Oct 09 '25 14:10 ahmetb

Does the kubectl core now allow adding plugins to arbitrary builtin subcommands?

Yes - please see the link and example in my first comment on this issue.

dhague avatar Oct 09 '25 15:10 dhague

I don't think you can add subcommands to a builtin command (except for "create")?

Is there actually a "kubectl node" command, if not, we don't grant a name like that to a 3rd party plugin to begin with in krew-index.

ahmetb avatar Oct 09 '25 18:10 ahmetb

Is there actually a "kubectl node" command, if not, we don't grant a name like that to a 3rd party plugin to begin with in krew-index.

There is no "kubectl node" command, but that's not relevant because we do not want to add it to the krew-index - these are plugins we want to use within our company and we want to use krew to manage their installation via a custom index.

As you point out, subcommands can legitimately be added to "kubectl create" and therefore this is still an issue that needs addressing even if not using a custom index.

dhague avatar Oct 13 '25 17:10 dhague