Skip to content

Commit 2fc42a2

Browse files
committed
Don't create Slice if Workload doesn't have Topology Assignment.
1 parent 9c1c13b commit 2fc42a2

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

slice/internal/controller/workload_controller.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,20 @@ func (r *WorkloadReconciler) newSlice(wl *kueue.Workload) (*v1alpha1.Slice, erro
110110

111111
if wl.Status.Admission != nil && wl.Status.Admission.PodSetAssignments != nil {
112112
for _, psa := range wl.Status.Admission.PodSetAssignments {
113-
for _, domain := range psa.TopologyAssignment.Domains {
114-
if slice.Spec.NodeSelector == nil {
115-
slice.Spec.NodeSelector = make(map[string][]string)
116-
}
117-
if slice.Spec.NodeSelector[TPUReservationSubblockLabel] == nil {
118-
slice.Spec.NodeSelector[TPUReservationSubblockLabel] = []string{}
119-
}
120-
// make sure there are no duplicates in the nodeSelector
121-
for _, v := range domain.Values {
122-
exists := slices.Contains(slice.Spec.NodeSelector[TPUReservationSubblockLabel], v)
123-
if !exists {
124-
slice.Spec.NodeSelector[TPUReservationSubblockLabel] = append(slice.Spec.NodeSelector[TPUReservationSubblockLabel], v)
113+
if psa.TopologyAssignment != nil {
114+
for _, domain := range psa.TopologyAssignment.Domains {
115+
if slice.Spec.NodeSelector == nil {
116+
slice.Spec.NodeSelector = make(map[string][]string)
117+
}
118+
if slice.Spec.NodeSelector[TPUReservationSubblockLabel] == nil {
119+
slice.Spec.NodeSelector[TPUReservationSubblockLabel] = []string{}
120+
}
121+
// make sure there are no duplicates in the nodeSelector
122+
for _, v := range domain.Values {
123+
exists := slices.Contains(slice.Spec.NodeSelector[TPUReservationSubblockLabel], v)
124+
if !exists {
125+
slice.Spec.NodeSelector[TPUReservationSubblockLabel] = append(slice.Spec.NodeSelector[TPUReservationSubblockLabel], v)
126+
}
125127
}
126128
}
127129
}
@@ -147,6 +149,13 @@ func (r *WorkloadReconciler) createSliceIfNotExist(ctx context.Context, wl *kueu
147149
return err
148150
}
149151

152+
// We should wait for TopologyAssignments.
153+
if len(slice.Spec.NodeSelector) == 0 {
154+
log := ctrl.LoggerFrom(ctx)
155+
log.V(2).Info("Workload does not have TopologyAssignments. Skipping Slice creation for now.")
156+
return nil
157+
}
158+
150159
return r.client.Create(ctx, slice)
151160
}
152161

slice/internal/controller/workload_controller_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,15 @@ func TestWorkloadReconciler(t *testing.T) {
9090
slice: baseSliceWrapper.DeepCopy(),
9191
wantWorkloads: []kueue.Workload{*baseWorkloadWrapper.Clone().Active(false).Obj()},
9292
},
93-
"should add finalizer and create slice": {
93+
"should add a finalizer but shouldn't create a Slice because there's no TopologyAssignment yet": {
9494
request: baseRequest,
95-
workload: baseWorkloadWrapper.UID(types.UID(baseWorkloadName)).DeepCopy(),
95+
workload: baseWorkloadWrapper.Clone().UID(types.UID(baseWorkloadName)).Obj(),
9696
wantWorkloads: []kueue.Workload{
9797
*baseWorkloadWrapper.Clone().
9898
UID(types.UID(baseWorkloadName)).
9999
Finalizers(CleanupSliceFinalizerName).
100100
Obj(),
101101
},
102-
wantSlices: []v1alpha1.Slice{
103-
*baseSliceWrapper.Clone().
104-
ControllerReference(kueue.GroupVersion.WithKind("Workload"), baseWorkloadName, baseWorkloadName).
105-
Obj(),
106-
},
107102
},
108103
"parse TAS Assignment to populate NodeSelector in Slice": {
109104
request: baseRequest,

0 commit comments

Comments
 (0)