@@ -23,12 +23,14 @@ import (
23
23
"maps"
24
24
25
25
"github.com/go-logr/logr"
26
+ apierrors "k8s.io/apimachinery/pkg/api/errors"
26
27
"k8s.io/apimachinery/pkg/api/meta"
27
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
29
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
29
30
apiruntime "k8s.io/apimachinery/pkg/runtime"
30
31
"k8s.io/apimachinery/pkg/runtime/schema"
31
32
metav1ac "k8s.io/client-go/applyconfigurations/meta/v1"
33
+ "k8s.io/utils/ptr"
32
34
ctrl "sigs.k8s.io/controller-runtime"
33
35
"sigs.k8s.io/controller-runtime/pkg/builder"
34
36
"sigs.k8s.io/controller-runtime/pkg/cache"
@@ -90,6 +92,20 @@ func (j *JobSet) Build(ctx context.Context, info *runtime.Info, trainJob *traine
90
92
return nil , fmt .Errorf ("runtime info or object is missing" )
91
93
}
92
94
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
+
93
109
// Get the runtime as unstructured from the TrainJob ref
94
110
runtimeJobTemplate := & unstructured.Unstructured {}
95
111
runtimeJobTemplate .SetAPIVersion (trainer .GroupVersion .String ())
0 commit comments