From 877592194b76ddfd472cde71e56f434fd73a8eb4 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Tue, 10 Oct 2023 11:04:04 +0800 Subject: [PATCH] issue 6734: spread backup pod evenly Signed-off-by: Lyndon-Li --- changelogs/unreleased/6935-Lyndon-Li | 1 + pkg/exposer/csi_snapshot.go | 18 ++++++++++++++++++ pkg/exposer/types.go | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 changelogs/unreleased/6935-Lyndon-Li diff --git a/changelogs/unreleased/6935-Lyndon-Li b/changelogs/unreleased/6935-Lyndon-Li new file mode 100644 index 0000000000..b14c4f3cce --- /dev/null +++ b/changelogs/unreleased/6935-Lyndon-Li @@ -0,0 +1 @@ +Partially fix #6734, guide Kubernetes' scheduler to spread backup pods evenly across nodes as much as possible, so that data mover backup could achieve better parallelism \ No newline at end of file diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index a0492d5233..85f511524c 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -361,6 +361,12 @@ func (e *csiSnapshotExposer) createBackupPod(ctx context.Context, ownerObject co var gracePeriod int64 = 0 volumeMounts, volumeDevices := kube.MakePodPVCAttachment(volumeName, backupPVC.Spec.VolumeMode) + if label == nil { + label = make(map[string]string) + } + + label[podGroupLabel] = podGroupSnapshot + pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: podName, @@ -377,6 +383,18 @@ func (e *csiSnapshotExposer) createBackupPod(ctx context.Context, ownerObject co Labels: label, }, Spec: corev1.PodSpec{ + TopologySpreadConstraints: []corev1.TopologySpreadConstraint{ + { + MaxSkew: 1, + TopologyKey: "kubernetes.io/hostname", + WhenUnsatisfiable: corev1.ScheduleAnyway, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + podGroupLabel: podGroupSnapshot, + }, + }, + }, + }, Containers: []corev1.Container{ { Name: containerName, diff --git a/pkg/exposer/types.go b/pkg/exposer/types.go index 21c473366d..f87620e8f8 100644 --- a/pkg/exposer/types.go +++ b/pkg/exposer/types.go @@ -23,6 +23,8 @@ import ( const ( AccessModeFileSystem = "by-file-system" AccessModeBlock = "by-block-device" + podGroupLabel = "velero.io/exposer-pod-group" + podGroupSnapshot = "snapshot-exposer" ) // ExposeResult defines the result of expose.