@@ -34,13 +34,7 @@ var _ = Describe("AtlasProject", func() {
3434
3535 createdProject = & mdbv1.AtlasProject {}
3636
37- connectionSecret = corev1.Secret {
38- ObjectMeta : metav1.ObjectMeta {
39- Name : "my-atlas-key" ,
40- Namespace : namespace .Name ,
41- },
42- StringData : map [string ]string {"orgId" : connection .OrgID , "publicApiKey" : connection .PublicKey , "privateApiKey" : connection .PrivateKey },
43- }
37+ connectionSecret = buildConnectionSecret ("my-atlas-key" )
4438 By (fmt .Sprintf ("Creating the Secret %s" , kube .ObjectKeyFromObject (& connectionSecret )))
4539 Expect (k8sClient .Create (context .Background (), & connectionSecret )).ToNot (HaveOccurred ())
4640 })
@@ -111,7 +105,6 @@ var _ = Describe("AtlasProject", func() {
111105 Eventually (testutil .WaitFor (k8sClient , createdProject , expectedCondition ),
112106 20 , interval ).Should (BeTrue ())
113107
114- Expect (createdProject .Status .ObservedGeneration ).To (Equal (createdProject .Generation ))
115108 expectedConditionsMatchers := testutil .MatchConditions (
116109 status .FalseCondition (status .ProjectReadyType ),
117110 status .FalseCondition (status .ReadyType ),
@@ -339,20 +332,83 @@ var _ = Describe("AtlasProject", func() {
339332 })
340333 })
341334 })
335+
336+ Describe ("Using the global Connection Secret" , func () {
337+ It ("Should Succeed" , func () {
338+ globalConnectionSecret := buildConnectionSecret ("atlas-operator-api-key" )
339+ Expect (k8sClient .Create (context .Background (), & globalConnectionSecret )).To (Succeed ())
340+
341+ // We don't specify the connection Secret per project - the global one must be used
342+ createdProject = testAtlasProject (namespace .Name , "test-project" , namespace .Name , "" )
343+
344+ Expect (k8sClient .Create (context .Background (), createdProject )).To (Succeed ())
345+
346+ Eventually (testutil .WaitFor (k8sClient , createdProject , status .TrueCondition (status .ReadyType )),
347+ 20 , interval ).Should (BeTrue ())
348+
349+ expectedConditionsMatchers := testutil .MatchConditions (
350+ status .TrueCondition (status .ProjectReadyType ),
351+ status .TrueCondition (status .IPAccessListReadyType ),
352+ status .TrueCondition (status .ReadyType ),
353+ )
354+ Expect (createdProject .Status .Conditions ).To (ConsistOf (expectedConditionsMatchers ))
355+ Expect (createdProject .Status .ObservedGeneration ).To (Equal (createdProject .Generation ))
356+ })
357+ It ("Should Fail if the global Secret doesn't exist" , func () {
358+ By ("Creating without a global Secret" , func () {
359+ createdProject = testAtlasProject (namespace .Name , "test-project" , namespace .Name , "" )
360+
361+ Expect (k8sClient .Create (context .Background (), createdProject )).ToNot (HaveOccurred ())
362+
363+ Eventually (testutil .WaitFor (k8sClient , createdProject , status .FalseCondition (status .ReadyType )),
364+ 20 , interval ).Should (BeTrue ())
365+
366+ expectedConditionsMatchers := testutil .MatchConditions (
367+ status .FalseCondition (status .ProjectReadyType ).WithReason (string (workflow .AtlasCredentialsNotProvided )),
368+ status .FalseCondition (status .ReadyType ),
369+ )
370+ Expect (createdProject .Status .Conditions ).To (ConsistOf (expectedConditionsMatchers ))
371+ Expect (createdProject .ID ()).To (BeEmpty ())
372+ Expect (createdProject .Status .ObservedGeneration ).To (Equal (createdProject .Generation ))
373+ })
374+ By ("Creating a global Secret - should get fixed" , func () {
375+ globalConnectionSecret := buildConnectionSecret ("atlas-operator-api-key" )
376+ Expect (k8sClient .Create (context .Background (), & globalConnectionSecret )).To (Succeed ())
377+
378+ Eventually (testutil .WaitFor (k8sClient , createdProject , status .TrueCondition (status .ReadyType )),
379+ 20 , interval ).Should (BeTrue ())
380+ })
381+
382+ })
383+ })
384+
342385})
343386
387+ func buildConnectionSecret (name string ) corev1.Secret {
388+ return corev1.Secret {
389+ ObjectMeta : metav1.ObjectMeta {
390+ Name : name ,
391+ Namespace : namespace .Name ,
392+ },
393+ StringData : map [string ]string {"orgId" : connection .OrgID , "publicApiKey" : connection .PublicKey , "privateApiKey" : connection .PrivateKey },
394+ }
395+ }
396+
344397// TODO builders
345398func testAtlasProject (namespace , name , atlasName , connectionSecretName string ) * mdbv1.AtlasProject {
346- return & mdbv1.AtlasProject {
399+ project := mdbv1.AtlasProject {
347400 ObjectMeta : metav1.ObjectMeta {
348401 Name : name ,
349402 Namespace : namespace ,
350403 },
351404 Spec : mdbv1.AtlasProjectSpec {
352- Name : atlasName ,
353- ConnectionSecret : & mdbv1.ResourceRef {Name : connectionSecretName },
405+ Name : atlasName ,
354406 },
355407 }
408+ if connectionSecretName != "" {
409+ project .Spec .ConnectionSecret = & mdbv1.ResourceRef {Name : connectionSecretName }
410+ }
411+ return & project
356412}
357413
358414func removeAtlasProject (projectID string ) func () bool {
0 commit comments