fix: delete empty backups

Signed-off-by: Yuval Manor <yuvalman958@gmail.com>
This commit is contained in:
I538157
2022-04-08 10:05:17 +03:00
committed by Yuval Manor
parent 20c2073428
commit 74db20993b
6 changed files with 57 additions and 28 deletions

View File

@@ -62,16 +62,17 @@ func InvokeDeleteActions(ctx *Context) error {
dir, err := archive.NewExtractor(ctx.Log, ctx.Filesystem).UnzipAndExtractBackup(ctx.BackupReader)
if err != nil {
return errors.Wrapf(err, "error extracting backup")
}
defer ctx.Filesystem.RemoveAll(dir)
ctx.Log.Debugf("Downloaded and extracted the backup file to: %s", dir)
backupResources, err := archive.NewParser(ctx.Log, ctx.Filesystem).Parse(dir)
if err != nil {
if existErr := errors.Is(err, archive.ErrNotExist); existErr {
ctx.Log.Debug("ignore invoking delete item actions: ", err)
return nil
} else if err != nil {
return errors.Wrapf(err, "error parsing backup %q", dir)
}
processdResources := sets.NewString()
for resource := range backupResources {

View File

@@ -138,6 +138,17 @@ func TestInvokeDeleteItemActionsRunForCorrectItems(t *testing.T) {
new(recordResourcesAction).ForLabelSelector("app=app1"): {"ns-1/pod-1", "ns-2/pvc-2"},
},
},
{
name: "success if resources dir does not exist",
backup: builder.ForBackup("velero", "velero").Result(),
tarball: test.NewTarWriter(t).
Done(),
apiResources: []*test.APIResource{test.Pods(), test.PVCs()},
actions: map[*recordResourcesAction][]string{
new(recordResourcesAction).ForNamespace("ns-1").ForResource("persistentvolumeclaims"): nil,
new(recordResourcesAction).ForNamespace("ns-2").ForResource("pods"): nil,
},
},
}
for _, tc := range tests {
@@ -149,7 +160,7 @@ func TestInvokeDeleteItemActionsRunForCorrectItems(t *testing.T) {
}
// Get the plugins out of the map in order to use them.
actions := []velero.DeleteItemAction{}
var actions []velero.DeleteItemAction
for action := range tc.actions {
actions = append(actions, action)
}