rancher/k3k

[EPIC] `k3kcli` enhancements

Open

#471 aperta il 19 set 2025

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)Go (77 fork)auto 404
good first issueteam/collie

Metriche repository

Star
 (886 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

As we approach the v1.0.0 GA release, our goal is to solidify k3kcli as a robust and user-friendly tool. This epic focuses on two key areas of improvement: kubeconfig management and interactive shell autocompletion.

Currently, kubeconfig files are generated in the working directory, which can be cumbersome for users managing multiple clusters. We will implement a more professional and organized storage mechanism using a standard configuration path ($XDG_CONFIG_HOME/k3k).

Additionally, migrating to Cobra opens the door for powerful shell autocompletion. We will implement this for key commands, arguments, and flags to guide users, reduce errors, and make the CLI much faster to use.

Some of the possible identified improvements are:

  • Kubeconfig files managed in a dedicated, standardized directory by default.
  • Users can override the default kubeconfig output location.
  • Core commands (cluster delete, kubeconfig generate, policy delete) have shell autocompletion for their arguments.
  • Common flags (e.g., --mode) support autocompletion where applicable.

config management

Currently the k3kcli generate the kubeconfig file in the current folder. When handling multiple virtual clusters it can be annoying. To avoid this we should create the kubeconfig in a dedicated folder, possibly in a standard path. A k3k directory, under the standard $XDG_CONFIG_HOME ($HOME/.config by default) could be used. Subfolders with the namespaces could be used to organize the kubeconfigs:

$HOME/.config/k3k/myns/cluster-1.yaml
$HOME/.config/k3k/myns/cluster-2.yaml
$HOME/.config/k3k/anotherns/cluster-foo.yaml

Also a --out flag should be added to override this behavior.

flag and args autocompletion

Migrating to Cobra we have now the opportunity to add the autocompletion for arguments and flags.

cluster delete

The k3kcli cluster delete [NAME] expects a single argument with the cluster to delete. We can provide an autocompletion to select from the available clusters.

NOTE: the command could also have a --namespace flag, to select the namespace. Different clusters could be part of different namespaces. A "workaround" could be dropping the --namespace flag, and/or handling the namespaces within the name, like k3kcli cluster delete myns/cluster. This will ease the deletion of different clusters in different namespaces.

kubeconfig generate

In a similar way the kubeconfig generate could handle a new argument, with the namespace/cluster, instead of the flags. We could still support the flags for backards compatibility, if needed, and adding the autocompletion also there.

policy delete

The policy is not a namespaced resource, so it's easier to handle. The arguments autocomplete should just list the available policies. We could add the chance to delete multiple policies.

Others

We have many flags and fields that can/should support the autocompletion, i.e. the --mode during the cluster creation, or the persistence-type, or many more. To investigate.

Guida contributor