Skip to content

Commit

Permalink
PB-7859: Add node affinity for kdmp live backup job pods with ROX or …
Browse files Browse the repository at this point in the history
…RWX pvc
  • Loading branch information
shkumari-px committed Aug 22, 2024
1 parent 22b4371 commit 6e81b69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkg/drivers/kopiabackup/kopiabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/drivers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 6e81b69

Please sign in to comment.