Skip to content

Commit

Permalink
Added checks for shoot generation before restore
Browse files Browse the repository at this point in the history
  • Loading branch information
akgalwas committed Jan 2, 2025
1 parent 4eff7bb commit 3f991d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
16 changes: 15 additions & 1 deletion hack/runtime-migrator/cmd/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ func (r Restore) Do(ctx context.Context, runtimeIDs []string) error {
continue
}

if currentShoot.Generation == objectsToRestore.OriginalShoot.Generation {
slog.Warn("Verify the current state of the system. Shoot was not modified after backup was prepared. Skipping.", "runtimeID", runtimeID)
r.results.OperationSkipped(runtimeID, currentShoot.Name)

continue
}

if currentShoot.Generation > objectsToRestore.OriginalShoot.Generation+1 {
slog.Warn("Verify the current state of the system. Restore should be performed manually, as the backup may overwrite more that on change.", "runtimeID", runtimeID)
r.results.AutomaticRestoreImpossible(runtimeID, currentShoot.Name)

continue
}

if r.cfg.IsDryRun {
slog.Info("Runtime processed successfully (dry-run)", "runtimeID", runtimeID)
r.results.OperationSucceeded(runtimeID, currentShoot.Name)
Expand All @@ -112,7 +126,7 @@ func (r Restore) Do(ctx context.Context, runtimeIDs []string) error {
return err
}

slog.Info(fmt.Sprintf("Restore completed. Successfully restored backups: %d, Failed operations: %d", r.results.Succeeded, r.results.Failed))
slog.Info(fmt.Sprintf("Restore completed. Successfully restored backups: %d, Failed operations: %d, Skipped backups: %d, ", r.results.Succeeded, r.results.Failed, r.results.Skipped))
slog.Info(fmt.Sprintf("Restore results saved in: %s", resultsFile))

return nil
Expand Down
30 changes: 28 additions & 2 deletions hack/runtime-migrator/internal/restore/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package restore
type StatusType string

const (
StatusSuccess StatusType = "Success"
StatusError StatusType = "Error"
StatusSuccess StatusType = "Success"
StatusError StatusType = "Error"
StatusRestoreSkipped = "Skipped"
StatusUpdateDetected = "UpdateDetected"
)

type RuntimeResult struct {
Expand All @@ -18,6 +20,8 @@ type Results struct {
Results []RuntimeResult
Succeeded int
Failed int
Skipped int
UpdateDetected int
OutputDirectory string
}

Expand Down Expand Up @@ -50,3 +54,25 @@ func (br *Results) OperationSucceeded(runtimeID string, shootName string) {
br.Succeeded++
br.Results = append(br.Results, result)
}

func (br *Results) OperationSkipped(runtimeID string, shootName string) {
result := RuntimeResult{
RuntimeID: runtimeID,
ShootName: shootName,
Status: StatusRestoreSkipped,
}

br.Skipped++
br.Results = append(br.Results, result)
}

func (br *Results) AutomaticRestoreImpossible(runtimeID string, shootName string) {
result := RuntimeResult{
RuntimeID: runtimeID,
ShootName: shootName,
Status: StatusUpdateDetected,
}

br.UpdateDetected++
br.Results = append(br.Results, result)
}

0 comments on commit 3f991d1

Please sign in to comment.