Skip to content

Commit

Permalink
Merge pull request #14 from vshn/fix-backup-info
Browse files Browse the repository at this point in the history
Fix null value fields in vshn postgres backup
  • Loading branch information
zugao authored Mar 23, 2023
2 parents 93a83f4 + 07fc136 commit 399ed3c
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 97 deletions.
147 changes: 81 additions & 66 deletions apis/appcat/v1/generated.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions apis/appcat/v1/vshn_postgres_backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type VSHNPostgresBackup struct {
// VSHNPostgresBackupStatus defines the desired state of VSHNPostgresBackup
type VSHNPostgresBackupStatus struct {
// Process holds status information of the backup process
Process runtime.RawExtension `json:"process,omitempty"`
Process *runtime.RawExtension `json:"process,omitempty"`
// BackupInformation holds specific backup information
BackupInformation runtime.RawExtension `json:"backupInformation,omitempty"`
BackupInformation *runtime.RawExtension `json:"backupInformation,omitempty"`
// DatabaseInstance is the database from which the backup has been done
DatabaseInstance string `json:"databaseInstance"`
}
Expand Down Expand Up @@ -125,18 +125,18 @@ func NewVSHNPostgresBackup(backup *SGBackupInfo, db, originalNamespace string) *

vshnPostgresBackup := &VSHNPostgresBackup{
ObjectMeta: backup.ObjectMeta,
Status: VSHNPostgresBackupStatus{},
}

vshnPostgresBackup.Status.DatabaseInstance = db
vshnPostgresBackup.Namespace = originalNamespace

if backup.Process.Object != nil {
vshnPostgresBackup.Status.Process = backup.Process
vshnPostgresBackup.Status.Process = &backup.Process
}

if backup.BackupInformation.Object != nil {
vshnPostgresBackup.Status.BackupInformation = backup.BackupInformation
vshnPostgresBackup.Status.BackupInformation = &backup.BackupInformation
}

return vshnPostgresBackup
}
26 changes: 10 additions & 16 deletions apis/appcat/v1/vshn_postgres_backup_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json"
"testing"
)

Expand All @@ -23,16 +22,16 @@ func TestNewVSHNBackupFromBackInfo(t *testing.T) {
"GivenNoDB_ThenNil": {
backupInfo: &SGBackupInfo{
ObjectMeta: metav1.ObjectMeta{Name: "backup"},
Process: rawFromObject(getTestProcess()),
BackupInformation: rawFromObject(getTestBI()),
Process: *rawFromObject(getTestProcess()),
BackupInformation: *rawFromObject(getTestBI()),
},
namespace: "namespace",
},
"GivenNoNamespace_ThenNil": {
backupInfo: &SGBackupInfo{
ObjectMeta: metav1.ObjectMeta{Name: "backup"},
Process: rawFromObject(getTestProcess()),
BackupInformation: rawFromObject(getTestBI()),
Process: *rawFromObject(getTestProcess()),
BackupInformation: *rawFromObject(getTestBI()),
},
db: "db1",
},
Expand All @@ -41,8 +40,8 @@ func TestNewVSHNBackupFromBackInfo(t *testing.T) {
namespace: "namespace",
backupInfo: &SGBackupInfo{
ObjectMeta: metav1.ObjectMeta{Name: "backup"},
Process: rawFromObject(getTestProcess()),
BackupInformation: rawFromObject(getTestBI()),
Process: *rawFromObject(getTestProcess()),
BackupInformation: *rawFromObject(getTestBI()),
},
vshnPostgresBackup: &VSHNPostgresBackup{
ObjectMeta: metav1.ObjectMeta{Name: "backup", Namespace: "namespace"},
Expand All @@ -58,7 +57,7 @@ func TestNewVSHNBackupFromBackInfo(t *testing.T) {
namespace: "namespace",
backupInfo: &SGBackupInfo{
ObjectMeta: metav1.ObjectMeta{Name: "backup"},
BackupInformation: rawFromObject(getTestBI()),
BackupInformation: *rawFromObject(getTestBI()),
},
vshnPostgresBackup: &VSHNPostgresBackup{
ObjectMeta: metav1.ObjectMeta{Name: "backup", Namespace: "namespace"},
Expand All @@ -73,7 +72,7 @@ func TestNewVSHNBackupFromBackInfo(t *testing.T) {
namespace: "namespace",
backupInfo: &SGBackupInfo{
ObjectMeta: metav1.ObjectMeta{Name: "backup"},
Process: rawFromObject(getTestProcess()),
Process: *rawFromObject(getTestProcess()),
},
vshnPostgresBackup: &VSHNPostgresBackup{
ObjectMeta: metav1.ObjectMeta{Name: "backup", Namespace: "namespace"},
Expand Down Expand Up @@ -109,11 +108,6 @@ func getTestBI() unstructured.Unstructured {
}
}

func rawFromObject(object unstructured.Unstructured) runtime.RawExtension {
return runtime.RawExtension{Object: &object}
}

func rawFromString(str string) runtime.RawExtension {
marshal, _ := json.Marshal(str)
return runtime.RawExtension{Raw: marshal}
func rawFromObject(object unstructured.Unstructured) *runtime.RawExtension {
return &runtime.RawExtension{Object: &object}
}
12 changes: 10 additions & 2 deletions apis/appcat/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions apiserver/vshn/postgres/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var (
},
Status: v1.VSHNPostgresBackupStatus{
DatabaseInstance: "postgres-one",
Process: runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"status": "Failed"}}},
BackupInformation: runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"disk": "1GB", "cpu": "1"}}},
Process: &runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"status": "Failed"}}},
BackupInformation: &runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"disk": "1GB", "cpu": "1"}}},
},
}

Expand Down Expand Up @@ -73,8 +73,8 @@ var (
},
Status: v1.VSHNPostgresBackupStatus{
DatabaseInstance: "postgres-two",
Process: runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"status": "Completed"}}},
BackupInformation: runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"disk": "2GB", "cpu": "2"}}},
Process: &runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"status": "Completed"}}},
BackupInformation: &runtime.RawExtension{Object: &unstructured.Unstructured{Object: map[string]interface{}{"disk": "2GB", "cpu": "2"}}},
},
}

Expand Down
8 changes: 4 additions & 4 deletions apiserver/vshn/postgres/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func backupToTableRow(backup *v1.VSHNPostgresBackup) metav1.TableRow {
}
}

func getStoredTime(process runtime.RawExtension) string {
if process.Object != nil {
func getStoredTime(process *runtime.RawExtension) string {
if process != nil && 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
Expand All @@ -74,8 +74,8 @@ func getStoredTime(process runtime.RawExtension) string {
return ""
}

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

0 comments on commit 399ed3c

Please sign in to comment.