Skip to content

Commit

Permalink
Added code creating backup report
Browse files Browse the repository at this point in the history
  • Loading branch information
akgalwas committed Dec 18, 2024
1 parent 2880523 commit 8949285
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions hack/runtime-migrator/cmd/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Backup struct {
shootClient gardener_types.ShootInterface
kubeconfigProvider kubeconfig.Provider
outputWriter backup.OutputWriter
results backup.Results
cfg config.Config
}

Expand All @@ -37,6 +38,7 @@ func NewBackup(cfg config.Config, kubeconfigProvider kubeconfig.Provider, shootC
shootClient: shootClient,
kubeconfigProvider: kubeconfigProvider,
outputWriter: outputWriter,
results: backup.NewBackupResults(outputWriter.NewResultsDir),
cfg: cfg,
}, nil
}
Expand All @@ -51,24 +53,32 @@ func (b Backup) Do(ctx context.Context, runtimeIDs []string) error {
}

backuper := backup.NewBackuper(b.cfg.IsDryRun, b.kubeconfigProvider)

for _, runtimeID := range runtimeIDs {
shoot, err := b.fetchShoot(ctx, shootList, runtimeID)
if err != nil {
slog.Error(fmt.Sprintf("Failed to fetch runtime: %v", err), "runtimeID", runtimeID)
errMsg := fmt.Sprintf("Failed to fetch runtime: %v", err)
b.results.ErrorOccurred(runtimeID, shoot.Name, errMsg)
slog.Error(errMsg, "runtimeID", runtimeID)
continue
}

runtimeBackup, err := backuper.Do(ctx, *shoot)
if err != nil {
slog.Error(fmt.Sprintf("Failed to backup runtime: %v", err), "runtimeID", runtimeID)
errMsg := fmt.Sprintf("Failed to backup runtime: %v", err)
b.results.ErrorOccurred(runtimeID, shoot.Name, errMsg)
slog.Error(errMsg, "runtimeID", runtimeID)
continue
}

if !b.cfg.IsDryRun {
if err := b.outputWriter.Save(runtimeBackup); err != nil {
slog.Error(fmt.Sprintf("Failed to store backup: %v", err), "runtimeID", runtimeID)
if err := b.outputWriter.Save(runtimeID, runtimeBackup); err != nil {
errMsg := fmt.Sprintf("Failed to store backup: %v", err)
slog.Error(errMsg, "runtimeID", runtimeID)
continue
}
}
b.results.OperationSucceeded(runtimeID, shoot.Name)
}

return nil
Expand Down

0 comments on commit 8949285

Please sign in to comment.