Skip to content

Commit

Permalink
Non admin status comparison against empty structure (#131)
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Pryc <[email protected]>
  • Loading branch information
mpryc authored Dec 10, 2024
1 parent ade1058 commit 06cf4a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
30 changes: 22 additions & 8 deletions internal/controller/nonadminbackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,21 @@ func updateNonAdminBackupVeleroBackupStatus(status *nacv1alpha1.NonAdminBackupSt
if status == nil || veleroBackup == nil {
return false
}

if status.VeleroBackup == nil {
status.VeleroBackup = &nacv1alpha1.VeleroBackup{}
}
if status.VeleroBackup.Status == nil || !reflect.DeepEqual(status.VeleroBackup.Status, veleroBackup.Status) {
status.VeleroBackup.Status = veleroBackup.Status.DeepCopy()
return true

if status.VeleroBackup.Status == nil {
status.VeleroBackup.Status = &velerov1.BackupStatus{}
}
return false

if reflect.DeepEqual(*status.VeleroBackup.Status, veleroBackup.Status) {
return false
}

status.VeleroBackup.Status = veleroBackup.Status.DeepCopy()
return true
}

// updateNonAdminBackupDeleteBackupRequestStatus sets the VeleroDeleteBackupRequest status field in NonAdminBackup object status and returns true
Expand All @@ -739,12 +746,19 @@ func updateNonAdminBackupDeleteBackupRequestStatus(status *nacv1alpha1.NonAdminB
if status == nil || veleroDeleteBackupRequest == nil {
return false
}

if status.VeleroDeleteBackupRequest == nil {
status.VeleroDeleteBackupRequest = &nacv1alpha1.VeleroDeleteBackupRequest{}
}
if status.VeleroDeleteBackupRequest.Status == nil || !reflect.DeepEqual(status.VeleroDeleteBackupRequest.Status, veleroDeleteBackupRequest.Status) {
status.VeleroDeleteBackupRequest.Status = veleroDeleteBackupRequest.Status.DeepCopy()
return true

if status.VeleroDeleteBackupRequest.Status == nil {
status.VeleroDeleteBackupRequest.Status = &velerov1.DeleteBackupRequestStatus{}
}
return false

if reflect.DeepEqual(*status.VeleroDeleteBackupRequest.Status, veleroDeleteBackupRequest.Status) {
return false
}

status.VeleroDeleteBackupRequest.Status = veleroDeleteBackupRequest.Status.DeepCopy()
return true
}
15 changes: 11 additions & 4 deletions internal/controller/nonadminrestore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ func (r *NonAdminRestoreReconciler) createVeleroRestore(ctx context.Context, log
return false, nil
}

// updateVeleroRestoreStatus sets the VeleroRestore status field in NonAdminRestore object status and returns true
// if the VeleroRestore fields are changed by this call.
func updateVeleroRestoreStatus(status *nacv1alpha1.NonAdminRestoreStatus, veleroRestore *velerov1.Restore) bool {
if status == nil || veleroRestore == nil {
return false
Expand All @@ -413,11 +415,16 @@ func updateVeleroRestoreStatus(status *nacv1alpha1.NonAdminRestoreStatus, velero
status.VeleroRestore = &nacv1alpha1.VeleroRestore{}
}

if status.VeleroRestore.Status == nil || !reflect.DeepEqual(status.VeleroRestore.Status, veleroRestore.Status) {
status.VeleroRestore.Status = veleroRestore.Status.DeepCopy()
return true
if status.VeleroRestore.Status == nil {
status.VeleroRestore.Status = &velerov1.RestoreStatus{}
}
return false

if reflect.DeepEqual(*status.VeleroRestore.Status, veleroRestore.Status) {
return false
}

status.VeleroRestore.Status = veleroRestore.Status.DeepCopy()
return true
}

// SetupWithManager sets up the controller with the Manager.
Expand Down

0 comments on commit 06cf4a2

Please sign in to comment.