Skip to content

Commit 34c7fc7

Browse files
authored
[slice] set type and topology (#677)
1 parent 6ff467b commit 34c7fc7

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

slice/internal/controller/workload_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ func (r *WorkloadReconciler) createSlice(ctx context.Context, wl *kueue.Workload
516516
}
517517
parseTopologyAssignmentIntoNodeSelector(slice, psa.TopologyAssignment, nodes)
518518

519+
ps := podset.FindPodSetByName(wl.Spec.PodSets, psa.Name)
520+
slice.Spec.AcceleratorType = core.GetTPUAccelerator(ps.Template)
521+
slice.Spec.AcceleratorTopology = core.GetTPUTopology(ps.Template)
522+
519523
if err := r.client.Create(ctx, slice); err != nil {
520524
msg := fmt.Sprintf("Error creating Slice %q: %v", client.ObjectKeyFromObject(slice), err)
521525
log.Error(err, msg)

slice/internal/controller/workload_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ func TestWorkloadReconciler(t *testing.T) {
134134
UID(baseWorkloadName).
135135
AdmissionCheck(buildAdmissionCheckState(kueue.CheckStatePending, ""))
136136
baseSlice1Wrapper := utiltesting.MakeSliceWrapper(core.SliceName(baseWorkloadName, "ps1"), corev1.NamespaceDefault).
137+
AcceleratorType("tpu-v7x").
138+
AcceleratorTopology("4x4x12").
137139
ControllerReference(workloadGVK, baseWorkloadName, baseWorkloadName).
138140
NodeSelector(map[string][]string{"cloud.google.com/gke-tpu-slice-4x4x4-id": {"subblock1"}})
139141
baseSlice2Wrapper := baseSlice1Wrapper.Clone().Name(core.SliceName(baseWorkloadName, "ps2")).
142+
AcceleratorType("tpu-v7x").
143+
AcceleratorTopology("4x4x12").
140144
NodeSelector(map[string][]string{"cloud.google.com/gke-tpu-slice-4x4x4-id": {"subblock2"}})
141145

142146
worker1Node := utiltesting.MakeNode("worker1").Label("cloud.google.com/gke-tpu-slice-4x4x4-id", "subblock1")

slice/internal/core/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ const (
2424

2525
TPUSliceHealthNodeSelectorKey = "cloud.google.com/gke-tpu-slice-4x4x4-health"
2626
TPUSliceHealthNodeSelectorValue = "true"
27+
28+
AcceleratorTpu7x = "tpu-v7x"
2729
)

slice/internal/core/core.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ func IsValidTPUTopology(tpuTopology string) bool {
3434
}
3535

3636
func IsValidTPUAccelerator(tpuAccelerator string) bool {
37-
return tpuAccelerator == "tpu-v7x"
37+
return tpuAccelerator == AcceleratorTpu7x
3838
}
3939

4040
func IsRelevantPodTemplateSpec(spec corev1.PodTemplateSpec) bool {
41-
return IsValidTPUTopology(spec.Annotations[TPUTopologyAnnotation]) &&
42-
IsValidTPUAccelerator(spec.Spec.NodeSelector[TPUAcceleratorLabel])
41+
return IsValidTPUTopology(GetTPUTopology(spec)) &&
42+
IsValidTPUAccelerator(GetTPUAccelerator(spec))
43+
}
44+
45+
func GetTPUTopology(spec corev1.PodTemplateSpec) string {
46+
return spec.Annotations[TPUTopologyAnnotation]
47+
}
48+
49+
func GetTPUAccelerator(spec corev1.PodTemplateSpec) string {
50+
return spec.Spec.NodeSelector[TPUAcceleratorLabel]
4351
}

slice/test/e2e/jobset_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ var _ = ginkgo.Describe("JobSet", func() {
221221
g.Expect(k8sClient.Get(ctx, sliceKey, createdSlice)).To(gomega.Succeed())
222222
g.Expect(createdSlice.Spec.NodeSelector).To(gomega.HaveLen(1))
223223
g.Expect(createdSlice.Spec.NodeSelector).To(gomega.BeComparableTo(tc.wantSliceNodeSelector))
224+
g.Expect(createdSlice.Spec.AcceleratorTopology).To(gomega.Equal(tc.tpuTopology))
225+
g.Expect(createdSlice.Spec.AcceleratorType).To(gomega.Equal("tpu-v7x"))
224226
}, utils.Timeout, utils.Interval).Should(gomega.Succeed())
225227
})
226228

0 commit comments

Comments
 (0)