diff --git a/controllers/helpers.go b/controllers/helpers.go index 6fa6ff6932..e8b76e81bd 100644 --- a/controllers/helpers.go +++ b/controllers/helpers.go @@ -504,9 +504,11 @@ func deleteCategoryKeyValues(ctx context.Context, client *prismclientv3.Client, err = client.V3.DeleteCategoryValue(ctx, key, value) if err != nil { - errorMsg := fmt.Errorf("failed to delete category with key %s. error: %v", key, err) - log.Error(errorMsg, "failed to delete category") - return errorMsg + errorMsg := fmt.Errorf("failed to delete category value with key:value %s:%s. error: %v", key, value, err) + log.Error(errorMsg, "failed to delete category value") + // NCN-101935: If the category value still has VMs assigned, do not delete the category key:value + // TODO:deepakmntnx Add a check for specific error mentioned in NCN-101935 + return nil } } diff --git a/test/e2e/categories_test.go b/test/e2e/categories_test.go index 08989c8f8a..0ff9349947 100644 --- a/test/e2e/categories_test.go +++ b/test/e2e/categories_test.go @@ -20,6 +20,7 @@ package e2e import ( "context" + "os" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -174,4 +175,83 @@ var _ = Describe("Nutanix categories", Label("capx-feature-test", "categories"), By("PASSED!") }) + + It("Create and delete 2 clusters with same name with default cluster categories and should succeed", Label("same-name-two-cluster-test"), func() { + Expect(namespace).NotTo(BeNil()) + flavor := clusterctl.DefaultFlavor + expectedClusterNameCategoryKey := infrav1.DefaultCAPICategoryKeyForName + By("Creating a workload cluster 1", func() { + testHelper.deployClusterAndWait( + deployClusterParams{ + clusterName: clusterName, + namespace: namespace, + flavor: flavor, + clusterctlConfigPath: clusterctlConfigPath, + artifactFolder: artifactFolder, + bootstrapClusterProxy: bootstrapClusterProxy, + }, clusterResources) + }) + + By("Checking cluster category condition is true", func() { + testHelper.verifyConditionOnNutanixCluster(verifyConditionParams{ + clusterName: clusterName, + namespace: namespace, + bootstrapClusterProxy: bootstrapClusterProxy, + expectedCondition: clusterv1.Condition{ + Type: infrav1.ClusterCategoryCreatedCondition, + Status: corev1.ConditionTrue, + }, + }) + }) + + By("Checking if a category was created", func() { + testHelper.verifyCategoryExists(ctx, expectedClusterNameCategoryKey, clusterName) + }) + + By("Checking if there are VMs assigned to this category", func() { + expectedCategories := map[string]string{ + expectedClusterNameCategoryKey: clusterName, + } + testHelper.verifyCategoriesNutanixMachines(ctx, clusterName, namespace.Name, expectedCategories) + }) + + os.Setenv("CONTROL_PLANE_ENDPOINT_IP", os.Getenv("CONTROL_PLANE_ENDPOINT_IP_2")) + By("Creating a workload cluster 2 with same name", func() { + testHelper.deployClusterAndWait( + deployClusterParams{ + clusterName: clusterName, + namespace: namespace, + flavor: flavor, + clusterctlConfigPath: clusterctlConfigPath, + artifactFolder: artifactFolder, + bootstrapClusterProxy: bootstrapClusterProxy, + }, clusterResources) + }) + + By("Checking cluster category condition is true", func() { + testHelper.verifyConditionOnNutanixCluster(verifyConditionParams{ + clusterName: clusterName, + namespace: namespace, + bootstrapClusterProxy: bootstrapClusterProxy, + expectedCondition: clusterv1.Condition{ + Type: infrav1.ClusterCategoryCreatedCondition, + Status: corev1.ConditionTrue, + }, + }) + }) + + By("Checking if a category was created", func() { + testHelper.verifyCategoryExists(ctx, expectedClusterNameCategoryKey, clusterName) + }) + + By("Checking if there are VMs assigned to this category", func() { + expectedCategories := map[string]string{ + expectedClusterNameCategoryKey: clusterName, + } + testHelper.verifyCategoriesNutanixMachines(ctx, clusterName, namespace.Name, expectedCategories) + }) + + // After each test, cluster with name clusterName will be deleted and if it fails due to categories + // issue then we will know since the test will fail. + }) })