-
Notifications
You must be signed in to change notification settings - Fork 230
Fix launcher job scheduling directives when unsuspending #772
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -687,9 +687,28 @@ func (c *MPIJobController) syncHandler(key string) error { | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if launcher != nil { | ||||||||||||||||||||||||||||||
| if isMPIJobSuspended(mpiJob) != isJobSuspended(launcher) { | ||||||||||||||||||||||||||||||
| // align the suspension state of launcher with the MPIJob | ||||||||||||||||||||||||||||||
| launcher.Spec.Suspend = ptr.To(isMPIJobSuspended(mpiJob)) | ||||||||||||||||||||||||||||||
| if !isMPIJobSuspended(mpiJob) && isJobSuspended(launcher) { | ||||||||||||||||||||||||||||||
| // We are unsuspending, hence we need to sync the pod template with the current MPIJob spec. | ||||||||||||||||||||||||||||||
| // This is important for interop with Kueue as it may have injected schedulingGates. | ||||||||||||||||||||||||||||||
| // Kubernetes validates that a Job template is immutable once StartTime is set, | ||||||||||||||||||||||||||||||
| // so we must clear it first via a status sub-resource update (consistent with JobSet). | ||||||||||||||||||||||||||||||
| if launcher.Status.StartTime != nil { | ||||||||||||||||||||||||||||||
| launcher.Status.StartTime = nil | ||||||||||||||||||||||||||||||
| if _, err := c.kubeClient.BatchV1().Jobs(namespace).UpdateStatus(context.TODO(), launcher, metav1.UpdateOptions{}); err != nil { | ||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Sync mutable scheduling directives (KEP-2926) and unsuspend. | ||||||||||||||||||||||||||||||
| desiredPodTemplate := c.newLauncherPodTemplate(mpiJob) | ||||||||||||||||||||||||||||||
| syncLauncherSchedulingDirectives(launcher, &desiredPodTemplate) | ||||||||||||||||||||||||||||||
| launcher.Spec.Suspend = ptr.To(false) | ||||||||||||||||||||||||||||||
| if _, err := c.kubeClient.BatchV1().Jobs(namespace).Update(context.TODO(), launcher, metav1.UpdateOptions{}); err != nil { | ||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } else if isMPIJobSuspended(mpiJob) && !isJobSuspended(launcher) { | ||||||||||||||||||||||||||||||
| // align the suspension state of launcher with the MPIJob. | ||||||||||||||||||||||||||||||
| launcher.Spec.Suspend = ptr.To(true) | ||||||||||||||||||||||||||||||
| if _, err := c.kubeClient.BatchV1().Jobs(namespace).Update(context.TODO(), launcher, metav1.UpdateOptions{}); err != nil { | ||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
@@ -1623,6 +1642,30 @@ func (c *MPIJobController) newLauncherPodTemplate(mpiJob *kubeflow.MPIJob) corev | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // syncLauncherSchedulingDirectives updates the mutable scheduling directives (as per KEP-2926) on | ||||||||||||||||||||||||||||||
| // the launcher Job's pod template to match the desired template. | ||||||||||||||||||||||||||||||
| func syncLauncherSchedulingDirectives(launcher *batchv1.Job, desired *corev1.PodTemplateSpec) { | ||||||||||||||||||||||||||||||
| if launcher.Spec.Template.Labels == nil { | ||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Optimizing initialization would be better. |
||||||||||||||||||||||||||||||
| launcher.Spec.Template.Labels = make(map[string]string) | ||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| for k, v := range desired.Labels { | ||||||||||||||||||||||||||||||
| launcher.Spec.Template.Labels[k] = v | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if desired.Annotations != nil { | ||||||||||||||||||||||||||||||
| if launcher.Spec.Template.Annotations == nil { | ||||||||||||||||||||||||||||||
| launcher.Spec.Template.Annotations = make(map[string]string) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| for k, v := range desired.Annotations { | ||||||||||||||||||||||||||||||
| launcher.Spec.Template.Annotations[k] = v | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+1655
to
+1662
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The range loop will be executed only when the |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| launcher.Spec.Template.Spec.NodeSelector = desired.Spec.NodeSelector | ||||||||||||||||||||||||||||||
| launcher.Spec.Template.Spec.Tolerations = desired.Spec.Tolerations | ||||||||||||||||||||||||||||||
| launcher.Spec.Template.Spec.SchedulingGates = desired.Spec.SchedulingGates | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| func (c *MPIJobController) jobPods(j *batchv1.Job) ([]*corev1.Pod, error) { | ||||||||||||||||||||||||||||||
| selector, err := metav1.LabelSelectorAsSelector(j.Spec.Selector) | ||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update launcher after startTime update to avoid coflict while scheduling directive update?