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

feat(cli): Add autocomplete on integrations, kits, kamelets commands #3902

Merged

Conversation

gansheer
Copy link
Contributor

@gansheer gansheer commented Dec 14, 2022

Fixes #3628

Motivation

Adding some completion on CLI basic commands to improve its usability through bash completion.

Description

The completion uses kubectl commands to retrieve the results.

  • kamel get autocomplete on integrations
    *kamel delete autocomplete on integrations (no modification made)
  • kamel get kit autocomplete on all kits
  • kamel delete kit still autocomplete on non-platform kits (no modification made)
  • kamel kamelet delete autocomplete on non-readonly and non-bundled kamelets (this is the command behavior)
  • kamel describe kamelet autocomplete on all kamelets

Pre-existing limit : the completion never use the value of the namespace flag even if it is provided, it always use the kubectl config context namespace. For kamel -n usernamespace get <TAB>, completion runs kamel get . None of the completion use the namespace flag.

Release Note

feat(cli): Enable CLI completion for integration, kit, kamelet names

* kamel get / kamel delete autocompletes on integrations
* kamel get kit autocompletes on all kits
* kamel delete kit autocompletes on non-platform kits
* kamel kamelet delete autocompletes on non-readonly and non-bundled kamelets
* kamel describe kamelet autocompletes on all kamelets

Closes apache#3628
Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

Nice stuff, thanks!

Copy link
Member

@tadayosi tadayosi left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@tadayosi
Copy link
Member

@gansheer OK, so I didn't notice that the autocompletion functions for kamel get / kamel delete are already included in the bash completion script. But it never works on my laptop.

$ kamel get
NAME	PHASE	KIT
java	Running	camel-k/kit-cedaklomsunon3m7so8g

$  kamel get [TAB]
(... only shows local files)

Is this only me?

@gansheer
Copy link
Contributor Author

gansheer commented Dec 15, 2022

@gansheer OK, so I didn't notice that the autocompletion functions for kamel get / kamel delete are already included in the bash completion script. But it never works on my laptop.

$ kamel get
NAME	PHASE	KIT
java	Running	camel-k/kit-cedaklomsunon3m7so8g

$  kamel get [TAB]
(... only shows local files)

Is this only me?

The kamel get needed to be integrated to the following code to be called:

__custom_func() {
case ${last_command} in
kamel_describe_integration)
__kamel_kubectl_get_integrations
return
;;
kamel_describe_kit)
__kamel_kubectl_get_integrationkits
return
;;
kamel_delete)
__kamel_kubectl_get_integrations
return
;;
kamel_log)
__kamel_kubectl_get_integrations
return
;;
kamel_kit_delete)
__kamel_kubectl_get_non_platform_integrationkits
return
;;
*)
;;
esac
}
`

It is why it was never called before, so it is normal it never works on your laptop.

For the kamel delete it should already have been working, so I don't really know.

@gansheer gansheer marked this pull request as ready for review December 15, 2022 07:39
@tadayosi
Copy link
Member

tadayosi commented Dec 15, 2022

Ah yes, kamel get [TAB] is fixed with this pull req. But even kamel delete [TAB] and kamel log [TAB] never work for me. Do they work for you? Can it be something related to difference between macOS / Linux? Since I'm using Fedora.

@gansheer
Copy link
Contributor Author

gansheer commented Dec 15, 2022

I am also using Fedora and both works on bash.
It could be some problems about the kubectl command. If you get the listing of you files it is probably be because the command did not give you any results. I did most of my tests on minikube's default namespace and context :

$ kubectl config get-contexts minikube
CURRENT   NAME       CLUSTER    AUTHINFO   NAMESPACE
*         minikube   minikube   minikube   default

The internal command used to retrieve integrations is : kubectl get -o template --template="{{ range .items }}{{ .metadata.name }} {{ end }}" integrations 2>/dev/null. As you can see there is no namespace in it, therefore it will always be the default namespace from the current kubectl config context used. It never uses the in given in flag or the one that can be defined as a kamel config (see 1.11.x doc). You can check your CLI config with kamel config --list.

I will create an issue about this "namespace" behavior. I tried some fixes while adding the missing autocompletes without success with the current way of managing autocompletes.

@gansheer
Copy link
Contributor Author

gansheer commented Dec 15, 2022

@tadayosi

I spent some time on the namespace problem and managed to make some adaptations that can make use of flag namespace (like kamel get --namespace test <TAB>) and the configured namespace. You can see the commit here in another branch.
Please tell me what you think about this commit. The code could probably be better but it is what I think the most we can do with the current legacy bash completion. Anything more advanced would be a refactoring IMHO.
I need to test it on an openshift remote to see if it works well in a multi-operator environment, but it seems to works as expected with a minikube environment.

For the moment, we could continue the current PR without dealing with the namespace problem if you think it still helps the CLI usability.

@tadayosi
Copy link
Member

If you get the listing of you files it is probably be because the command did not give you any results.

Hmm, namespace doesn't seem to be a problem for me. I use kubens so the default namespace is always set:

$ kubectl config get-contexts minikube
CURRENT   NAME       CLUSTER    AUTHINFO   NAMESPACE
*         minikube   minikube   minikube   camel-k

so the internal command also works fine for me:

$  kamel get
NAME				PHASE	KIT
java				Running	camel-k/kit-cedaklomsunon3m7so8g
timer-source-to-log-sink	Running	camel-k/kit-cedbu7gd2eat7v11jb30

$ kubectl get -otemplate --template="{{ range .items }}{{ .metadata.name }} {{ end }}" integrations 2> /dev/null
java timer-source-to-log-sink

Anyway, if it works for you on Fedora, then probably the problem should be specific to my env. I'll look into further why it doesn't work for me.

I will create an issue about this "namespace" behavior. I tried some fixes while adding the missing autocompletes without success with the current way of managing autocompletes.

Yes, please go ahead and file another issue. I also looked at the other commit and it looks good as well. So please submit a pull req with it.

In the meantime, I think this pull req is great enough so I'm merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable CLI completion for integration, kit, kamelet names
4 participants