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

feature: add bash completion for plugin mode of kubectl ctx and kubectl ns #380

Conversation

RouxAntoine
Copy link
Contributor

@RouxAntoine RouxAntoine commented Feb 6, 2023

if added to PATH and name kubectl_complete-ns and kubectl_complete-ctx these two script provide completion for ns and ctx cli in kubectl plugin mode

if this pull request is good to merge i could made another one on krew-index project to adapt the two manifest like this :

apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
  name: ns
spec:
  homepage: https://github.com/ahmetb/kubectx
  shortDescription: Switch between Kubernetes namespaces
  version: v0.9.4
  description: |
    Also known as "kubens", a utility to set your current namespace and switch
    between them.
  caveats: |
    If fzf is installed on your machine, you can interactively choose
    between the entries using the arrow keys, or by fuzzy searching
    as you type.
    To enable completion run add "$KREW_ROOT/store/ns/v0.9.4/completion/" to your PATH
  platforms:
  - selector:
      matchExpressions:
      - key: os
        operator: In
        values:
        - darwin
        - linux
    uri: https://github.com/ahmetb/kubectx/archive/v0.9.4.tar.gz
    sha256: e50b72a37d01cc4b2c7d51b8f2167de518031b0c013bcb0b82c036d5ad1d1926
    bin: kubens
    files:
    - from: kubectx-*/kubens
      to: .
    - from: kubectx-*/LICENSE
      to: .
    - from: kubectx-*/completion/plugins/kubectl_complete-ns
      to: completion

ps : maybe some change should be done to made this bash agnostic

@ahmetb
Copy link
Owner

ahmetb commented Feb 6, 2023

Nice, but I'm trying to see if we can provide a straightforward way in krew manifests to let plugins configure how their binary is linked for completions.

For kubectx, since we're moving away from bash implementations to Go based implementations, completions might make sense to implement as a hidden subcommand. It might take me a while to get back to this.

@RouxAntoine
Copy link
Contributor Author

kubectl completion for plugin call a binary named kubectl_complete-<pluginName> so i think hidden command would not work. But yes maybe a go binary is better to benefit of classical application function.

I thought of another solution for link completion in krew with existing manifest but it doesn't work. This solution was to create link from $KREW_ROOT/store/kubectl_complete-<pluginName> to $KREW_ROOT/bin/ but krew create only one link currently. Feel free to refuse this pull request i do this more for me than for particular contribution 🙂

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 22, 2024
…tl ns

if added to PATH and name `kubectl_complete-ns` and `kubectl_complete-ctx` these two script provide
completion for ns and ctx cli in kubectl plugin mode
@RouxAntoine RouxAntoine force-pushed the feature/bash-completion-plugin-mode branch from 81898c3 to 8fb3a1a Compare December 22, 2024 11:05
@RouxAntoine RouxAntoine force-pushed the feature/bash-completion-plugin-mode branch 2 times, most recently from 3970029 to c101628 Compare December 22, 2024 11:11
@RouxAntoine RouxAntoine force-pushed the feature/bash-completion-plugin-mode branch from 34ea187 to c347913 Compare December 22, 2024 12:06
@RouxAntoine RouxAntoine force-pushed the feature/bash-completion-plugin-mode branch from 66fd875 to 26fcbbc Compare December 22, 2024 12:50
@RouxAntoine RouxAntoine force-pushed the feature/bash-completion-plugin-mode branch from 796ec13 to cf37719 Compare December 27, 2024 12:55
@ahmetb
Copy link
Owner

ahmetb commented Dec 27, 2024

@RouxAntoine thanks for all these good commits. Do you mind sending the unrelated chores/fixes separately so I can merge them right away?

@RouxAntoine
Copy link
Contributor Author

RouxAntoine commented Dec 27, 2024

Hello @ahmetb sorry for notification, I miss that this PR was still open. Yes I can split it. There is a part you are more interrested to pick ?

Maybe I can extract

@RouxAntoine
Copy link
Contributor Author

And for information I have made this work to start implementing support for multiple kubeconfig file.

For the moment I have a first basic implementation which do not totally work, and today I start a more structured implementation by isolating the interface exposed by the Kubeconfig struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants