-
Notifications
You must be signed in to change notification settings - Fork 88
/
backup.go
40 lines (32 loc) · 1.1 KB
/
backup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package print
import (
"fmt"
"time"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)
func Backups(backups []velerov1.Backup) {
w := NewTabWriter()
defer w.Flush()
fmtColumns := "%s\t%s\t%s\t%s\t%s\t%s\t%s\n"
fmt.Fprintf(w, fmtColumns, "NAME", "STATUS", "ERRORS", "WARNINGS", "STARTED", "COMPLETED", "EXPIRES")
for _, b := range backups {
expiresAt := ""
if b.Status.Expiration != nil {
expiresAtDuration := b.Status.Expiration.Time.Sub(time.Now())
expiresAt = fmt.Sprintf("%dd", uint64(expiresAtDuration.Hours()/24))
}
var startedAt *time.Time
if b.Status.StartTimestamp != nil && !b.Status.StartTimestamp.Time.IsZero() {
startedAt = &b.Status.StartTimestamp.Time
}
var completedAt *time.Time
if b.Status.CompletionTimestamp != nil && !b.Status.CompletionTimestamp.Time.IsZero() {
completedAt = &b.Status.CompletionTimestamp.Time
}
phase := b.Status.Phase
if phase == "" {
phase = "New"
}
fmt.Fprintf(w, fmtColumns, b.ObjectMeta.Name, phase, fmt.Sprintf("%d", b.Status.Errors), fmt.Sprintf("%d", b.Status.Warnings), startedAt, completedAt, expiresAt)
}
}