From bc15fe8d9ca76270339c1509a70f5addd8670750 Mon Sep 17 00:00:00 2001 From: Ning Ding <834652870@qq.com> Date: Thu, 28 Apr 2022 20:24:12 +0800 Subject: [PATCH 1/2] cleanup restic helper folder when done Signed-off-by: Ning Ding <834652870@qq.com> --- .../velero-restic-restore-helper.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 65f5e4a60f..d9fdfccad7 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 +} From e09c31e5590e63ab128a7dcbab3aba156a986a65 Mon Sep 17 00:00:00 2001 From: Ning Ding <834652870@qq.com> Date: Mon, 9 May 2022 15:55:14 +0800 Subject: [PATCH 2/2] changes according to review comments Signed-off-by: Ning Ding <834652870@qq.com> --- changelogs/unreleased/4872-big-appled | 1 + .../velero-restic-restore-helper.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/4872-big-appled diff --git a/changelogs/unreleased/4872-big-appled b/changelogs/unreleased/4872-big-appled new file mode 100644 index 0000000000..739fb5ab11 --- /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 d9fdfccad7..6622bee11b 100644 --- a/cmd/velero-restic-restore-helper/velero-restic-restore-helper.go +++ b/cmd/velero-restic-restore-helper/velero-restic-restore-helper.go @@ -41,8 +41,9 @@ func main() { err := removeFolder() if err != nil { fmt.Println(err) + } else { + fmt.Println("Done cleanup .velero folder") } - fmt.Println("Cleanup .velero folder") return } } @@ -85,7 +86,6 @@ func done() bool { func removeFolder() error { children, err := ioutil.ReadDir("/restores") if err != nil { - fmt.Fprintf(os.Stderr, "ERROR reading /restores directory: %s\n", err) return err }