Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(migration): update volume migration to run in parallel #52

Merged
merged 3 commits into from
Sep 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/migrate/cstor/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,16 @@ func (v *VolumeMigrator) updateStorageClass(pvName, scName string) error {
return err
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
}
}
cond0, ret0 := isTmpSCValid(v, scName)
mittachaitu marked this conversation as resolved.
Show resolved Hide resolved
if cond0 {
return ret0
}
if scObj == nil || scObj.Provisioner != cstorCSIDriver {
tmpSCObj, err = v.createTmpSC(scName)
if err != nil {
if k8serrors.IsAlreadyExists(err) {
return nil
}
return err
}
replicaCount, err := v.getReplicaCount(pvName)
Expand Down Expand Up @@ -587,6 +594,22 @@ func (v *VolumeMigrator) updateStorageClass(pvName, scName string) error {
return nil
}

// While running multiple volume migration in parallel there can be
// a race condition to update a common storageclass shared between
// the volumes. This check makes sure that only one migration job which
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
// was able to create the temporary storageclass will update the storageclass
// and other jobs will skip this step.
func isTmpSCValid(v *VolumeMigrator, scName string) (bool, error) {
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
tmpSC, err := v.KubeClientset.StorageV1().StorageClasses().
Get("tmp-migrate-"+scName, metav1.GetOptions{})
if err == nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No need of this if block

if tmpSC.Annotations["pv-name"] != v.PVName {
return true, nil
}
}
return false, nil
}

func (v *VolumeMigrator) createTmpSC(scName string) (*storagev1.StorageClass, error) {
tmpSCName := "tmp-migrate-" + scName
tmpSCObj, err := v.KubeClientset.StorageV1().
Expand All @@ -606,9 +629,13 @@ func (v *VolumeMigrator) createTmpSC(scName string) (*storagev1.StorageClass, er
Annotations: scObj.Annotations,
Labels: scObj.Labels,
}
tmpSCObj.Annotations["pv-name"] = v.PVName
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
tmpSCObj, err = v.KubeClientset.StorageV1().
StorageClasses().Create(tmpSCObj)
if err != nil {
if k8serrors.IsAlreadyExists(err) {
return nil, err
prateekpandey14 marked this conversation as resolved.
Show resolved Hide resolved
}
return nil, errors.Wrapf(err, "failed to create temporary storageclass")
}
}
Expand Down