mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-20 06:54:32 +00:00
use pointer types for metav1.Time fields (#1951)
* use pointer types for metav1.Time fields Signed-off-by: Adnan Abdulhussein <aadnan@vmware.com> * simpler metav1.Time ptrs Signed-off-by: Adnan Abdulhussein <aadnan@vmware.com> * remove test debug println Signed-off-by: Adnan Abdulhussein <aadnan@vmware.com>
This commit is contained in:
committed by
Steve Kriss
parent
3fc4097231
commit
e3d64d9dd9
@@ -219,19 +219,22 @@ func DescribeBackupStatus(d *Describer, backup *velerov1api.Backup, details bool
|
||||
|
||||
d.Println()
|
||||
// "<n/a>" output should only be applicable for backups that failed validation
|
||||
if status.StartTimestamp.Time.IsZero() {
|
||||
if status.StartTimestamp == nil || status.StartTimestamp.Time.IsZero() {
|
||||
d.Printf("Started:\t%s\n", "<n/a>")
|
||||
} else {
|
||||
d.Printf("Started:\t%s\n", status.StartTimestamp.Time)
|
||||
}
|
||||
if status.CompletionTimestamp.Time.IsZero() {
|
||||
if status.CompletionTimestamp == nil || status.CompletionTimestamp.Time.IsZero() {
|
||||
d.Printf("Completed:\t%s\n", "<n/a>")
|
||||
} else {
|
||||
d.Printf("Completed:\t%s\n", status.CompletionTimestamp.Time)
|
||||
}
|
||||
|
||||
d.Println()
|
||||
d.Printf("Expiration:\t%s\n", status.Expiration.Time)
|
||||
// Expiration can't be 0, it is always set to a 30-day default. It can be nil
|
||||
// if the controller hasn't processed this Backup yet, in which case this will
|
||||
// just display `<nil>`, though this should be temporary.
|
||||
d.Printf("Expiration:\t%s\n", status.Expiration)
|
||||
d.Println()
|
||||
|
||||
if details {
|
||||
|
||||
@@ -88,7 +88,10 @@ func printBackup(backup *velerov1api.Backup, options printers.PrintOptions) ([]m
|
||||
Object: runtime.RawExtension{Object: backup},
|
||||
}
|
||||
|
||||
expiration := backup.Status.Expiration.Time
|
||||
var expiration time.Time
|
||||
if backup.Status.Expiration != nil {
|
||||
expiration = backup.Status.Expiration.Time
|
||||
}
|
||||
if expiration.IsZero() && backup.Spec.TTL.Duration > 0 {
|
||||
expiration = backup.CreationTimestamp.Add(backup.Spec.TTL.Duration)
|
||||
}
|
||||
@@ -111,7 +114,7 @@ func printBackup(backup *velerov1api.Backup, options printers.PrintOptions) ([]m
|
||||
|
||||
location := backup.Spec.StorageLocation
|
||||
|
||||
row.Cells = append(row.Cells, backup.Name, status, backup.Status.StartTimestamp.Time, humanReadableTimeFromNow(expiration), location, metav1.FormatLabelSelector(backup.Spec.LabelSelector))
|
||||
row.Cells = append(row.Cells, backup.Name, status, backup.Status.StartTimestamp, humanReadableTimeFromNow(expiration), location, metav1.FormatLabelSelector(backup.Spec.LabelSelector))
|
||||
|
||||
return []metav1.TableRow{row}, nil
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func DescribeScheduleSpec(d *Describer, spec v1.ScheduleSpec) {
|
||||
|
||||
func DescribeScheduleStatus(d *Describer, status v1.ScheduleStatus) {
|
||||
lastBackup := "<never>"
|
||||
if !status.LastBackup.Time.IsZero() {
|
||||
if status.LastBackup != nil && !status.LastBackup.Time.IsZero() {
|
||||
lastBackup = fmt.Sprintf("%v", status.LastBackup.Time)
|
||||
}
|
||||
d.Printf("Last Backup:\t%s\n", lastBackup)
|
||||
|
||||
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package output
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/printers"
|
||||
@@ -61,13 +63,18 @@ func printSchedule(schedule *v1.Schedule, options printers.PrintOptions) ([]meta
|
||||
status = v1.SchedulePhaseNew
|
||||
}
|
||||
|
||||
var lastBackupTime time.Time
|
||||
if schedule.Status.LastBackup != nil {
|
||||
lastBackupTime = schedule.Status.LastBackup.Time
|
||||
}
|
||||
|
||||
row.Cells = append(row.Cells,
|
||||
schedule.Name,
|
||||
status,
|
||||
schedule.CreationTimestamp.Time,
|
||||
schedule.Spec.Schedule,
|
||||
schedule.Spec.Template.TTL.Duration,
|
||||
humanReadableTimeFromNow(schedule.Status.LastBackup.Time),
|
||||
humanReadableTimeFromNow(lastBackupTime),
|
||||
metav1.FormatLabelSelector(schedule.Spec.Template.LabelSelector),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user