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

Set node affinity during unsuspend #142

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
implemented nodeAfinties on resume job
  • Loading branch information
mcariatm committed May 12, 2023
commit 897d1b0155525bb4d0f7bf54aa8b2e3fa5549257
8 changes: 8 additions & 0 deletions pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"
"sync"

batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -238,10 +239,17 @@ func (r *JobSetReconciler) suspendJobSet(ctx context.Context, js *jobset.JobSet,
}

func (r *JobSetReconciler) resumeJobSetIfNecessary(ctx context.Context, js *jobset.JobSet, ownedJobs *childJobs) error {
nodeAffinities := map[string]map[string]string{}
for _, replicatedJob := range js.Spec.ReplicatedJobs {
nodeAffinities[fmt.Sprintf("%s-%s", js.Name, replicatedJob.Name)] = replicatedJob.Template.Spec.Template.Spec.NodeSelector
}

// If JobSpec is unsuspended, ensure all active child Jobs are also
// unsuspended and update the suspend condition to true.
for _, job := range ownedJobs.active {
if pointer.BoolDeref(job.Spec.Suspend, false) != false {
i := strings.LastIndex(job.Name, "-")
job.Spec.Template.Spec.NodeSelector = nodeAffinities[job.Name[:i]]
job.Spec.Suspend = pointer.Bool(false)
if err := r.Update(ctx, job); err != nil {
return err
Expand Down