diff --git a/pkg/drivers/kopiabackup/kopiabackup.go b/pkg/drivers/kopiabackup/kopiabackup.go index d50220e0..66fe825c 100644 --- a/pkg/drivers/kopiabackup/kopiabackup.go +++ b/pkg/drivers/kopiabackup/kopiabackup.go @@ -402,10 +402,6 @@ func jobFor( } } - if len(nodeName) != 0 { - job.Spec.Template.Spec.NodeName = nodeName - } - // Add the image secret in job spec only if it is present in the stork deployment. if len(imageRegistrySecret) != 0 { job.Spec.Template.Spec.ImagePullSecrets = utils.ToImagePullSecret(utils.GetImageSecretName(jobName)) @@ -417,6 +413,28 @@ func jobFor( if err != nil { return nil, err } + } else { + accessModes, err := utils.GetAccessModeFromPvc(jobOption.SourcePVCName, jobOption.SourcePVCNamespace) + if err != nil { + return nil, err + } + + var singleNodeMount bool + for _, val := range accessModes { + if val == "ReadWriteOnce" || val == "ReadWriteOncePod" { + singleNodeMount = true + break + } + } + + if singleNodeMount && len(nodeName) != 0 { + job.Spec.Template.Spec.NodeName = nodeName + } else if !singleNodeMount { + job, err = utils.AddNodeAffinityToJob(job, jobOption) + if err != nil { + return nil, err + } + } } if len(jobOption.NfsServer) != 0 { diff --git a/pkg/drivers/utils/utils.go b/pkg/drivers/utils/utils.go index 2341d6e7..410334db 100644 --- a/pkg/drivers/utils/utils.go +++ b/pkg/drivers/utils/utils.go @@ -1168,3 +1168,13 @@ func AddNodeAffinityToJob(job *batchv1.Job, jobOption drivers.JobOpts) (*batchv1 } return job, nil } + +// GetAccessModeFromPvc gets the access modes of the pvc +func GetAccessModeFromPvc(srcPvcName, srcPvcNameSpace string) ([]corev1.PersistentVolumeAccessMode, error) { + srcPvc, err := core.Instance().GetPersistentVolumeClaim(srcPvcName, srcPvcNameSpace) + if err != nil { + return nil, err + } + accessModes := srcPvc.Status.AccessModes + return accessModes, nil +}