@@ -6,28 +6,23 @@ import (
66 "strconv"
77 "time"
88
9- "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/k8s"
10-
11- v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
12-
13- "k8s.io/apimachinery/pkg/types"
14-
15- "sigs.k8s.io/controller-runtime/pkg/client"
16-
17- "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
18-
199 . "github.com/onsi/ginkgo/v2"
2010 . "github.com/onsi/gomega"
2111 . "github.com/onsi/gomega/gstruct"
2212 "go.mongodb.org/atlas/mongodbatlas"
13+ corev1 "k8s.io/api/core/v1"
14+ "k8s.io/apimachinery/pkg/types"
15+ "sigs.k8s.io/controller-runtime/pkg/client"
2316
17+ v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
18+ "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
2419 kube "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions/kube"
2520 "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/api/atlas"
2621 appclient "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/appclient"
2722 "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli"
2823 "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/helm"
29- kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
3024 "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/config"
25+ "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/k8s"
3126 "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
3227 "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/utils"
3328)
@@ -133,16 +128,6 @@ func WaitDeploymentWithoutGenerationCheck(data *model.TestDataProvider) {
133128 }
134129}
135130
136- func WaitProject (data * model.TestDataProvider , generation int ) {
137- EventuallyWithOffset (1 , kube .ProjectReadyCondition (data ), "25m" , "10s" ).Should (Equal ("True" ), "Kubernetes resource: Project status `Ready` should be 'True'" )
138- gen , err := k8s .GetProjectObservedGeneration (data .Context , data .K8SClient , data .Resources .Namespace , data .Resources .Project .GetK8sMetaName ())
139- Expect (err ).ToNot (HaveOccurred ())
140- ExpectWithOffset (1 , gen ).Should (Equal (generation ), "Kubernetes resource: Generation should be upgraded" )
141- atlasProject , err := kube .GetProjectResource (data )
142- Expect (err ).ShouldNot (HaveOccurred ())
143- ExpectWithOffset (1 , atlasProject .Status .ID ).ShouldNot (BeNil (), "Kubernetes resource: Project status should have non-empty ID field" )
144- }
145-
146131func WaitProjectWithoutGenerationCheck (data * model.TestDataProvider ) {
147132 EventuallyWithOffset (1 , func () string {
148133 return kube .ProjectReadyCondition (data )
@@ -163,13 +148,6 @@ func WaitTestApplication(data *model.TestDataProvider, ns, labelKey, labelValue
163148 EventuallyWithOffset (1 , isAppRunning (), "2m" , "10s" ).Should (BeTrue (), "Test application should be running" )
164149}
165150
166- func CheckIfDeploymentExist (input model.UserInputs ) func () bool {
167- return func () bool {
168- aClient := atlas .GetClientOrFail ()
169- return aClient .IsDeploymentExist (input .ProjectID , input .Deployments [0 ].Spec .DeploymentSpec .Name )
170- }
171- }
172-
173151func CheckIfUsersExist (input model.UserInputs ) func () bool {
174152 return func () bool {
175153 atlasClient , err := atlas .AClient ()
@@ -269,18 +247,6 @@ func CompareServerlessSpec(requested model.DeploymentSpec, created mongodbatlas.
269247 Expect (created .GroupID ).To (Not (BeEmpty ()))
270248}
271249
272- func SaveK8sResourcesTo (resources []string , ns string , destination string ) {
273- for _ , resource := range resources {
274- data := kubecli .GetYamlResource (resource , ns )
275- path := fmt .Sprintf ("output/%s/%s.yaml" , destination , resource )
276- utils .SaveToFile (path , data )
277- }
278- }
279-
280- func SaveK8sResources (resources []string , ns string ) {
281- SaveK8sResourcesTo (resources , ns , ns )
282- }
283-
284250func SaveProjectsToFile (ctx context.Context , k8sClient client.Client , ns string ) error {
285251 yaml , err := k8s .ProjectListYaml (ctx , k8sClient , ns )
286252 if err != nil {
@@ -335,21 +301,17 @@ func SaveUsersToFile(ctx context.Context, k8sClient client.Client, ns string) er
335301
336302func SaveTestAppLogs (input model.UserInputs ) {
337303 for _ , user := range input .Users {
338- utils . SaveToFile (
339- fmt . Sprintf ( "output/%s/testapp-describe-%s.txt" , input .Namespace , user . Spec . Username ),
340- kubecli . DescribeTestApp ( config . TestAppLabelPrefix + user . Spec . Username , input . Namespace ),
341- )
304+ testAppName := fmt . Sprintf ( "test-app-%s" , user . Spec . Username )
305+ bytes , err := k8s . GetPodLogsByDeployment ( testAppName , input .Namespace , corev1. PodLogOptions {})
306+ Expect ( err ). ToNot ( HaveOccurred ())
307+
342308 utils .SaveToFile (
343309 fmt .Sprintf ("output/%s/testapp-logs-%s.txt" , input .Namespace , user .Spec .Username ),
344- kubecli . GetLogs ( config . TestAppLabelPrefix + user . Spec . Username , input . Namespace ) ,
310+ bytes ,
345311 )
346312 }
347313}
348314
349- func SaveDeploymentDump (input model.UserInputs ) {
350- kubecli .GetDeploymentDump (fmt .Sprintf ("output/%s/dump" , input .Namespace ))
351- }
352-
353315func CheckUsersAttributes (data * model.TestDataProvider ) {
354316 input := data .Resources
355317 aClient := atlas .GetClientOrFail ()
@@ -487,85 +449,6 @@ func CreateConnectionAtlasKey(data *model.TestDataProvider) {
487449 })
488450}
489451
490- func createConnectionAtlasKeyFrom (data * model.TestDataProvider , key * mongodbatlas.APIKey ) {
491- By ("Change resources depends on AtlasKey and create key" , func () {
492- if data .Resources .AtlasKeyAccessType .GlobalLevelKey {
493- err := k8s .CreateSecret (data .Context , data .K8SClient , key .PublicKey , key .PrivateKey , config .DefaultOperatorGlobalKey , data .Resources .Namespace )
494- Expect (err ).NotTo (HaveOccurred ())
495- } else {
496- err := k8s .CreateSecret (data .Context , data .K8SClient , key .PublicKey , key .PrivateKey , data .Resources .KeyName , data .Resources .Namespace )
497- Expect (err ).NotTo (HaveOccurred ())
498- }
499- })
500- }
501-
502- func recreateAtlasKeyIfNeed (data * model.TestDataProvider ) {
503- if ! data .Resources .AtlasKeyAccessType .IsFullAccess () {
504- aClient , err := atlas .AClient ()
505- Expect (err ).ShouldNot (HaveOccurred ())
506- globalKey , err := aClient .AddKeyWithAccessList (data .Resources .ProjectID , data .Resources .AtlasKeyAccessType .Roles , data .Resources .AtlasKeyAccessType .Whitelist )
507- Expect (err ).ShouldNot (HaveOccurred ())
508- Expect (globalKey .PublicKey ).ShouldNot (BeEmpty ())
509- Expect (globalKey .PrivateKey ).ShouldNot (BeEmpty ())
510- data .Resources .AtlasKeyAccessType .GlobalKeyAttached = globalKey
511-
512- k8s .DeleteKey (data .Context , data .K8SClient , data .Resources .KeyName , data .Resources .Namespace )
513- createConnectionAtlasKeyFrom (data , globalKey )
514- }
515- }
516-
517- func DeployProjectAndWait (data * model.TestDataProvider , generation int ) {
518- By ("Create users resources: keys, project" , func () {
519- CreateConnectionAtlasKey (data )
520- kubecli .Apply (data .Resources .ProjectPath , "-n" , data .Resources .Namespace )
521- By ("Wait project creation and get projectID" , func () {
522- WaitProject (data , generation )
523- atlasProject , err := kube .GetProjectResource (data )
524- Expect (err ).Should (BeNil (), "Error has Occurred" )
525- data .Resources .ProjectID = atlasProject .Status .ID
526- Expect (data .Resources .ProjectID ).ShouldNot (BeEmpty ())
527- })
528- recreateAtlasKeyIfNeed (data )
529- })
530- }
531-
532- func DeployDeployment (data * model.TestDataProvider ) {
533- if len (data .Resources .Deployments ) > 0 {
534- By ("Create deployment" , func () {
535- kubecli .Apply (data .Resources .Deployments [0 ].DeploymentFileName (data .Resources ), "-n" , data .Resources .Namespace )
536- })
537- By ("Wait deployment creation" , func () {
538- WaitDeploymentWithoutGenerationCheck (data )
539- })
540- By ("check deployment Attribute" , func () {
541- aClient , err := atlas .AClient ()
542- Expect (err ).NotTo (HaveOccurred ())
543- deployment := aClient .GetDeployment (data .Resources .ProjectID , data .Resources .Deployments [0 ].Spec .DeploymentSpec .Name )
544- CompareDeploymentsSpec (data .Resources .Deployments [0 ].Spec , deployment )
545- })
546- }
547- }
548-
549- func DeployUsers (data * model.TestDataProvider ) {
550- By ("create users" , func () {
551- kubecli .Apply (data .Resources .GetResourceFolder ()+ "/user/" , "-n" , data .Resources .Namespace )
552- })
553- By ("check database users Attributes" , func () {
554- Eventually (CheckIfUsersExist (data .Resources ), "2m" , "10s" ).Should (BeTrue ())
555- CheckUsersAttributes (data )
556- })
557- By ("Deploy application for user" , func () {
558- CheckUsersCanUseApp (data )
559- })
560- }
561-
562- // DeployUserResourcesAction deploy all user resources, wait, and check results
563- func DeployUserResourcesAction (data * model.TestDataProvider ) {
564- DeployProjectAndWait (data , 1 )
565- DeployDeployment (data )
566- DeployUsers (data )
567- }
568-
569452func DeleteDBUsersApps (data model.TestDataProvider ) {
570453 By ("Delete dbusers applications" , func () {
571454 for _ , user := range data .Resources .Users {
@@ -574,34 +457,6 @@ func DeleteDBUsersApps(data model.TestDataProvider) {
574457 })
575458}
576459
577- func DeleteUserResources (data * model.TestDataProvider ) {
578- DeleteUserResourcesDeployment (data )
579- DeleteUserResourcesProject (data )
580- }
581-
582- func DeleteUserResourcesDeployment (data * model.TestDataProvider ) {
583- By ("Delete deployment" , func () {
584- kubecli .Delete (data .Resources .Deployments [0 ].DeploymentFileName (data .Resources ), "-n" , data .Resources .Namespace )
585- Eventually (
586- CheckIfDeploymentExist (data .Resources ),
587- "10m" , "1m" ,
588- ).Should (BeFalse (), "Deployment should be deleted from Atlas" )
589- })
590- }
591-
592- func DeleteUserResourcesProject (data * model.TestDataProvider ) {
593- By ("Delete project" , func () {
594- kubecli .Delete (data .Resources .ProjectPath , "-n" , data .Resources .Namespace )
595- Eventually (
596- func (g Gomega ) bool {
597- aClient := atlas .GetClientOrFail ()
598- return aClient .IsProjectExists (g , data .Resources .ProjectID )
599- },
600- "5m" , "20s" ,
601- ).Should (BeFalse (), "Project should be deleted from Atlas" )
602- })
603- }
604-
605460func DeleteTestDataProject (data * model.TestDataProvider ) {
606461 By ("Delete project" , func () {
607462 Expect (data .K8SClient .Get (data .Context , types.NamespacedName {Name : data .Project .Name , Namespace : data .Project .Namespace }, data .Project )).Should (Succeed ())
@@ -648,6 +503,16 @@ func DeleteTestDataDeployments(data *model.TestDataProvider) {
648503 })
649504}
650505
506+ func DeleteTestDataUsers (data * model.TestDataProvider ) {
507+ By ("Delete Users" , func () {
508+ for _ , user := range data .Users {
509+ Expect (data .K8SClient .Get (data .Context , types.NamespacedName {Name : data .Project .Name , Namespace : data .Project .Namespace }, data .Project )).Should (Succeed ())
510+ Expect (data .K8SClient .Get (data .Context , types.NamespacedName {Name : user .Name , Namespace : user .Namespace }, user )).Should (Succeed ())
511+ Expect (data .K8SClient .Delete (data .Context , user )).Should (Succeed ())
512+ }
513+ })
514+ }
515+
651516func DeleteAtlasGlobalKeyIfExist (data model.TestDataProvider ) {
652517 if data .Resources .AtlasKeyAccessType .GlobalLevelKey {
653518 By ("Delete Global API key for test" , func () {
0 commit comments