diff --git a/changelogs/unreleased/4872-big-appled b/changelogs/unreleased/4872-big-appled new file mode 100644 index 000000000..739fb5ab1 --- /dev/null +++ b/changelogs/unreleased/4872-big-appled @@ -0,0 +1 @@ +Cleanup the .velero folder after restic done \ No newline at end of file diff --git a/cmd/velero-restic-restore-helper/velero-restic-restore-helper.go b/cmd/velero-restic-restore-helper/velero-restic-restore-helper.go index 65f5e4a60..6622bee11 100644 --- a/cmd/velero-restic-restore-helper/velero-restic-restore-helper.go +++ b/cmd/velero-restic-restore-helper/velero-restic-restore-helper.go @@ -38,6 +38,12 @@ func main() { case <-ticker.C: if done() { fmt.Println("All restic restores are done") + err := removeFolder() + if err != nil { + fmt.Println(err) + } else { + fmt.Println("Done cleanup .velero folder") + } return } } @@ -75,3 +81,28 @@ func done() bool { return true } + +// remove .velero folder +func removeFolder() error { + children, err := ioutil.ReadDir("/restores") + if err != nil { + return err + } + + for _, child := range children { + if !child.IsDir() { + fmt.Printf("%s is not a directory, skipping.\n", child.Name()) + continue + } + + donePath := filepath.Join("/restores", child.Name(), ".velero") + + err = os.RemoveAll(donePath) + if err != nil { + return err + } + fmt.Printf("Deleted %s", donePath) + } + + return nil +}