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

Volume size human on backup list - fix #806

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 21 additions & 13 deletions kotsadm/pkg/snapshot/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions kotsadm/pkg/snapshot/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
7 changes: 7 additions & 0 deletions kotsadm/pkg/snapshot/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 1 addition & 1 deletion kotsadm/web/src/components/apps/AppSnapshotRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AppShanpshotRow extends React.Component {
<div className="flex flex-auto alignItems--center u-marginTop--5">
<div className="flex flex1 alignItems--center">
<p className="u-fontSize--normal u-color--doveGray u-fontWeight--bold u-lineHeight--normal u-marginRight--20"><span className="u-fontWeight--normal u-color--dustyGray">Volumes included:</span> {snapshot?.volumeSuccessCount}/{snapshot?.volumeCount}</p>
<p className="u-fontSize--normal u-color--doveGray u-fontWeight--bold u-lineHeight--normal u-marginRight--20"><span className="u-fontWeight--normal u-color--dustyGray">Backup size:</span> {Utilities.bytesToSize(snapshot?.volumeBytes)} </p>
<p className="u-fontSize--normal u-color--doveGray u-fontWeight--bold u-lineHeight--normal u-marginRight--20"><span className="u-fontWeight--normal u-color--dustyGray">Backup size:</span> {snapshot?.volumeSizeHuman} </p>
</div>
</div>
</div>
Expand Down