@@ -324,6 +324,16 @@ func (options *SubmitJobOptions) Run(ctx context.Context, factory cmdutil.Factor
324324 return fmt .Errorf ("failed to initialize clientset: %w" , err )
325325 }
326326
327+ // If submission ID is not provided by the user, generate one.
328+ if options .submissionID == "" {
329+ generatedID , err := generateSubmissionID ()
330+ if err != nil {
331+ return fmt .Errorf ("failed to generate submission ID: %w" , err )
332+ }
333+ options .submissionID = generatedID
334+ fmt .Printf ("Generated submission ID for Ray job: %s\n " , options .submissionID )
335+ }
336+
327337 if options .fileName == "" {
328338 // Genarate the Ray job.
329339 rayJobObject := generation.RayJobYamlObject {
@@ -358,6 +368,7 @@ func (options *SubmitJobOptions) Run(ctx context.Context, factory cmdutil.Factor
358368 },
359369 }
360370 rayJobApplyConfig := rayJobObject .GenerateRayJobApplyConfig ()
371+ rayJobApplyConfig .Spec .JobId = & options .submissionID
361372
362373 // Print out the yaml if it is a dry run
363374 if options .dryRun {
@@ -378,6 +389,7 @@ func (options *SubmitJobOptions) Run(ctx context.Context, factory cmdutil.Factor
378389 options .RayJob = & rayv1.RayJob {}
379390 options .RayJob .SetName (rayJobApplyConfigResult .Name )
380391 } else {
392+ options .RayJob .Spec .JobId = options .submissionID
381393 options .RayJob , err = k8sClients .RayClient ().RayV1 ().RayJobs (options .namespace ).Create (ctx , options .RayJob , v1.CreateOptions {FieldManager : util .FieldManager })
382394 if err != nil {
383395 return fmt .Errorf ("Error when creating RayJob CR: %w" , err )
@@ -486,16 +498,6 @@ func (options *SubmitJobOptions) Run(ctx context.Context, factory cmdutil.Factor
486498 fmt .Printf ("Using address %s (no port-forwarding)\n " , options .address )
487499 }
488500
489- // If submission ID is not provided by the user, generate one.
490- if options .submissionID == "" {
491- generatedID , err := generateSubmissionID ()
492- if err != nil {
493- return fmt .Errorf ("failed to generate submission ID: %w" , err )
494- }
495- options .submissionID = generatedID
496- fmt .Printf ("Generated submission ID for Ray job: %s\n " , options .submissionID )
497- }
498-
499501 // Submitting ray job to cluster
500502 raySubmitCmd , err := options .raySubmitCmd ()
501503 if err != nil {
@@ -514,13 +516,10 @@ func (options *SubmitJobOptions) Run(ctx context.Context, factory cmdutil.Factor
514516 return fmt .Errorf ("Error while setting up `ray job submit` stderr: %w" , err )
515517 }
516518
517- go func () {
518- fmt .Printf ("Running Ray submit job command...\n " )
519- err := cmd .Start ()
520- if err != nil {
521- log .Fatalf ("error occurred while running command %s: %v" , fmt .Sprint (raySubmitCmd ), err )
522- }
523- }()
519+ fmt .Printf ("Running Ray submit job command...\n " )
520+ if err := cmd .Start (); err != nil {
521+ log .Fatalf ("error occurred while running command %s: %v" , fmt .Sprint (raySubmitCmd ), err )
522+ }
524523
525524 rayJobID := options .submissionID
526525
@@ -551,18 +550,6 @@ func (options *SubmitJobOptions) Run(ctx context.Context, factory cmdutil.Factor
551550 }
552551 }()
553552
554- // Add annotation to RayJob with the correct Ray job ID and update the CR
555- options .RayJob , err = k8sClients .RayClient ().RayV1 ().RayJobs (options .namespace ).Get (ctx , options .RayJob .GetName (), v1.GetOptions {})
556- if err != nil {
557- return fmt .Errorf ("Failed to get latest version of Ray job: %w" , err )
558- }
559- options .RayJob .Spec .JobId = rayJobID
560-
561- _ , err = k8sClients .RayClient ().RayV1 ().RayJobs (options .namespace ).Update (ctx , options .RayJob , v1.UpdateOptions {FieldManager : util .FieldManager })
562- if err != nil {
563- return fmt .Errorf ("Error occurred when trying to add job ID to RayJob: %w" , err )
564- }
565-
566553 // Wait for Ray job submit to finish.
567554 err = cmd .Wait ()
568555 if err != nil {
0 commit comments