Skip to content

Commit

Permalink
Merge pull request #9 from vshn/add-stored-print-column
Browse files Browse the repository at this point in the history
Add stored time to table
  • Loading branch information
zugao authored Mar 10, 2023
2 parents efe2777 + ffefeb8 commit e2a4b10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions apis/appcat/v1/vshn_postgres_backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ var (
Process = "process"
// BackupInformation holds field path name backupInformation
BackupInformation = "backupInformation"
// DatabaseInstance holds field path name databaseInstance
DatabaseInstance = "databaseInstance"
// InstanceNamespace holds field path name instanceNamespace
InstanceNamespace = "instanceNamespace"
// Timing holds field path name timing
Timing = "timing"
// Stored holds field path name stored
Stored = "stored"
)

// VSHNPostgreSQLName represents the name of a VSHNPostgreSQL
Expand Down
13 changes: 13 additions & 0 deletions apiserver/vshn/postgres/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (v *vshnPostgresBackupStorage) ConvertToTable(_ context.Context, obj runtim
table.ColumnDefinitions = []metav1.TableColumnDefinition{
{Name: "Backup Name", Type: "string", Format: "name", Description: desc["name"]},
{Name: "Database Instance", Type: "string", Description: "The database instance"},
{Name: "Stored Time", Type: "string", Description: "When backup is stored"},
{Name: "Status", Type: "string", Description: "The state of this backup"},
{Name: "Age", Type: "date", Description: desc["creationTimestamp"]},
}
Expand All @@ -55,12 +56,24 @@ func backupToTableRow(backup *v1.VSHNPostgresBackup) metav1.TableRow {
Cells: []interface{}{
backup.GetName(),
backup.Status.DatabaseInstance,
getStoredTime(backup.Status.Process),
getProcessStatus(backup.Status.Process),
duration.HumanDuration(time.Since(backup.GetCreationTimestamp().Time))},
Object: runtime.RawExtension{Object: backup},
}
}

func getStoredTime(process runtime.RawExtension) string {
if process.Object != nil {
if v, err := runtime.DefaultUnstructuredConverter.ToUnstructured(process.Object); err == nil {
if storedTime, exists, _ := unstructured.NestedString(v, v1.Timing, v1.Stored); exists {
return storedTime
}
}
}
return ""
}

func getProcessStatus(process runtime.RawExtension) string {
if process.Object != nil {
unstructuredProcess, err := runtime.DefaultUnstructuredConverter.ToUnstructured(process.Object)
Expand Down

0 comments on commit e2a4b10

Please sign in to comment.