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][kubectl-plugin] Implement kubectl ray session #2298

Merged

Conversation

MortalHappiness
Copy link
Member

@MortalHappiness MortalHappiness commented Aug 9, 2024

Why are these changes needed?

This PR implements the Ray session part in this REP.

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 :(

@MortalHappiness
Copy link
Member Author

@chiayi @andrewsykim @kevin85421 PTAL

In this draft PR I only implemented the port-forwarding part of the Ray Dashboard. I use the kubectl port-forward command directly. But there are some drawbacks by using kubectl port-forward directly:

  • We cannot print message after the port-forwarding is created and the kubectl port-forward command is still running.
  • By using kubectl port-forward <head-pod-svc> 0:8265, a random port on localhost will be port-forwarded, but it's hard to get this port number to print it to stdout.

If we don't use kubectl port-forward, we need to implement the port-forwarding using client-go ourselves, like the following file does.

https://github.com/kubernetes/kubectl/blob/master/pkg/cmd/portforward/portforward.go

What do you think?

@andrewsykim
Copy link
Collaborator

I think usnig client-go portforward library makes sense. Can you share the output you see when you run kubectl ray cluster session?

rayHeadSrc := rayHeadSvcs.Items[0]

portForwardCmd := portforward.NewCmdPortForward(factory, *options.ioStreams)
portForwardCmd.SetArgs([]string{"service/" + rayHeadSrc.Name, "0:8265"})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another possibility instead of using 0:8265 is to default the local port to 8265 and make it configurable?

rayHeadSrc := rayHeadSvcs.Items[0]

portForwardCmd := portforward.NewCmdPortForward(factory, *options.ioStreams)
portForwardCmd.SetArgs([]string{"service/" + rayHeadSrc.Name, "0:8265"})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also consider port-forwarding the client port at 10001?

@MortalHappiness
Copy link
Member Author

image

@andrewsykim The above is the output of the command. Currently I hard-coded the port to 8265 and 10001. We can make these 2 ports configurable if needed in the future.

@MortalHappiness MortalHappiness changed the title [Feature][kubectl-plugin] Implement kubectl ray cluster session [Feature][kubectl-plugin] Implement kubectl ray session Sep 4, 2024
portForwardCmd := portforward.NewCmdPortForward(factory, *options.ioStreams)
portForwardCmd.SetArgs([]string{"service/" + rayHeadSrc.Name, "0:8265"})

if err := portForwardCmd.ExecuteContext(ctx); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Run this as a goroutine with a stop channel?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are there any benefits to run it as a goroutine?

Copy link
Collaborator

@andrewsykim andrewsykim Sep 4, 2024

Choose a reason for hiding this comment

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

Feel free to ignore, I thought the stop channel would be necessary to handle stop signal but looks like it's already handled by client-go


fmt.Printf("Ray Dashboard: http://localhost:%d\nRay Interactive Client: http://localhost:%d\n\n", DASHBOARD_PORT, CLIENT_PORT)

if err := portForwardCmd.ExecuteContext(ctx); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will interrupt signal work here? (^C)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. You can see from the screenshot above that the last line is ^C.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks, I didnt' see the terminal prompt after so it wasn't clear if it actually stopped the program

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
@MortalHappiness MortalHappiness marked this pull request as ready for review September 5, 2024 16:57
@MortalHappiness
Copy link
Member Author

@andrewsykim @kevin85421 I've added tests and marked this PR as ready for review. Thanks.

Copy link
Collaborator

@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, @chiayi can you review this too please?

Copy link
Contributor

@chiayi chiayi left a comment

Choose a reason for hiding this comment

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

Just one thing I want to clear up but other than that LGTM!

return err
}

portForwardCmd := portforward.NewCmdPortForward(factory, *options.ioStreams)
Copy link
Contributor

Choose a reason for hiding this comment

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

@andrewsykim @MortalHappiness Want to make sure I'm on the same page, since I know there were some discussion on the port forwarding. Is the plan to currently use kubectl port forward since it's more straightfoward and change to client-go in the future for more configurability?

Copy link
Member Author

@MortalHappiness MortalHappiness Sep 9, 2024

Choose a reason for hiding this comment

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

Yes, now in #2298 I use the kubectl port-forward directly by calling ExecuteContext (from cobra package).

But I don't know whether we want to change to client-go in the future.

https://pkg.go.dev/github.com/spf13/cobra#Command.ExecuteContext

Copy link
Member

@kevin85421 kevin85421 left a comment

Choose a reason for hiding this comment

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

Merge this PR because @andrewsykim has already approved the PR.

@kevin85421 kevin85421 merged commit 22c2b45 into ray-project:master Sep 10, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants