From dc273e3bed595c477a57afda3d90429735d5bf26 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Tue, 12 Jun 2018 13:39:29 -0700 Subject: [PATCH] remove existing .ark dir and contents during restic restores Signed-off-by: Steve Kriss --- pkg/controller/pod_volume_restore_controller.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/controller/pod_volume_restore_controller.go b/pkg/controller/pod_volume_restore_controller.go index 97967550f..33b79122d 100644 --- a/pkg/controller/pod_volume_restore_controller.go +++ b/pkg/controller/pod_volume_restore_controller.go @@ -324,6 +324,14 @@ func restorePodVolume(req *arkv1api.PodVolumeRestore, credsFile, volumeDir strin return errors.Wrap(err, "error identifying path of volume") } + // Remove the .ark directory from the staging directory (it may contain done files from previous restores + // of this volume, which we don't want to carry over). If this fails for any reason, log and continue, since + // this is non-essential cleanup (the done files are named based on restore UID and the init container looks + // for the one specific to the restore being executed). + if err := os.RemoveAll(filepath.Join(restorePath, ".ark")); err != nil { + log.WithError(err).Warnf("error removing .ark directory from staging directory %s", restorePath) + } + // Move the contents of the staging directory into the new volume directory to finalize the restore. Trailing // slashes are needed so the *contents* of restorePath/ are moved into volumePath/. --delete removes files/dirs // in the destination that aren't in source, and --archive copies recursively while retaining perms, owners, @@ -337,7 +345,7 @@ func restorePodVolume(req *arkv1api.PodVolumeRestore, credsFile, volumeDir strin // Don't fail the restore if this returns an error, since the actual directory content // has already successfully been moved into the pod volume. if err := os.RemoveAll(restorePath); err != nil { - log.WithError(err).Warnf("error removing staging directory %s for pod volume restore %s/%s", restorePath, req.Namespace, req.Name) + log.WithError(err).Warnf("error removing staging directory %s", restorePath) } var restoreUID types.UID @@ -354,8 +362,6 @@ func restorePodVolume(req *arkv1api.PodVolumeRestore, credsFile, volumeDir strin return errors.Wrap(err, "error creating .ark directory for done file") } - // TODO remove any done files from previous ark restores from .ark - // Write a done file with name= into the just-created .ark dir // within the volume. The ark restic init container on the pod is waiting // for this file to exist in each restored volume before completing.