From ea0c59e4a94dedc585c209cb2238235fc48448c9 Mon Sep 17 00:00:00 2001 From: Ashish Pandey Date: Tue, 3 Dec 2024 13:03:01 +0530 Subject: [PATCH] Noobaa/Operator: Display error message While deleting OBC or Bucketclass which does not exist, we should display an error message and should not silently give success. Signed-off-by: Ashish Pandey (cherry picked from commit 553c49674a0e20b2fb566915278a5b2ab4009ea2) --- pkg/bucketclass/bucketclass.go | 5 +++++ pkg/obc/obc.go | 6 +++++- test/cli/test_cli_functions.sh | 4 +--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/bucketclass/bucketclass.go b/pkg/bucketclass/bucketclass.go index 33b0e4cf23..89fe13b16a 100644 --- a/pkg/bucketclass/bucketclass.go +++ b/pkg/bucketclass/bucketclass.go @@ -425,6 +425,11 @@ func RunDelete(cmd *cobra.Command, args []string) { bucketClass.Name = args[0] bucketClass.Namespace = options.Namespace + if !util.KubeCheck(bucketClass) { + log.Fatalf(`❌ Could not delete, BucketClass %q in namespace %q does not exist`, + bucketClass.Name, bucketClass.Namespace) + } + if !util.KubeDelete(bucketClass) { log.Fatalf(`❌ Could not delete BucketClass %q in namespace %q`, bucketClass.Name, bucketClass.Namespace) diff --git a/pkg/obc/obc.go b/pkg/obc/obc.go index f528e26f0e..aa28190997 100644 --- a/pkg/obc/obc.go +++ b/pkg/obc/obc.go @@ -147,7 +147,7 @@ func RunCreate(cmd *cobra.Command, args []string) { log.Fatalf(`❌ NSFS account config must include both UID and GID as positive integers`) } - if bucketClassName == "" && ( gid > -1 || uid > -1 || distinguishedName != "" ) { + if bucketClassName == "" && (gid > -1 || uid > -1 || distinguishedName != "") { log.Fatalf(`❌ NSFS account config cannot be set without an NSFS bucketclass`) } @@ -331,6 +331,10 @@ func RunDelete(cmd *cobra.Command, args []string) { obc.Name = args[0] obc.Namespace = appNamespace + if !util.KubeCheck(obc) { + log.Fatalf(`❌ Could not delete. OBC %q in namespace %q does not exist`, obc.Name, obc.Namespace) + } + if !util.KubeDelete(obc) { log.Fatalf(`❌ Could not delete OBC %q in namespace %q`, obc.Name, obc.Namespace) diff --git a/test/cli/test_cli_functions.sh b/test/cli/test_cli_functions.sh index ea982a780e..953c89c738 100644 --- a/test/cli/test_cli_functions.sh +++ b/test/cli/test_cli_functions.sh @@ -965,13 +965,11 @@ function delete_backingstore_path { function delete_namespacestore_path { local object_bucket namespace_store - test_noobaa obc delete ${obc[2]} - test_noobaa bucketclass delete ${bucketclass[2]} local namespacestore=($(test_noobaa silence namespacestore list | grep -v "NAME" | awk '{print $1}')) local bucketclass=($(test_noobaa silence bucketclass list | grep -v "NAME" | awk '{print $1}')) local obc=() local all_obc=($(test_noobaa silence obc list | grep -v "BUCKET-NAME" | awk '{print $2":"$5}')) - + # get obcs that their bucketclass is in bucketclass array for object_bucket in ${all_obc[@]} do