Skip to content

[Feat][kubectl-plugin] Add dynamic shell completion for kubectl ray session #2390

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

Conversation

MortalHappiness
Copy link
Member

Why are these changes needed?

Implement dynamic shell completion for kubectl ray session command.

Note: I haven't found a proper way to mock the cmd Factory to get custom resources for testing.

Screencast:

2024-09-18.17-35-09.mp4

Related issue number

N/A

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

…ession

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
@MortalHappiness
Copy link
Member Author

@kevin85421 @andrewsykim @chiayi PTAL

@kevin85421
Copy link
Member

The demo video looks good! Is it only for session, or do other commands like get also support it?

@kevin85421 kevin85421 self-assigned this Sep 18, 2024
@MortalHappiness
Copy link
Member Author

@kevin85421 Currently only session command.

@andrewsykim
Copy link
Member

@MortalHappiness the autocomplete looks awesome, can't wait to try it!

Currently only session command.

@chiayi can we look into implementing similar autocompletion for kubectl ray logs?

}

// RayJobCompletionFunc Returns a completion function that completes RayJob resource names.
func RayJobCompletionFunc(f cmdutil.Factory) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
Copy link
Member

Choose a reason for hiding this comment

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

Is RayJobCompletionFunc and RayServiceCompletionFunc still needed? It looks like RayClusterResourceNameCompletionFunc handles resource type already

Copy link
Member Author

@MortalHappiness MortalHappiness Sep 20, 2024

Choose a reason for hiding this comment

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

These 3 functions RayClusterCompletionFunc, RayJobCompletionFunc, and RayServiceCompletionFunc are not used in this PR. But I think they may be useful for implementing autocompletion for other commands. Let me introduce the differences:

RayClusterResourceNameCompletionFunc:

  • If toComplete does not have slash, complete it from either RayCluster names or resource types (raycluster/, rayjob/, rayservice/)
  • If toComplete starts with resource types and slash, complete it with the corresponding resource name (e.g. rayjob/sample-rayjob)
  • Examples:
    • r<Tab> -> raycluster-1, raycluster-2, raycluster/, rayjob/, rayservice/
    • m<Tab> -> my-raycluster-1, my-raycluster-2
    • rayjob/<Tab> -> rayjob/rayjob-1, rayjob/rayjob-2

RayClusterCompletionFunc, RayJobCompletionFunc, RayServiceCompletionFunc:

  • These functions only complete the resource name of the corresponding resource. For example, for RayJobCompletionFunc, the completion result will not include rayjob/, only the name of RayJobs are presented to the users.
  • So these function can be used by other commands that don't need resource type completion. For example, kubectl ray logs can use RayClusterCompletionFunc. cc @chiayi
  • Examples (RayClusterCompletionFunc):
    • r<Tab> -> raycluster-1, raycluster-2

Note that the r<Tab> results are different for RayClusterResourceNameCompletionFunc and RayClusterCompletionFunc.

Copy link
Member

Choose a reason for hiding this comment

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

okay that makes sense to me, thanks for clarifying

Copy link
Member

@andrewsykim andrewsykim left a comment

Choose a reason for hiding this comment

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

LGTM

@andrewsykim andrewsykim merged commit f69885b into ray-project:master Sep 20, 2024
27 checks passed
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.

3 participants