Skip to content

CLOUDP-316083: Third Party Integrations Controller #2313

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

Merged
merged 4 commits into from
Jun 17, 2025
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
2 changes: 1 addition & 1 deletion .licenses-gomod.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
100644 c8e3dff0e5c33fa3dbbc73d0d75cf57f9f1d7e7e go.mod
100644 b1190edabf8ad97f199b0eb0358514f45d8c9bb3 go.mod
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ packages:
github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/translation/encryptionatrest:
github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/translation/networkcontainer:
github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/translation/networkpeering:
github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/translation/thirdpartyintegration:
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ e2e2: run-kind manager install-credentials install-crds set-namespace ## Run e2e
NO_GORUN=1 \
AKO_E2E2_TEST=1 \
OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) \
ginkgo --race --label-filter=$(label) --timeout 120m -vv test/e2e2/
ginkgo --race --label-filter=$(label) -ldflags="$(LD_FLAGS)" --timeout 120m -vv test/e2e2/

.PHONY: e2e-openshift-upgrade
e2e-openshift-upgrade:
Expand Down Expand Up @@ -581,12 +581,26 @@ run: prepare-run ## Run a freshly compiled manager against kind
ifdef RUN_YAML
kubectl apply -n $(OPERATOR_NAMESPACE) -f $(RUN_YAML)
endif
ifdef BACKGROUND
@bash -c '(VERSION=$(NEXT_VERSION) \
OPERATOR_POD_NAME=$(OPERATOR_POD_NAME) \
OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) \
nohup bin/manager --object-deletion-protection=false --log-level=$(RUN_LOG_LEVEL) \
--atlas-domain=$(ATLAS_DOMAIN) \
--global-api-secret-name=$(ATLAS_KEY_SECRET_NAME) > ako.log 2>&1 & echo $$! > ako.pid \
&& echo "OPERATOR_PID=$$!")'
else
VERSION=$(NEXT_VERSION) \
OPERATOR_POD_NAME=$(OPERATOR_POD_NAME) \
OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) \
bin/manager --object-deletion-protection=false --log-level=$(RUN_LOG_LEVEL) \
--atlas-domain=$(ATLAS_DOMAIN) \
--global-api-secret-name=$(ATLAS_KEY_SECRET_NAME)
endif

.PHONY: stop-ako
stop-ako:
@kill `cat ako.pid` && rm ako.pid || echo "AKO process not found or already stopped!"

.PHONY: local-docker-build
local-docker-build:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
go.mongodb.org/atlas-sdk/v20231115004 v20231115004.1.0
go.mongodb.org/atlas-sdk/v20231115008 v20231115008.5.0
go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0
go.mongodb.org/mongo-driver v1.17.4
go.uber.org/zap v1.27.0
golang.org/x/sync v0.15.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ go.mongodb.org/atlas-sdk/v20231115008 v20231115008.5.0 h1:OuV1HfIpZUZa4+BKvtrvDl
go.mongodb.org/atlas-sdk/v20231115008 v20231115008.5.0/go.mod h1:0707RpWIrNFZ6Msy/dwRDCzC5JVDon61JoOqcbfCujg=
go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0 h1:G3UZcWwWziGUuaILWp/Gc+jLm1tfu7OUhUOpMWVZSWc=
go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0/go.mod h1:fMiUyCacIAm+XwFkJ4j+rJtYLRsGU7hButtgGv+SBU4=
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0 h1:KX8PrYp3/PCSxG4NbGLcc3+EsNcfyhcvylGbe/oRlx8=
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0/go.mod h1:HHCmHxHPdJRr1bUXlvRIZbm7M4gRujjur1GnjE44YgA=
go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
Expand Down
11 changes: 11 additions & 0 deletions internal/controller/atlas/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/mongodb-forks/digest"
adminv20231115008 "go.mongodb.org/atlas-sdk/v20231115008/admin"
adminv20241113001 "go.mongodb.org/atlas-sdk/v20241113001/admin"
adminv20250312002 "go.mongodb.org/atlas-sdk/v20250312002/admin"
"go.mongodb.org/atlas/mongodbatlas"
"go.uber.org/zap"

