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

[refactor][kubectl-plugin] make --node-type an enum flag #3018

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidxia
Copy link
Contributor

@davidxia davidxia commented Feb 11, 2025

in the kubectl ray log command.

This is more complex but has several advantages.

  • better help and error messages, e.g. shows the default "all" value in the
    help messages
  • more type-safe
  • can set the default value of "all" more easily
  • supports shell completion

References

Before

$ kubectl ray logs -h
...
      --node-type string               type of Ray node from which to download log, supports 'worker', 'head', or 'all'
...

$ kubectl ray logs dxia-test
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve both head and worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl
Downloading log for Ray Node dxia-test-head-xnh9r

$ kubectl ray logs dxia-test --node-type foo
No output directory specified, creating dir under current directory using resource name.
Error: unknown node type `foo`

$ kubectl ray logs dxia-test --node-type WORKER
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve only worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl

After

$ kubectl ray logs -h
...
      --node-type enum                 type of Ray node from which to download logs, supports: 'worker', 'head', or 'all' (default all)
...

$ kubectl ray logs dxia-test
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve both head and worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl
Downloading log for Ray Node dxia-test-head-xnh9r

$ kubectl ray logs dxia-test --node-type foo
Error: invalid argument "foo" for "--node-type" flag: must be one of "all", "head", or "worker"

$ kubectl ray logs dxia-test --node-type WORKER
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve only worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl

Checks

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

@davidxia

This comment was marked as outdated.

@davidxia davidxia changed the title [refactor][kubectl-plugin] set --node-type=all default [refactor][kubectl-plugin] make --node-type an enum flag Feb 12, 2025
@davidxia
Copy link
Contributor Author

What my fish shell looks like when I press after the end of --node-type after enabling shell completion. Tabbing scrolls through the options and populates my command. Very nice!

image

in the `kubectl ray log` command.

This is more complex but has several advantages.

* better help and error messages, e.g. shows the default "all" value in the
  help messages
* more type-safe
* can set the default value of "all" more easily
* supports shell completion

References

* https://stackoverflow.com/a/70541824/553994
* https://applejag.eu/blog/go-spf13-cobra-custom-flag-types/

## Before

```console
$ kubectl ray logs -h
...
      --node-type string               type of Ray node from which to download log, supports 'worker', 'head', or 'all'
...

$ kubectl ray logs dxia-test
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve both head and worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl
Downloading log for Ray Node dxia-test-head-xnh9r

$ kubectl ray logs dxia-test --node-type foo
No output directory specified, creating dir under current directory using resource name.
Error: unknown node type `foo`

$ kubectl ray logs dxia-test --node-type WORKER
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve only worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl
```

## After

```console
$ kubectl ray logs -h
...
      --node-type enum                 type of Ray node from which to download logs, supports: 'worker', 'head', or 'all' (default all)
...

$ kubectl ray logs dxia-test
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve both head and worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl
Downloading log for Ray Node dxia-test-head-xnh9r

$ kubectl ray logs dxia-test --node-type foo
Error: invalid argument "foo" for "--node-type" flag: must be one of "all", "head", or "worker"

$ kubectl ray logs dxia-test --node-type WORKER
No output directory specified, creating dir under current directory using resource name.
Command set to retrieve only worker node logs.
Downloading log for Ray Node dxia-test-default-group-worker-dgxsl
```

Signed-off-by: David Xia <david@davidxia.com>
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.

1 participant