Merge pull request #1246 from skriss/preserve-storageclass

when restoring a PV, don't remove its spec.storageClassName
This commit is contained in:
Nolan Brubaker
2019-02-28 18:02:20 -05:00
committed by GitHub
3 changed files with 10 additions and 4 deletions

View File

View File

@@ -1130,7 +1130,6 @@ func (r *pvRestorer) executePVAction(obj *unstructured.Unstructured) (*unstructu
}
delete(spec, "claimRef")
delete(spec, "storageClassName")
if boolptr.IsSetToFalse(r.snapshotVolumes) {
// The backup had snapshots disabled, so we can return early

View File

@@ -1344,18 +1344,25 @@ func TestExecutePVAction_NoSnapshotRestores(t *testing.T) {
expectedErr: true,
},
{
name: "ensure spec.claimRef, spec.storageClassName are deleted",
obj: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("claimRef", "storageClassName", "someOtherField").Unstructured,
name: "ensure spec.claimRef is deleted",
obj: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("claimRef", "someOtherField").Unstructured,
restore: velerotest.NewDefaultTestRestore().WithRestorePVs(false).Restore,
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(api.BackupPhaseInProgress).Backup,
expectedRes: NewTestUnstructured().WithAnnotations("a", "b").WithName("pv-1").WithSpec("someOtherField").Unstructured,
},
{
name: "ensure spec.storageClassName is retained",
obj: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("storageClassName", "someOtherField").Unstructured,
restore: velerotest.NewDefaultTestRestore().WithRestorePVs(false).Restore,
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(api.BackupPhaseInProgress).Backup,
expectedRes: NewTestUnstructured().WithAnnotations("a", "b").WithName("pv-1").WithSpec("storageClassName", "someOtherField").Unstructured,
},
{
name: "if backup.spec.snapshotVolumes is false, ignore restore.spec.restorePVs and return early",
obj: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("claimRef", "storageClassName", "someOtherField").Unstructured,
restore: velerotest.NewDefaultTestRestore().WithRestorePVs(true).Restore,
backup: velerotest.NewTestBackup().WithName("backup1").WithPhase(api.BackupPhaseInProgress).WithSnapshotVolumes(false).Backup,
expectedRes: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("someOtherField").Unstructured,
expectedRes: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("storageClassName", "someOtherField").Unstructured,
},
{
name: "restore.spec.restorePVs=false, return early",