Skip to content

Commit d8bf3a0

Browse files
authored
fix: apply node affinity to runner pods (#215)
This ensures runner pods are both scheduled on the correct node types and distributed evenly across available nodes for optimal performance testing.
1 parent b700b35 commit d8bf3a0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cmd/kperf/commands/runnergroup/run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var runCommand = cli.Command{
4444
},
4545
cli.StringSliceFlag{
4646
Name: "affinity",
47-
Usage: "Deploy server to the node with a specific labels (FORMAT: KEY=VALUE[,VALUE])",
47+
Usage: "Deploy server and runners to the node with a specific labels (FORMAT: KEY=VALUE[,VALUE])",
4848
},
4949
cli.IntFlag{
5050
Name: "runner-verbosity",
@@ -76,6 +76,8 @@ var runCommand = cli.Command{
7676
return fmt.Errorf("only support one runner group right now. will support it after https://github.com/Azure/kperf/issues/25")
7777
}
7878

79+
specs[0].NodeAffinity = affinityLabels
80+
7981
kubeCfgPath := cliCtx.GlobalString("kubeconfig")
8082
return runner.CreateRunnerGroupServer(context.Background(),
8183
kubeCfgPath,

runner/group/handler.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ func (h *Handler) buildBatchJobObject(uploadURL string) *batchv1.Job {
374374
job.OwnerReferences = append(job.OwnerReferences, *h.ownerRef)
375375
}
376376

377+
job.Spec.Template.ObjectMeta = metav1.ObjectMeta{
378+
Labels: map[string]string{
379+
"app-name-job": h.name,
380+
},
381+
}
377382
job.Spec.Template.Spec = corev1.PodSpec{
378383
Affinity: &corev1.Affinity{},
379384
Containers: []corev1.Container{
@@ -430,6 +435,19 @@ func (h *Handler) buildBatchJobObject(uploadURL string) *batchv1.Job {
430435
},
431436
},
432437
RestartPolicy: corev1.RestartPolicyNever,
438+
TopologySpreadConstraints: []corev1.TopologySpreadConstraint{
439+
{
440+
MaxSkew: 1,
441+
TopologyKey: "kubernetes.io/hostname",
442+
WhenUnsatisfiable: corev1.ScheduleAnyway,
443+
LabelSelector: &metav1.LabelSelector{
444+
MatchLabels: map[string]string{
445+
"app-name-job": h.name,
446+
},
447+
},
448+
},
449+
},
450+
433451
Volumes: []corev1.Volume{
434452
{
435453
Name: "config",

0 commit comments

Comments
 (0)