Skip to content

Commit 3bc6d46

Browse files
committed
feat: customize connection string secret annotations
1 parent c83d4d4 commit 3bc6d46

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

api/v1/mongodbcommunity_types.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ type MongoDBUser struct {
489489
// +optional
490490
ConnectionStringSecretNamespace string `json:"connectionStringSecretNamespace,omitempty"`
491491

492+
// ConnectionStringSecretAnnotations is the annotations of the secret object created by the operator which exposes the connection strings for the user.
493+
// +optional
494+
ConnectionStringSecretAnnotations map[string]string `json:"connectionStringSecretAnnotations,omitempty"`
495+
492496
// Additional options to be appended to the connection string.
493497
// These options apply only to this user and will override any existing options in the resource.
494498
// +kubebuilder:validation:Type=object
@@ -789,12 +793,13 @@ func (m *MongoDBCommunity) GetAuthUsers() []authtypes.User {
789793
}
790794

791795
users[i] = authtypes.User{
792-
Username: u.Name,
793-
Database: u.DB,
794-
Roles: roles,
795-
ConnectionStringSecretName: u.GetConnectionStringSecretName(m.Name),
796-
ConnectionStringSecretNamespace: u.GetConnectionStringSecretNamespace(m.Namespace),
797-
ConnectionStringOptions: u.AdditionalConnectionStringConfig.Object,
796+
Username: u.Name,
797+
Database: u.DB,
798+
Roles: roles,
799+
ConnectionStringSecretName: u.GetConnectionStringSecretName(m.Name),
800+
ConnectionStringSecretNamespace: u.GetConnectionStringSecretNamespace(m.Namespace),
801+
ConnectionStringSecretAnnotations: u.ConnectionStringSecretAnnotations,
802+
ConnectionStringOptions: u.AdditionalConnectionStringConfig.Object,
798803
}
799804

800805
if u.DB != constants.ExternalDB {

config/crd/bases/mongodbcommunity.mongodb.com_mongodbcommunity.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,13 @@ spec:
552552
nullable: true
553553
type: object
554554
x-kubernetes-preserve-unknown-fields: true
555+
connectionStringSecretAnnotations:
556+
additionalProperties:
557+
type: string
558+
description: ConnectionStringSecretAnnotations is the annotations
559+
of the secret object created by the operator which exposes
560+
the connection strings for the user.
561+
type: object
555562
connectionStringSecretName:
556563
description: |-
557564
ConnectionStringSecretName is the name of the secret object created by the operator which exposes the connection strings for the user.

controllers/mongodb_users.go

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (r ReplicaSetReconciler) updateConnectionStringSecrets(ctx context.Context,
7777
SetField("username", user.Username).
7878
SetField("password", pwd).
7979
SetOwnerReferences(mdb.GetOwnerReferences()).
80+
SetAnnotations(user.ConnectionStringSecretAnnotations).
8081
Build()
8182

8283
if err := secret.CreateOrUpdate(ctx, r.client, connectionStringSecret); err != nil {

pkg/authentication/authtypes/authtypes.go

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ type User struct {
7373
// ConnectionStringSecretNamespace is the namespace of the secret object created by the operator which exposes the connection strings for the user.
7474
ConnectionStringSecretNamespace string `json:"connectionStringSecretNamespace,omitempty"`
7575

76+
// ConnectionStringSecretAnnotations is the annotations of the secret object created by the operator which exposes the connection strings for the user.
77+
ConnectionStringSecretAnnotations map[string]string
78+
7679
// ConnectionStringOptions contains connection string options for this user
7780
// These options will be appended at the end of the connection string and
7881
// will override any existing options from the resources.

pkg/kube/secret/secret_builder.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type builder struct {
1111
labels map[string]string
1212
name string
1313
namespace string
14+
annotations map[string]string
1415
ownerReferences []metav1.OwnerReference
1516
}
1617

@@ -24,6 +25,11 @@ func (b *builder) SetNamespace(namespace string) *builder {
2425
return b
2526
}
2627

28+
func (b *builder) SetAnnotations(annotations map[string]string) *builder {
29+
b.annotations = annotations
30+
return b
31+
}
32+
2733
func (b *builder) SetField(key, value string) *builder {
2834
b.data[key] = []byte(value)
2935
return b
@@ -72,6 +78,7 @@ func (b builder) Build() corev1.Secret {
7278
Namespace: b.namespace,
7379
OwnerReferences: b.ownerReferences,
7480
Labels: b.labels,
81+
Annotations: b.annotations,
7582
},
7683
Data: b.data,
7784
Type: b.dataType,

0 commit comments

Comments
 (0)