Expand All @@ -49,6 +50,7 @@ type Provider interface {
type ClientSet struct {
SdkClient20231115008 *adminv20231115008.APIClient
SdkClient20241113001 *adminv20241113001.APIClient
SdkClient20250312002 *adminv20250312002.APIClient
}

type ProductionProvider struct {
Expand Down Expand Up @@ -162,9 +164,18 @@ func (p *ProductionProvider) SdkClientSet(ctx context.Context, creds *Credential
return nil, err
}

clientv20241113002, err := adminv20250312002.NewClient(
adminv20250312002.UseBaseURL(p.domain),
adminv20250312002.UseHTTPClient(httpClient),
adminv20250312002.UseUserAgent(operatorUserAgent()))
if err != nil {
return nil, err
}

return &ClientSet{
SdkClient20231115008: clientv20231115008,
SdkClient20241113001: clientv20241113001,
SdkClient20250312002: clientv20241113002,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type AtlasCustomRoleReconciler struct {
reconciler.AtlasReconciler
Scheme *runtime.Scheme
EventRecorder record.EventRecorder
AtlasProvider atlas.Provider
GlobalPredicates []predicate.Predicate
ObjectDeletionProtection bool
SubObjectDeletionProtection bool
Expand All @@ -71,10 +70,10 @@ func NewAtlasCustomRoleReconciler(
Client: c.GetClient(),
Log: logger.Named("controllers").Named("AtlasCustomRoles").Sugar(),
GlobalSecretRef: globalSecretRef,
AtlasProvider: atlasProvider,
},
Scheme: c.GetScheme(),
EventRecorder: c.GetEventRecorderFor("AtlasCustomRoles"),
AtlasProvider: atlasProvider,
GlobalPredicates: predicates,
ObjectDeletionProtection: deletionProtection,
independentSyncPeriod: independentSyncPeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,48 +368,48 @@ func TestAtlasCustomRoleReconciler_Reconcile(t *testing.T) {
AtlasReconciler: reconciler.AtlasReconciler{
Client: k8sClient,
Log: zap.S(),
},
Scheme: testScheme,
EventRecorder: record.NewFakeRecorder(10),
AtlasProvider: &atlasmocks.TestProvider{
SdkClientSetFunc: func(ctx context.Context, creds *atlas.Credentials, log *zap.SugaredLogger) (*atlas.ClientSet, error) {
if tt.sdkShouldError {
return nil, fmt.Errorf("failed to create sdk")
}
cdrAPI := mockadmin.NewCustomDatabaseRolesApi(t)
cdrAPI.EXPECT().GetCustomDatabaseRole(mock.Anything, "testProjectID", "TestRoleName").
Return(admin.GetCustomDatabaseRoleApiRequest{ApiService: cdrAPI})
cdrAPI.EXPECT().GetCustomDatabaseRoleExecute(admin.GetCustomDatabaseRoleApiRequest{ApiService: cdrAPI}).
Return(&admin.UserCustomDBRole{}, &http.Response{StatusCode: http.StatusNotFound}, nil)
cdrAPI.EXPECT().CreateCustomDatabaseRole(mock.Anything, "testProjectID",
mock.AnythingOfType("*admin.UserCustomDBRole")).
Return(admin.CreateCustomDatabaseRoleApiRequest{ApiService: cdrAPI})
cdrAPI.EXPECT().CreateCustomDatabaseRoleExecute(admin.CreateCustomDatabaseRoleApiRequest{ApiService: cdrAPI}).
Return(nil, nil, nil)
AtlasProvider: &atlasmocks.TestProvider{
SdkClientSetFunc: func(ctx context.Context, creds *atlas.Credentials, log *zap.SugaredLogger) (*atlas.ClientSet, error) {
if tt.sdkShouldError {
return nil, fmt.Errorf("failed to create sdk")
}
cdrAPI := mockadmin.NewCustomDatabaseRolesApi(t)
cdrAPI.EXPECT().GetCustomDatabaseRole(mock.Anything, "testProjectID", "TestRoleName").
Return(admin.GetCustomDatabaseRoleApiRequest{ApiService: cdrAPI})
cdrAPI.EXPECT().GetCustomDatabaseRoleExecute(admin.GetCustomDatabaseRoleApiRequest{ApiService: cdrAPI}).
Return(&admin.UserCustomDBRole{}, &http.Response{StatusCode: http.StatusNotFound}, nil)
cdrAPI.EXPECT().CreateCustomDatabaseRole(mock.Anything, "testProjectID",
mock.AnythingOfType("*admin.UserCustomDBRole")).
Return(admin.CreateCustomDatabaseRoleApiRequest{ApiService: cdrAPI})
cdrAPI.EXPECT().CreateCustomDatabaseRoleExecute(admin.CreateCustomDatabaseRoleApiRequest{ApiService: cdrAPI}).
Return(nil, nil, nil)

pAPI := mockadmin.NewProjectsApi(t)
if tt.akoCustomRole.Spec.ExternalProjectRef != nil {
grp := &admin.Group{
Id: &tt.akoCustomRole.Spec.ExternalProjectRef.ID,
Name: tt.akoCustomRole.Spec.ExternalProjectRef.ID,
pAPI := mockadmin.NewProjectsApi(t)
if tt.akoCustomRole.Spec.ExternalProjectRef != nil {
grp := &admin.Group{
Id: &tt.akoCustomRole.Spec.ExternalProjectRef.ID,
Name: tt.akoCustomRole.Spec.ExternalProjectRef.ID,
}
pAPI.EXPECT().GetProject(context.Background(), tt.akoCustomRole.Spec.ExternalProjectRef.ID).
Return(admin.GetProjectApiRequest{ApiService: pAPI})
pAPI.EXPECT().GetProjectExecute(admin.GetProjectApiRequest{ApiService: pAPI}).
Return(grp, nil, nil)
}
pAPI.EXPECT().GetProject(context.Background(), tt.akoCustomRole.Spec.ExternalProjectRef.ID).
Return(admin.GetProjectApiRequest{ApiService: pAPI})
pAPI.EXPECT().GetProjectExecute(admin.GetProjectApiRequest{ApiService: pAPI}).
Return(grp, nil, nil)
}
return &atlas.ClientSet{SdkClient20231115008: &admin.APIClient{
CustomDatabaseRolesApi: cdrAPI,
ProjectsApi: pAPI,
}}, nil
},
IsCloudGovFunc: func() bool {
return false
},
IsSupportedFunc: func() bool {
return tt.isSupported
return &atlas.ClientSet{SdkClient20231115008: &admin.APIClient{
CustomDatabaseRolesApi: cdrAPI,
ProjectsApi: pAPI,
}}, nil
},
IsCloudGovFunc: func() bool {
return false
},
IsSupportedFunc: func() bool {
return tt.isSupported
},
},
},
Scheme: testScheme,
EventRecorder: record.NewFakeRecorder(10),
}

result, err := r.Reconcile(context.Background(), ctrl.Request{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var ErrOIDCNotEnabled = fmt.Errorf("'OIDCAuthType' field is set but OIDC authent
// AtlasDatabaseUserReconciler reconciles an AtlasDatabaseUser object
type AtlasDatabaseUserReconciler struct {
reconciler.AtlasReconciler
AtlasProvider atlas.Provider
Scheme *runtime.Scheme
EventRecorder record.EventRecorder
GlobalPredicates []predicate.Predicate
Expand Down Expand Up @@ -287,8 +286,8 @@ func NewAtlasDatabaseUserReconciler(
Client: c.GetClient(),
Log: logger.Named("controllers").Named("AtlasDatabaseUser").Sugar(),
GlobalSecretRef: globalSecretRef,
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
Scheme: c.GetScheme(),
EventRecorder: c.GetEventRecorderFor("AtlasDatabaseUser"),
GlobalPredicates: predicates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ func TestReconcile(t *testing.T) {
Build()
r := &AtlasDatabaseUserReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Client: k8sClient,
Log: zaptest.NewLogger(t).Sugar(),
Client: k8sClient,
Log: zaptest.NewLogger(t).Sugar(),
AtlasProvider: DefaultTestProvider(t),
},
AtlasProvider: DefaultTestProvider(t),
EventRecorder: record.NewFakeRecorder(10),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ func TestHandleDatabaseUser(t *testing.T) {
Namespace: "default",
Name: "secret",
},
AtlasProvider: tt.atlasProvider,
},
AtlasProvider: tt.atlasProvider,
}
ctx := &workflow.Context{
Context: context.Background(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type AtlasDeploymentReconciler struct {
Scheme *runtime.Scheme
GlobalPredicates []predicate.Predicate
EventRecorder record.EventRecorder
AtlasProvider atlas.Provider
ObjectDeletionProtection bool
SubObjectDeletionProtection bool
independentSyncPeriod time.Duration
Expand Down Expand Up @@ -422,11 +421,11 @@ func NewAtlasDeploymentReconciler(
Client: c.GetClient(),
Log: suggaredLogger,
GlobalSecretRef: globalSecretref,
AtlasProvider: atlasProvider,
},
Scheme: c.GetScheme(),
EventRecorder: c.GetEventRecorderFor("AtlasDeployment"),
GlobalPredicates: predicates,
AtlasProvider: atlasProvider,
ObjectDeletionProtection: deletionProtection,
independentSyncPeriod: independentSyncPeriod,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ func TestCleanupBindings(t *testing.T) {
}
r := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Log: testLog(t),
Client: testK8sClient(),
Log: testLog(t),
Client: testK8sClient(),
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
}
policy := testBackupPolicy() // deployment -> schedule -> policy
require.NoError(t, r.Client.Create(context.Background(), policy))
Expand Down Expand Up @@ -140,10 +140,10 @@ func TestCleanupBindings(t *testing.T) {
}
r := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Log: testLog(t),
Client: testK8sClient(),
Log: testLog(t),
Client: testK8sClient(),
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
}
policy := testBackupPolicy() // deployment + deployment2 -> schedule -> policy
require.NoError(t, r.Client.Create(context.Background(), policy))
Expand Down Expand Up @@ -179,10 +179,10 @@ func TestCleanupBindings(t *testing.T) {
}
r := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Log: testLog(t),
Client: testK8sClient(),
Log: testLog(t),
Client: testK8sClient(),
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
}
policy := testBackupPolicy() // deployment -> schedule + schedule2 -> policy
require.NoError(t, r.Client.Create(context.Background(), policy))
Expand Down Expand Up @@ -556,10 +556,10 @@ func TestRegularClusterReconciliation(t *testing.T) {

reconciler := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Client: k8sClient,
Log: logger.Sugar(),
Client: k8sClient,
Log: logger.Sugar(),
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
EventRecorder: record.NewFakeRecorder(10),
ObjectDeletionProtection: false,
SubObjectDeletionProtection: false,
Expand Down Expand Up @@ -693,10 +693,10 @@ func TestServerlessInstanceReconciliation(t *testing.T) {

reconciler := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Client: k8sClient,
Log: logger.Sugar(),
Client: k8sClient,
Log: logger.Sugar(),
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
EventRecorder: record.NewFakeRecorder(10),
ObjectDeletionProtection: false,
SubObjectDeletionProtection: false,
Expand Down Expand Up @@ -818,10 +818,10 @@ func TestFlexClusterReconciliation(t *testing.T) {

reconciler := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Client: k8sClient,
Log: logger.Sugar(),
Client: k8sClient,
Log: logger.Sugar(),
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
EventRecorder: record.NewFakeRecorder(10),
ObjectDeletionProtection: false,
SubObjectDeletionProtection: false,
Expand Down Expand Up @@ -1002,10 +1002,10 @@ func TestDeletionReconciliation(t *testing.T) {

reconciler := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Client: k8sClient,
Log: logger,
Client: k8sClient,
Log: logger,
AtlasProvider: atlasProvider,
},
AtlasProvider: atlasProvider,
EventRecorder: record.NewFakeRecorder(10),
ObjectDeletionProtection: false,
SubObjectDeletionProtection: false,
Expand Down Expand Up @@ -1455,10 +1455,10 @@ func TestChangeDeploymentType(t *testing.T) {

r := &AtlasDeploymentReconciler{
AtlasReconciler: reconciler.AtlasReconciler{
Client: k8sClient,
Log: logger.Sugar(),
Client: k8sClient,
Log: logger.Sugar(),
AtlasProvider: tt.atlasProvider,
},
AtlasProvider: tt.atlasProvider,
EventRecorder: record.NewFakeRecorder(10),
}
result, err := r.Reconcile(
Expand Down
Loading
Loading