diff --git a/pkg/api/v1/custom_roles.go b/pkg/api/v1/custom_roles.go index 725d43c549..8bb2d1957d 100644 --- a/pkg/api/v1/custom_roles.go +++ b/pkg/api/v1/custom_roles.go @@ -2,8 +2,6 @@ package v1 import ( "go.mongodb.org/atlas/mongodbatlas" - - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr" ) type CustomRole struct { @@ -47,8 +45,8 @@ func (in *CustomRole) ToAtlas() *mongodbatlas.CustomDBRole { resources := make([]mongodbatlas.Resource, 0, len(action.Resources)) for _, resource := range action.Resources { - if resource.Cluster == nil { - resource.Cluster = toptr.MakePtr(false) + if resource.Cluster != nil && !*resource.Cluster { + resource.Cluster = nil } resources = append(resources, mongodbatlas.Resource{ Collection: resource.Collection, diff --git a/pkg/api/v1/custom_roles_test.go b/pkg/api/v1/custom_roles_test.go index 505b60091c..99bce0ef6f 100644 --- a/pkg/api/v1/custom_roles_test.go +++ b/pkg/api/v1/custom_roles_test.go @@ -76,12 +76,12 @@ func TestAtlasCustomRoles_ToAtlas(t *testing.T) { Action: "testName", Resources: []mongodbatlas.Resource{ { - Cluster: toptr.MakePtr(false), + Cluster: nil, DB: toptr.MakePtr("testDB"), Collection: toptr.MakePtr("testCollection"), }, { - Cluster: toptr.MakePtr(false), + Cluster: nil, DB: toptr.MakePtr("testDB2"), Collection: toptr.MakePtr("testCollection2"), }, @@ -99,7 +99,7 @@ func TestAtlasCustomRoles_ToAtlas(t *testing.T) { Action: "testName3", Resources: []mongodbatlas.Resource{ { - Cluster: toptr.MakePtr(false), + Cluster: nil, DB: toptr.MakePtr(""), Collection: toptr.MakePtr(""), }, diff --git a/pkg/controller/atlasproject/custom_roles.go b/pkg/controller/atlasproject/custom_roles.go index 2e51387ef2..75dfc9e960 100644 --- a/pkg/controller/atlasproject/custom_roles.go +++ b/pkg/controller/atlasproject/custom_roles.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -74,8 +73,8 @@ func fetchCustomRoles(ctx *workflow.Context, projectID string) ([]v1.CustomRole, resources := make([]v1.Resource, 0, len(atlasAction.Resources)) for _, atlasResource := range atlasAction.Resources { - if atlasResource.Cluster == nil { - atlasResource.Cluster = toptr.MakePtr(false) + if atlasResource.Cluster != nil && !*atlasResource.Cluster { + atlasResource.Cluster = nil } resources = append(resources, v1.Resource{ Cluster: atlasResource.Cluster, diff --git a/test/int/project_test.go b/test/int/project_test.go index 965c373fa6..0fefa02ffa 100644 --- a/test/int/project_test.go +++ b/test/int/project_test.go @@ -54,6 +54,7 @@ var _ = Describe("AtlasProject", Label("int", "AtlasProject"), func() { AfterEach(func() { if createdProject != nil && createdProject.Status.ID != "" { By("Removing Atlas Project " + createdProject.Status.ID) + Expect(k8sClient.Get(context.Background(), kube.ObjectKeyFromObject(createdProject), createdProject)).To(Succeed()) Expect(k8sClient.Delete(context.Background(), createdProject)).To(Succeed()) Eventually(checkAtlasProjectRemoved(createdProject.Status.ID), 20, interval).Should(BeTrue()) }