Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non admin status comparison against empty structure #131

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading