Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return information about combined backup on backup page #5087

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions pkg/handlers/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (h *Handler) ListInstanceBackups(w http.ResponseWriter, r *http.Request) {

type GetBackupResponse struct {
BackupDetails []snapshottypes.BackupDetail `json:"backupDetails"`
Backup *snapshottypes.Backup `json:"backup"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
Expand All @@ -147,6 +148,14 @@ func (h *Handler) GetBackup(w http.ResponseWriter, r *http.Request) {
}
getBackupResponse.BackupDetails = backups

thisBackup, err := snapshot.GetInstanceBackup(r.Context(), util.PodNamespace, mux.Vars(r)["snapshotName"])
if err != nil {
logger.Error(err)
getBackupResponse.Error = "failed to get backup"
JSON(w, 500, getBackupResponse)
return
}
getBackupResponse.Backup = thisBackup
getBackupResponse.Success = true

JSON(w, http.StatusOK, getBackupResponse)
Expand Down
16 changes: 16 additions & 0 deletions pkg/kotsadmsnapshot/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,22 @@ func getBackupsFromVeleroBackups(ctx context.Context, veleroBackups []velerov1.B
return backups, nil
}

// GetInstanceBackup calls ListInstanceBackups and returns the first backup with the given name.
// This is done because multiple velero backup objects are combined into a single kots backup object,
// and the easiest way to do that is to generate the entire set of kots backup objects again.
func GetInstanceBackup(ctx context.Context, namespace string, backupName string) (*types.Backup, error) {
allBackups, err := ListInstanceBackups(ctx, namespace)
if err != nil {
return nil, err
}
for _, backup := range allBackups {
if backup.Name == backupName {
return backup, nil
}
}
return nil, fmt.Errorf("no backup found with name %s", backupName)
}

// getAppsFromAppSequences returns a list of `App` structs from the backup sequence annotation.
func getAppsFromAppSequences(veleroBackup velerov1.Backup) ([]types.App, error) {
apps := []types.App{}
Expand Down
Loading