Skip to content

Commit ade55bd

Browse files
committed
Do not update JobSets that are not suspended
Signed-off-by: Antonin Stefanutti <[email protected]>
1 parent 56dc0dd commit ade55bd

File tree

1 file changed

+16
-0
lines changed
  • pkg/runtime/framework/plugins/jobset

1 file changed

+16
-0
lines changed

pkg/runtime/framework/plugins/jobset/jobset.go

+16
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import (
2323
"maps"
2424

2525
"github.com/go-logr/logr"
26+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2627
"k8s.io/apimachinery/pkg/api/meta"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2930
apiruntime "k8s.io/apimachinery/pkg/runtime"
3031
"k8s.io/apimachinery/pkg/runtime/schema"
3132
metav1ac "k8s.io/client-go/applyconfigurations/meta/v1"
33+
"k8s.io/utils/ptr"
3234
ctrl "sigs.k8s.io/controller-runtime"
3335
"sigs.k8s.io/controller-runtime/pkg/builder"
3436
"sigs.k8s.io/controller-runtime/pkg/cache"
@@ -90,6 +92,20 @@ func (j *JobSet) Build(ctx context.Context, info *runtime.Info, trainJob *traine
9092
return nil, fmt.Errorf("runtime info or object is missing")
9193
}
9294

95+
// Do not update the JobSet if it already exists and is not suspended
96+
oldJobSet := &jobsetv1alpha2.JobSet{}
97+
if err := j.client.Get(ctx, client.ObjectKeyFromObject(trainJob), oldJobSet); err != nil {
98+
if !apierrors.IsNotFound(err) {
99+
return nil, err
100+
}
101+
oldJobSet = nil
102+
}
103+
if oldJobSet != nil &&
104+
!ptr.Deref(trainJob.Spec.Suspend, false) &&
105+
!ptr.Deref(oldJobSet.Spec.Suspend, false) {
106+
return nil, nil
107+
}
108+
93109
// Get the runtime as unstructured from the TrainJob ref
94110
runtimeJobTemplate := &unstructured.Unstructured{}
95111
runtimeJobTemplate.SetAPIVersion(trainer.GroupVersion.String())

0 commit comments

Comments
 (0)