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]'ray log command' Add check and cleanup directory when no ray node exist #2473

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

chiayi
Copy link
Contributor

@chiayi chiayi commented Oct 24, 2024

Why are these changes needed?

Currently, if there is no nodes found when using kubectl ray log, the command ends silently. If no out-dir was specified and directory is generated, it just leaves an empty dir. This PR adds a check and return error if no ray node was found as well as clean up the empty directory if directory was generated.

Before change:
Screenshot 2024-10-24 at 3 29 00 PM

After change:
Screenshot 2024-10-24 at 3 28 07 PM

Related issue number

Checks

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

options.outputDir = options.ResourceName
err := os.MkdirAll(options.outputDir, 0o755)
if err != nil {
return fmt.Errorf("could not create directory with cluster name %s: %w", options.outputDir, err)
}
genereatedDirectory = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of tracking a global env var here, can you check options.outputDir == "" in Run()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The options.outputDir is filled in Validations if the user does not input a outputDir. It then becomes difficult to know if we were the one that generated the dir or its user input.

if len(rayNodes.Items) == 0 {
// Clean up the empty directory if the directory was generated. Since it will always be in current dir, only Remove() is used.
if genereatedDirectory {
os.Remove(options.outputDir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, could we consider a preflight check that at least 1 node exists before we create the directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've also considered that option, but I thought this option was less complex then doing a preflight check in Validations(). Please let me know if you think its a better choice to do a preflight check before we generate the file.

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, just left a minor nit

kubectl-plugin/pkg/cmd/log/log.go Outdated Show resolved Hide resolved
@andrewsykim andrewsykim merged commit 5cb2f56 into ray-project:master Oct 30, 2024
28 of 29 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.

2 participants