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..d9fdfccad 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,11 @@ func main() { case <-ticker.C: if done() { fmt.Println("All restic restores are done") + err := removeFolder() + if err != nil { + fmt.Println(err) + } + fmt.Println("Cleanup .velero folder") return } } @@ -75,3 +80,29 @@ func done() bool { return true } + +// remove .velero folder +func removeFolder() error { + children, err := ioutil.ReadDir("/restores") + if err != nil { + fmt.Fprintf(os.Stderr, "ERROR reading /restores directory: %s\n", err) + 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 +}