Skip to content

Commit c5c3f26

Browse files
authored
Constrain test to single node (#252)
1 parent 607bd59 commit c5c3f26

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ charts/
44
cover.out
55
.DS_Store
66
coverage/
7-
*.test
7+
*.test
8+
launch.json

test/e2e/modules/resources/rd/node.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ func FindNodesWithEnoughGPUs(ctx context.Context, client runtimeClient.Client, n
119119
return gpuNodes
120120
}
121121

122+
func FindNodesWithExactGPUs(ctx context.Context, client runtimeClient.Client, numFreeGPUs int64) []*corev1.Node {
123+
allNodes := corev1.NodeList{}
124+
var gpuNodes []*corev1.Node
125+
Expect(client.List(ctx, &allNodes)).To(Succeed())
126+
for index, node := range allNodes.Items {
127+
gpusQty, found := node.Status.Allocatable[constants.GpuResource]
128+
if !found || gpusQty.IsZero() {
129+
continue
130+
}
131+
desiredQty := resource.NewQuantity(numFreeGPUs, resource.DecimalSI)
132+
if gpusQty.Cmp(*desiredQty) == 0 {
133+
gpuNodes = append(gpuNodes, &allNodes.Items[index])
134+
}
135+
}
136+
return gpuNodes
137+
}
138+
122139
func GetNodeGpuDeviceMemory(ctx context.Context, client runtimeClient.Client, nodeName string) int64 {
123140
node := &v1.Node{}
124141
err := client.Get(ctx, runtimeClient.ObjectKey{Name: nodeName}, node)

test/e2e/suites/reclaim/reclaim_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ var _ = Describe("Reclaim", Ordered, func() {
278278
},
279279
})
280280

281+
nodes := rd.FindNodesWithExactGPUs(ctx, testCtx.ControllerClient, 8)
282+
Expect(len(nodes)).To(BeNumerically(">", 0))
283+
testNodeName := nodes[0].Name
284+
281285
parentQueue, reclaimee1Queue, reclaimee2Queue := createQueues(8, 1, 1)
282286
reclaimee1Queue.Spec.Resources.GPU.OverQuotaWeight = 1
283287
reclaimee2Queue.Spec.Resources.GPU.OverQuotaWeight = 2
@@ -302,6 +306,9 @@ var _ = Describe("Reclaim", Ordered, func() {
302306
constants.GpuResource: resource.MustParse("1"),
303307
},
304308
})
309+
job.Spec.Template.Spec.NodeSelector = map[string]string{
310+
"kubernetes.io/hostname": testNodeName,
311+
}
305312
err := testCtx.ControllerClient.Create(ctx, job)
306313
Expect(err).To(Succeed())
307314
}
@@ -312,6 +319,9 @@ var _ = Describe("Reclaim", Ordered, func() {
312319
constants.GpuResource: resource.MustParse("1"),
313320
},
314321
})
322+
job.Spec.Template.Spec.NodeSelector = map[string]string{
323+
"kubernetes.io/hostname": testNodeName,
324+
}
315325
err := testCtx.ControllerClient.Create(ctx, job)
316326
Expect(err).To(Succeed())
317327
}
@@ -338,6 +348,9 @@ var _ = Describe("Reclaim", Ordered, func() {
338348
constants.GpuResource: resource.MustParse("3"),
339349
},
340350
})
351+
reclaimerPod.Spec.NodeSelector = map[string]string{
352+
"kubernetes.io/hostname": testNodeName,
353+
}
341354
reclaimerPod, err = rd.CreatePod(ctx, testCtx.KubeClientset, reclaimerPod)
342355
Expect(err).To(Succeed())
343356
wait.ForPodScheduled(ctx, testCtx.ControllerClient, reclaimerPod)

0 commit comments

Comments
 (0)