diff --git a/kotsadm/pkg/snapshot/backup.go b/kotsadm/pkg/snapshot/backup.go index 54695616e8..7a48a61a41 100644 --- a/kotsadm/pkg/snapshot/backup.go +++ b/kotsadm/pkg/snapshot/backup.go @@ -275,14 +275,15 @@ func ListBackupsForApp(appID string) ([]*types.Backup, error) { if backup.Status != "New" && backup.Status != "InProgress" { if !volumeBytesOk || !volumeSuccessCountOk { // save computed summary as annotations if snapshot is finished - vc, vsc, vb, err := getSnapshotVolumeSummary(&veleroBackup) + volumeSummary, err := getSnapshotVolumeSummary(&veleroBackup) if err != nil { return nil, errors.Wrap(err, "failed to get volume summary") } - backup.VolumeCount = vc - backup.VolumeSuccessCount = vsc - backup.VolumeBytes = vb + backup.VolumeCount = volumeSummary.VolumeCount + backup.VolumeSuccessCount = volumeSummary.VolumeSuccessCount + backup.VolumeBytes = volumeSummary.VolumeBytes + backup.VolumeSizeHuman = volumeSummary.VolumeSizeHuman // This is failing with "the server could not find the requested resource (put backups.velero.io scheduled-1586536961)" // veleroBackup.Annotations["kots.io/snapshot-volume-count"] = strconv.Itoa(backup.VolumeCount) @@ -385,14 +386,15 @@ func ListKotsadmBackups() ([]*types.Backup, error) { if backup.Status != "New" && backup.Status != "InProgress" { if !volumeBytesOk || !volumeSuccessCountOk { // save computed summary as annotations if snapshot is finished - vc, vsc, vb, err := getSnapshotVolumeSummary(&veleroBackup) + volumeSummary, err := getSnapshotVolumeSummary(&veleroBackup) if err != nil { return nil, errors.Wrap(err, "failed to get volume summary") } - backup.VolumeCount = vc - backup.VolumeSuccessCount = vsc - backup.VolumeBytes = vb + backup.VolumeCount = volumeSummary.VolumeCount + backup.VolumeSuccessCount = volumeSummary.VolumeSuccessCount + backup.VolumeBytes = volumeSummary.VolumeBytes + backup.VolumeSizeHuman = volumeSummary.VolumeSizeHuman } } @@ -402,22 +404,22 @@ func ListKotsadmBackups() ([]*types.Backup, error) { return backups, nil } -func getSnapshotVolumeSummary(veleroBackup *velerov1.Backup) (int, int, int64, error) { +func getSnapshotVolumeSummary(veleroBackup *velerov1.Backup) (*types.VolumeSummary, error) { cfg, err := config.GetConfig() if err != nil { - return 0, 0, int64(0), errors.Wrap(err, "failed to get cluster config") + return nil, errors.Wrap(err, "failed to get cluster config") } veleroClient, err := veleroclientv1.NewForConfig(cfg) if err != nil { - return 0, 0, int64(0), errors.Wrap(err, "failed to create clientset") + return nil, errors.Wrap(err, "failed to create clientset") } veleroPodBackupVolumes, err := veleroClient.PodVolumeBackups(veleroBackup.Namespace).List(context.TODO(), metav1.ListOptions{ LabelSelector: fmt.Sprintf("velero.io/backup-name=%s", velerolabel.GetValidName(veleroBackup.Name)), }) if err != nil { - return 0, 0, int64(0), errors.Wrap(err, "failed to list pod back up volumes") + return nil, errors.Wrap(err, "failed to list pod back up volumes") } count := 0 @@ -433,8 +435,14 @@ func getSnapshotVolumeSummary(veleroBackup *velerov1.Backup) (int, int, int64, e totalBytes += veleroPodBackupVolume.Status.Progress.BytesDone } - return count, success, totalBytes, nil + volumeSummary := types.VolumeSummary{ + VolumeCount: count, + VolumeSuccessCount: success, + VolumeBytes: totalBytes, + VolumeSizeHuman: units.HumanSize(float64(totalBytes)), + } + return &volumeSummary, nil } // this is a copy from registry. so many import cycles to unwind here, todo diff --git a/kotsadm/pkg/snapshot/store.go b/kotsadm/pkg/snapshot/store.go index 43b197297d..6c9af3688b 100644 --- a/kotsadm/pkg/snapshot/store.go +++ b/kotsadm/pkg/snapshot/store.go @@ -153,15 +153,15 @@ func UpdateGlobalStore(store *types.Store) (*velerov1.BackupStorageLocation, err } else if store.Other != nil { kotsadmVeleroBackendStorageLocation.Spec.Config = map[string]string{ "region": store.Other.Region, - "s3Url": store.Other.Endpoint, + "s3Url": store.Other.Endpoint, } // create or update the secret } else if store.Internal != nil { kotsadmVeleroBackendStorageLocation.Spec.Config = map[string]string{ - "region": store.Internal.Region, - "s3Url": store.Internal.Endpoint, - "publicUrl": fmt.Sprintf("http://%s", store.Internal.ObjectStoreClusterIP), + "region": store.Internal.Region, + "s3Url": store.Internal.Endpoint, + "publicUrl": fmt.Sprintf("http://%s", store.Internal.ObjectStoreClusterIP), "s3ForcePathStyle": "true", } diff --git a/kotsadm/pkg/snapshot/types/types.go b/kotsadm/pkg/snapshot/types/types.go index 7659f3d835..bc81f38cf2 100644 --- a/kotsadm/pkg/snapshot/types/types.go +++ b/kotsadm/pkg/snapshot/types/types.go @@ -109,3 +109,10 @@ type SnapshotError struct { Message string `json:"message"` Namespace string `json:"namespace"` } + +type VolumeSummary struct { + VolumeCount int `json:"volumeCount"` + VolumeSuccessCount int `json:"volumeSuccessCount"` + VolumeBytes int64 `json:"volumeBytes"` + VolumeSizeHuman string `json:"volumeSizeHuman"` +} diff --git a/kotsadm/web/src/components/apps/AppSnapshotRow.jsx b/kotsadm/web/src/components/apps/AppSnapshotRow.jsx index 198fff552b..c19a5ef2de 100644 --- a/kotsadm/web/src/components/apps/AppSnapshotRow.jsx +++ b/kotsadm/web/src/components/apps/AppSnapshotRow.jsx @@ -43,7 +43,7 @@ class AppShanpshotRow extends React.Component {

Volumes included: {snapshot?.volumeSuccessCount}/{snapshot?.volumeCount}

-

Backup size: {Utilities.bytesToSize(snapshot?.volumeBytes)}

+

Backup size: {snapshot?.volumeSizeHuman}