-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-278387: Add index for dbUser by project and improve connection…
… secret generation (#1860)
- Loading branch information
Showing
7 changed files
with
245 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package indexer | ||
|
||
import ( | ||
"context" | ||
|
||
"go.uber.org/zap" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1" | ||
) | ||
|
||
const ( | ||
AtlasDatabaseUserByProject = "atlasdatabaseuser.spec.projectRef,externalProjectID" | ||
) | ||
|
||
type AtlasDatabaseUserByProjectIndexer struct { | ||
ctx context.Context | ||
client client.Client | ||
logger *zap.SugaredLogger | ||
} | ||
|
||
func NewAtlasDatabaseUserByProjectIndexer(ctx context.Context, client client.Client, logger *zap.Logger) *AtlasDatabaseUserByProjectIndexer { | ||
return &AtlasDatabaseUserByProjectIndexer{ | ||
ctx: ctx, | ||
client: client, | ||
logger: logger.Named(AtlasDatabaseUserByProject).Sugar(), | ||
} | ||
} | ||
|
||
func (*AtlasDatabaseUserByProjectIndexer) Object() client.Object { | ||
return &akov2.AtlasDatabaseUser{} | ||
} | ||
|
||
func (*AtlasDatabaseUserByProjectIndexer) Name() string { | ||
return AtlasDatabaseUserByProject | ||
} | ||
|
||
func (a *AtlasDatabaseUserByProjectIndexer) Keys(object client.Object) []string { | ||
user, ok := object.(*akov2.AtlasDatabaseUser) | ||
if !ok { | ||
a.logger.Errorf("expected *v1.AtlasDatabaseUser but got %T", object) | ||
return nil | ||
} | ||
|
||
if user.Spec.ExternalProjectRef != nil && user.Spec.ExternalProjectRef.ID != "" { | ||
return []string{user.Spec.ExternalProjectRef.ID} | ||
} | ||
|
||
if user.Spec.Project != nil && user.Spec.Project.Name != "" { | ||
project := &akov2.AtlasProject{} | ||
err := a.client.Get(a.ctx, *user.Spec.Project.GetObject(user.Namespace), project) | ||
if err != nil { | ||
a.logger.Errorf("unable to find project to index: %s", err) | ||
|
||
return nil | ||
} | ||
|
||
if project.ID() != "" { | ||
return []string{project.ID()} | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.