1- package atlasdatabaseuser
1+ package connectionsecret
22
33import (
44 "context"
@@ -10,7 +10,6 @@ import (
1010 "sigs.k8s.io/controller-runtime/pkg/client"
1111
1212 mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
13- "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/connectionsecret"
1413 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/workflow"
1514 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube"
1615 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/stringutil"
@@ -91,16 +90,16 @@ func createOrUpdateConnectionSecretsFromDeploymentSecrets(ctx *workflow.Context,
9190 if err != nil {
9291 return workflow .Terminate (workflow .DatabaseUserConnectionSecretsNotCreated , err .Error ())
9392 }
94- data := connectionsecret. ConnectionData {
93+ data := ConnectionData {
9594 DBUserName : dbUser .Spec .Username ,
9695 Password : password ,
9796 ConnURL : ds .connectionStrings .Standard ,
9897 SrvConnURL : ds .connectionStrings .StandardSrv ,
9998 }
100- fillPrivateConnStrings (ds .connectionStrings , & data )
99+ FillPrivateConnStrings (ds .connectionStrings , & data )
101100
102101 var secretName string
103- if secretName , err = connectionsecret . Ensure (k8sClient , dbUser .Namespace , project .Spec .Name , project .ID (), ds .name , data ); err != nil {
102+ if secretName , err = Ensure (k8sClient , dbUser .Namespace , project .Spec .Name , project .ID (), ds .name , data ); err != nil {
104103 return workflow .Terminate (workflow .DatabaseUserConnectionSecretsNotCreated , err .Error ())
105104 }
106105 secrets = append (secrets , secretName )
@@ -128,7 +127,7 @@ func cleanupStaleSecrets(ctx *workflow.Context, k8sClient client.Client, project
128127 // Performing the cleanup of old secrets only if the username has changed
129128 if user .Status .UserName != user .Spec .Username {
130129 // Note, that we pass the username from the status, not from the spec
131- return removeStaleSecretsByUserName (k8sClient , projectID , user .Status .UserName , user , ctx .Log )
130+ return RemoveStaleSecretsByUserName (k8sClient , projectID , user .Status .UserName , user , ctx .Log )
132131 }
133132 return nil
134133}
@@ -139,12 +138,12 @@ func removeStaleByScope(ctx *workflow.Context, k8sClient client.Client, projectI
139138 if len (scopes ) == 0 {
140139 return nil
141140 }
142- secrets , err := connectionsecret . ListByUserName (k8sClient , user .Namespace , projectID , user .Spec .Username )
141+ secrets , err := ListByUserName (k8sClient , user .Namespace , projectID , user .Spec .Username )
143142 if err != nil {
144143 return err
145144 }
146145 for i , s := range secrets {
147- deployment , ok := s .Labels [connectionsecret . ClusterLabelKey ]
146+ deployment , ok := s .Labels [ClusterLabelKey ]
148147 if ! ok {
149148 continue
150149 }
@@ -158,9 +157,9 @@ func removeStaleByScope(ctx *workflow.Context, k8sClient client.Client, projectI
158157 return nil
159158}
160159
161- // removeStaleSecretsByUserName removes the stale secrets when the database user name changes (as it's used as a part of Secret name)
162- func removeStaleSecretsByUserName (k8sClient client.Client , projectID , userName string , user mdbv1.AtlasDatabaseUser , log * zap.SugaredLogger ) error {
163- secrets , err := connectionsecret . ListByUserName (k8sClient , user .Namespace , projectID , userName )
160+ // RemoveStaleSecretsByUserName removes the stale secrets when the database user name changes (as it's used as a part of Secret name)
161+ func RemoveStaleSecretsByUserName (k8sClient client.Client , projectID , userName string , user mdbv1.AtlasDatabaseUser , log * zap.SugaredLogger ) error {
162+ secrets , err := ListByUserName (k8sClient , user .Namespace , projectID , userName )
164163 if err != nil {
165164 return err
166165 }
@@ -181,7 +180,7 @@ func removeStaleSecretsByUserName(k8sClient client.Client, projectID, userName s
181180 return lastError
182181}
183182
184- func fillPrivateConnStrings (connStrings * mongodbatlas.ConnectionStrings , data * connectionsecret. ConnectionData ) {
183+ func FillPrivateConnStrings (connStrings * mongodbatlas.ConnectionStrings , data * ConnectionData ) {
185184 if connStrings .Private != "" {
186185 data .PvtConnURL = connStrings .Private
187186 data .PvtSrvConnURL = connStrings .PrivateSrv
0 commit comments