From fc5ce6ff1bc7b85ba35c258e858d38463bf27e8e Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Mon, 21 Oct 2024 16:38:56 -0500 Subject: [PATCH] velero: adjust delete() returns --- pkg/velero/backup.go | 7 ++++++- pkg/velero/backupstoragelocation.go | 7 ++++++- pkg/velero/backupstoragelocation_test.go | 3 +-- pkg/velero/restore.go | 8 +++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/velero/backup.go b/pkg/velero/backup.go index 6096945a1..fa98f9c21 100644 --- a/pkg/velero/backup.go +++ b/pkg/velero/backup.go @@ -355,7 +355,12 @@ func (builder *BackupBuilder) Delete() (*BackupBuilder, error) { builder.Definition.Name, builder.Definition.Namespace) if !builder.Exists() { - return builder, fmt.Errorf("backup cannot be deleted because it does not exist") + glog.V(100).Infof("Backup %s in namespace %s cannot be deleted because it does not exist", + builder.Definition.Name, builder.Definition.Namespace) + + builder.Object = nil + + return builder, nil } err := builder.apiClient.Delete(context.TODO(), builder.Definition) diff --git a/pkg/velero/backupstoragelocation.go b/pkg/velero/backupstoragelocation.go index 8d3198ca5..cbaba6481 100644 --- a/pkg/velero/backupstoragelocation.go +++ b/pkg/velero/backupstoragelocation.go @@ -319,7 +319,12 @@ func (builder *BackupStorageLocationBuilder) Delete() error { builder.Definition.Name, builder.Definition.Namespace) if !builder.Exists() { - return fmt.Errorf("backupstoragelocation cannot be deleted because it does not exist") + glog.V(100).Infof("BackupStorageLocation %s in namespace %s cannot be deleted"+ + " because it does not exist", builder.Definition.Name, builder.Definition.Namespace) + + builder.Object = nil + + return nil } err := builder.apiClient.Delete(context.TODO(), builder.Definition) diff --git a/pkg/velero/backupstoragelocation_test.go b/pkg/velero/backupstoragelocation_test.go index e9197ec2d..bbcd4e153 100644 --- a/pkg/velero/backupstoragelocation_test.go +++ b/pkg/velero/backupstoragelocation_test.go @@ -1,7 +1,6 @@ package velero import ( - "errors" "fmt" "testing" "time" @@ -452,7 +451,7 @@ func TestBackupStorageLocationDelete(t *testing.T) { }, { exists: false, - expectedError: errors.New("backupstoragelocation cannot be deleted because it does not exist"), + expectedError: nil, }, } diff --git a/pkg/velero/restore.go b/pkg/velero/restore.go index be61b9a95..2faef10fe 100644 --- a/pkg/velero/restore.go +++ b/pkg/velero/restore.go @@ -235,7 +235,13 @@ func (builder *RestoreBuilder) Delete() (*RestoreBuilder, error) { builder.Definition.Name, builder.Definition.Namespace) if !builder.Exists() { - return builder, fmt.Errorf("restore cannot be deleted because it does not exist") + glog.V(100).Infof("Restore %s in namespace %s cannot be deleted"+ + " because it does not exist", + builder.Definition.Name, builder.Definition.Namespace) + + builder.Object = nil + + return builder, nil } err := builder.apiClient.Delete(context.TODO(), builder.Definition)