Skip to content

Commit

Permalink
rename variables #967
Browse files Browse the repository at this point in the history
Signed-off-by: u5surf <[email protected]>
  • Loading branch information
u5surf committed Oct 22, 2018
1 parent 57ce590 commit ef19497
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions pkg/controller/restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ type restoreController struct {
newBackupStore func(*api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
}

type apiRestoreResult struct {
warnings api.RestoreResult
errors api.RestoreResult
type restoreResult struct {
warnings, errors api.RestoreResult
}

func NewRestoreController(
Expand Down Expand Up @@ -236,20 +235,20 @@ func (c *restoreController) processRestore(key string) error {
log.Debug("Running restore")

// execution & upload of restore
apiRestoreResults, restoreFailure := c.runRestore(
restoreRes, restoreFailure := c.runRestore(
restore,
actions,
info,
pluginManager,
)

restore.Status.Warnings = len(apiRestoreResults.warnings.Ark) + len(apiRestoreResults.warnings.Cluster)
for _, w := range apiRestoreResults.warnings.Namespaces {
restore.Status.Warnings = len(restoreRes.warnings.Ark) + len(restoreRes.warnings.Cluster)
for _, w := range restoreRes.warnings.Namespaces {
restore.Status.Warnings += len(w)
}

restore.Status.Errors = len(apiRestoreResults.errors.Ark) + len(apiRestoreResults.errors.Cluster)
for _, e := range apiRestoreResults.errors.Namespaces {
restore.Status.Errors = len(restoreRes.errors.Ark) + len(restoreRes.errors.Cluster)
for _, e := range restoreRes.errors.Namespaces {
restore.Status.Errors += len(e)
}

Expand Down Expand Up @@ -491,7 +490,7 @@ func (c *restoreController) runRestore(
actions []restore.ItemAction,
info backupInfo,
pluginManager plugin.Manager,
) (apiRestoreResult, error) {
) (restoreResult, error) {
var restoreWarnings, restoreErrors api.RestoreResult
var restoreFailure error
logFile, err := ioutil.TempFile("", "")
Expand All @@ -506,7 +505,7 @@ func (c *restoreController) runRestore(
WithError(errors.WithStack(err)).
Error("Error creating log temp file")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
gzippedLogFile := gzip.NewWriter(logFile)
// Assuming we successfully uploaded the log file, this will have already been closed below. It is safe to call
Expand All @@ -529,7 +528,7 @@ func (c *restoreController) runRestore(
log.WithError(err).Error("Error downloading backup")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
restoreFailure = err
return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
defer closeAndRemoveFile(backupFile, c.logger)

Expand All @@ -538,7 +537,7 @@ func (c *restoreController) runRestore(
log.WithError(errors.WithStack(err)).Error("Error creating results temp file")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
restoreFailure = err
return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
defer closeAndRemoveFile(resultsFile, c.logger)

Expand All @@ -547,7 +546,7 @@ func (c *restoreController) runRestore(
log.WithError(errors.WithStack(err)).Error("Error fetching volume snapshots")
restoreErrors.Ark = append(restoreErrors.Ark, err.Error())
restoreFailure = err
return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}

// Any return statement above this line means a total restore failure
Expand All @@ -563,7 +562,7 @@ func (c *restoreController) runRestore(
// Reset the offset to 0 for reading
if _, err = logFile.Seek(0, 0); err != nil {
restoreErrors.Ark = append(restoreErrors.Ark, fmt.Sprintf("error resetting log file offset to 0: %v", err))
return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}

if err := info.backupStore.PutRestoreLog(restore.Spec.BackupName, restore.Name, logFile); err != nil {
Expand All @@ -579,19 +578,19 @@ func (c *restoreController) runRestore(

if err := json.NewEncoder(gzippedResultsFile).Encode(m); err != nil {
log.WithError(errors.WithStack(err)).Error("Error encoding restore results")
return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
gzippedResultsFile.Close()

if _, err = resultsFile.Seek(0, 0); err != nil {
log.WithError(errors.WithStack(err)).Error("Error resetting results file offset to 0")
return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}
if err := info.backupStore.PutRestoreResults(restore.Spec.BackupName, restore.Name, resultsFile); err != nil {
log.WithError(errors.WithStack(err)).Error("Error uploading results file to backup storage")
}

return apiRestoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
return restoreResult{warnings: restoreWarnings, errors: restoreErrors}, restoreFailure
}

func downloadToTempFile(
Expand Down

0 comments on commit ef19497

Please sign in to comment.