Update migration behavior for PVs
Set reclaim policy to Retain if volumes aren't being migrated
Update PV if it already exists instead of deleting and creating
@@ -603,7 +603,7 @@ func (m *MigrationController) prepareResources(
switch o.GetObjectKind().GroupVersionKind().Kind {
case "PersistentVolume":
- err := m.preparePVResource(o)
+ err := m.preparePVResource(migration, o)
if err != nil {
return fmt.Errorf("error preparing PV resource %v: %v", metadata.GetName(), err)
}
@@ -652,8 +652,17 @@ func (m *MigrationController) updateResourceStatus(
}
func (m *MigrationController) preparePVResource(
+ migration *stork_api.Migration,
object runtime.Unstructured,
) error {
+ // Set the reclaim policy to retain if the volumes are not being migrated
+ if migration.Spec.IncludeVolumes != nil && !*migration.Spec.IncludeVolumes {
+ spec, err := collections.GetMap(object.UnstructuredContent(), "spec")
+ if err != nil {
+ return err
+ }
+ spec["persistentVolumeReclaimPolicy"] = v1.PersistentVolumeReclaimRetain
+ }
_, err := m.Driver.UpdateMigratedPersistentVolumeSpec(object)
return err
}
@@ -774,8 +783,14 @@ func (m *MigrationController) applyResources(
if err != nil && (apierrors.IsAlreadyExists(err) || strings.Contains(err.Error(), portallocator.ErrAllocated.Error())) {
switch objectType.GetKind() {
// Don't want to delete the Volume resources
- case "PersistentVolumeClaim", "PersistentVolume":
+ case "PersistentVolumeClaim":
err = nil
+ case "PersistentVolume":
+ if migration.Spec.IncludeVolumes == nil || *migration.Spec.IncludeVolumes {
+ err = nil
+ } else {
+ _, err = dynamicClient.Update(unstructured)
+ }
default:
// Delete the resource if it already exists on the destination
// cluster and try creating again
