Don't log error if restic volume is empty (#1480)

* Don't log error if restic volume is empty

Signed-off-by: Carlisia <carlisiac@vmware.com>
reviewable/pr1532/r1
KubeKween 2019-05-30 09:48:21 -07:00 committed by Nolan Brubaker
parent 411d44a673
commit 0804f34644
3 changed files with 24 additions and 8 deletions

View File

@ -0,0 +1 @@
Stop returning an error when a restic volume is empty since it is a valid scenario.

View File

@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 2018, 2019 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -228,23 +228,34 @@ func (c *podVolumeBackupController) processBackup(req *velerov1api.PodVolumeBack
var stdout, stderr string
var emptySnapshot bool
if stdout, stderr, err = veleroexec.RunCommand(resticCmd.Cmd()); err != nil {
log.WithError(errors.WithStack(err)).Errorf("Error running command=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
return c.fail(req, fmt.Sprintf("error running restic backup, stderr=%s: %s", stderr, err.Error()), log)
if strings.Contains(stderr, "snapshot is empty") {
emptySnapshot = true
} else {
log.WithError(errors.WithStack(err)).Errorf("Error running command=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
return c.fail(req, fmt.Sprintf("error running restic backup, stderr=%s: %s", stderr, err.Error()), log)
}
}
log.Debugf("Ran command=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
snapshotID, err := restic.GetSnapshotID(req.Spec.RepoIdentifier, file, req.Spec.Tags, env)
if err != nil {
log.WithError(err).Error("Error getting SnapshotID")
return c.fail(req, errors.Wrap(err, "error getting snapshot id").Error(), log)
var snapshotID string
if !emptySnapshot {
snapshotID, err = restic.GetSnapshotID(req.Spec.RepoIdentifier, file, req.Spec.Tags, env)
if err != nil {
log.WithError(err).Error("Error getting SnapshotID")
return c.fail(req, errors.Wrap(err, "error getting snapshot id").Error(), log)
}
}
// update status to Completed with path & snapshot id
req, err = c.patchPodVolumeBackup(req, func(r *velerov1api.PodVolumeBackup) {
r.Status.Path = path
r.Status.SnapshotID = snapshotID
r.Status.Phase = velerov1api.PodVolumeBackupPhaseCompleted
r.Status.SnapshotID = snapshotID
if emptySnapshot {
r.Status.Message = "volume was empty so no snapshot was taken"
}
})
if err != nil {
log.WithError(err).Error("Error setting phase to Completed")

View File

@ -168,6 +168,10 @@ ForEachVolume:
case res := <-resultsChan:
switch res.Status.Phase {
case velerov1api.PodVolumeBackupPhaseCompleted:
if res.Status.SnapshotID == "" { // when the volume is empty there is no restic snapshot, so best to exclude it
delete(volumeSnapshots, res.Spec.Volume)
break
}
volumeSnapshots[res.Spec.Volume] = res.Status.SnapshotID
case velerov1api.PodVolumeBackupPhaseFailed:
errs = append(errs, errors.Errorf("pod volume backup failed: %s", res.Status.Message))