Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ jobs:
wget https://github.com/operator-framework/operator-sdk/releases/download/v1.22.0/operator-sdk_linux_amd64 -q
chmod +x operator-sdk_linux_amd64 && sudo mv operator-sdk_linux_amd64 /usr/local/bin/operator-sdk
operator-sdk version
- name: Print kubectl version
run: |
kubectl version
- name: Install CRDs if needed
if: ${{ !( matrix.test == 'helm-update' || matrix.test == 'helm-wide' || matrix.test == 'bundle-test' ) }}
run: |
Expand All @@ -203,7 +206,7 @@ jobs:
MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
MCLI_ORG_ID: ${{ secrets.ATLAS_ORG_ID}}
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/"
IMAGE_URL: ${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}
IMAGE_URL: "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}"
BUNDLE_IMAGE: "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_BUNDLES_REPO}}:${{ steps.prepare.outputs.tag }}"
K8S_PLATFORM: "${{ steps.properties.outputs.k8s_platform }}"
K8S_VERSION: "${{ steps.properties.outputs.k8s_version }}"
Expand Down
16 changes: 10 additions & 6 deletions test/e2e/actions/project_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ func ProjectCreationFlow(userData *model.TestDataProvider) {
}

func PrepareOperatorConfigurations(userData *model.TestDataProvider) manager.Manager {
By(fmt.Sprintf("Create namespace %s", userData.Resources.Namespace))
Expect(k8s.CreateNamespace(userData.Context, userData.K8SClient, userData.Resources.Namespace)).Should(Succeed())
k8s.CreateDefaultSecret(userData.Context, userData.K8SClient, config.DefaultOperatorGlobalKey, userData.Resources.Namespace)
if !userData.Resources.AtlasKeyAccessType.GlobalLevelKey {
CreateConnectionAtlasKey(userData)
}
CreateNamespaceAndSecrets(userData)
logPath := path.Join("output", userData.Resources.Namespace)
mgr, err := k8s.RunOperator(&k8s.Config{
Namespace: userData.Resources.Namespace,
Expand All @@ -52,3 +47,12 @@ func PrepareOperatorConfigurations(userData *model.TestDataProvider) manager.Man
Expect(err).NotTo(HaveOccurred())
return mgr
}

func CreateNamespaceAndSecrets(userData *model.TestDataProvider) {
By(fmt.Sprintf("Create namespace %s", userData.Resources.Namespace))
Expect(k8s.CreateNamespace(userData.Context, userData.K8SClient, userData.Resources.Namespace)).Should(Succeed())
k8s.CreateDefaultSecret(userData.Context, userData.K8SClient, config.DefaultOperatorGlobalKey, userData.Resources.Namespace)
if !userData.Resources.AtlasKeyAccessType.GlobalLevelKey {
CreateConnectionAtlasKey(userData)
}
}
177 changes: 21 additions & 156 deletions test/e2e/actions/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@ import (
"strconv"
"time"

"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/k8s"

v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"

"k8s.io/apimachinery/pkg/types"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
"go.mongodb.org/atlas/mongodbatlas"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
kube "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions/kube"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/api/atlas"
appclient "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/appclient"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/helm"
kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/config"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/k8s"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/utils"
)
Expand Down Expand Up @@ -133,16 +128,6 @@ func WaitDeploymentWithoutGenerationCheck(data *model.TestDataProvider) {
}
}

func WaitProject(data *model.TestDataProvider, generation int) {
EventuallyWithOffset(1, kube.ProjectReadyCondition(data), "25m", "10s").Should(Equal("True"), "Kubernetes resource: Project status `Ready` should be 'True'")
gen, err := k8s.GetProjectObservedGeneration(data.Context, data.K8SClient, data.Resources.Namespace, data.Resources.Project.GetK8sMetaName())
Expect(err).ToNot(HaveOccurred())
ExpectWithOffset(1, gen).Should(Equal(generation), "Kubernetes resource: Generation should be upgraded")
atlasProject, err := kube.GetProjectResource(data)
Expect(err).ShouldNot(HaveOccurred())
ExpectWithOffset(1, atlasProject.Status.ID).ShouldNot(BeNil(), "Kubernetes resource: Project status should have non-empty ID field")
}

func WaitProjectWithoutGenerationCheck(data *model.TestDataProvider) {
EventuallyWithOffset(1, func() string {
return kube.ProjectReadyCondition(data)
Expand All @@ -163,13 +148,6 @@ func WaitTestApplication(data *model.TestDataProvider, ns, labelKey, labelValue
EventuallyWithOffset(1, isAppRunning(), "2m", "10s").Should(BeTrue(), "Test application should be running")
}

func CheckIfDeploymentExist(input model.UserInputs) func() bool {
return func() bool {
aClient := atlas.GetClientOrFail()
return aClient.IsDeploymentExist(input.ProjectID, input.Deployments[0].Spec.DeploymentSpec.Name)
}
}

func CheckIfUsersExist(input model.UserInputs) func() bool {
return func() bool {
atlasClient, err := atlas.AClient()
Expand Down Expand Up @@ -269,18 +247,6 @@ func CompareServerlessSpec(requested model.DeploymentSpec, created mongodbatlas.
Expect(created.GroupID).To(Not(BeEmpty()))
}

func SaveK8sResourcesTo(resources []string, ns string, destination string) {
for _, resource := range resources {
data := kubecli.GetYamlResource(resource, ns)
path := fmt.Sprintf("output/%s/%s.yaml", destination, resource)
utils.SaveToFile(path, data)
}
}

func SaveK8sResources(resources []string, ns string) {
SaveK8sResourcesTo(resources, ns, ns)
}

func SaveProjectsToFile(ctx context.Context, k8sClient client.Client, ns string) error {
yaml, err := k8s.ProjectListYaml(ctx, k8sClient, ns)
if err != nil {
Expand Down Expand Up @@ -335,21 +301,17 @@ func SaveUsersToFile(ctx context.Context, k8sClient client.Client, ns string) er

func SaveTestAppLogs(input model.UserInputs) {
for _, user := range input.Users {
utils.SaveToFile(
fmt.Sprintf("output/%s/testapp-describe-%s.txt", input.Namespace, user.Spec.Username),
kubecli.DescribeTestApp(config.TestAppLabelPrefix+user.Spec.Username, input.Namespace),
)
testAppName := fmt.Sprintf("test-app-%s", user.Spec.Username)
bytes, err := k8s.GetPodLogsByDeployment(testAppName, input.Namespace, corev1.PodLogOptions{})
Expect(err).ToNot(HaveOccurred())

utils.SaveToFile(
fmt.Sprintf("output/%s/testapp-logs-%s.txt", input.Namespace, user.Spec.Username),
kubecli.GetLogs(config.TestAppLabelPrefix+user.Spec.Username, input.Namespace),
bytes,
)
}
}

func SaveDeploymentDump(input model.UserInputs) {
kubecli.GetDeploymentDump(fmt.Sprintf("output/%s/dump", input.Namespace))
}

func CheckUsersAttributes(data *model.TestDataProvider) {
input := data.Resources
aClient := atlas.GetClientOrFail()
Expand Down Expand Up @@ -487,85 +449,6 @@ func CreateConnectionAtlasKey(data *model.TestDataProvider) {
})
}

func createConnectionAtlasKeyFrom(data *model.TestDataProvider, key *mongodbatlas.APIKey) {
By("Change resources depends on AtlasKey and create key", func() {
if data.Resources.AtlasKeyAccessType.GlobalLevelKey {
err := k8s.CreateSecret(data.Context, data.K8SClient, key.PublicKey, key.PrivateKey, config.DefaultOperatorGlobalKey, data.Resources.Namespace)
Expect(err).NotTo(HaveOccurred())
} else {
err := k8s.CreateSecret(data.Context, data.K8SClient, key.PublicKey, key.PrivateKey, data.Resources.KeyName, data.Resources.Namespace)
Expect(err).NotTo(HaveOccurred())
}
})
}

func recreateAtlasKeyIfNeed(data *model.TestDataProvider) {
if !data.Resources.AtlasKeyAccessType.IsFullAccess() {
aClient, err := atlas.AClient()
Expect(err).ShouldNot(HaveOccurred())
globalKey, err := aClient.AddKeyWithAccessList(data.Resources.ProjectID, data.Resources.AtlasKeyAccessType.Roles, data.Resources.AtlasKeyAccessType.Whitelist)
Expect(err).ShouldNot(HaveOccurred())
Expect(globalKey.PublicKey).ShouldNot(BeEmpty())
Expect(globalKey.PrivateKey).ShouldNot(BeEmpty())
data.Resources.AtlasKeyAccessType.GlobalKeyAttached = globalKey

k8s.DeleteKey(data.Context, data.K8SClient, data.Resources.KeyName, data.Resources.Namespace)
createConnectionAtlasKeyFrom(data, globalKey)
}
}

func DeployProjectAndWait(data *model.TestDataProvider, generation int) {
By("Create users resources: keys, project", func() {
CreateConnectionAtlasKey(data)
kubecli.Apply(data.Resources.ProjectPath, "-n", data.Resources.Namespace)
By("Wait project creation and get projectID", func() {
WaitProject(data, generation)
atlasProject, err := kube.GetProjectResource(data)
Expect(err).Should(BeNil(), "Error has Occurred")
data.Resources.ProjectID = atlasProject.Status.ID
Expect(data.Resources.ProjectID).ShouldNot(BeEmpty())
})
recreateAtlasKeyIfNeed(data)
})
}

func DeployDeployment(data *model.TestDataProvider) {
if len(data.Resources.Deployments) > 0 {
By("Create deployment", func() {
kubecli.Apply(data.Resources.Deployments[0].DeploymentFileName(data.Resources), "-n", data.Resources.Namespace)
})
By("Wait deployment creation", func() {
WaitDeploymentWithoutGenerationCheck(data)
})
By("check deployment Attribute", func() {
aClient, err := atlas.AClient()
Expect(err).NotTo(HaveOccurred())
deployment := aClient.GetDeployment(data.Resources.ProjectID, data.Resources.Deployments[0].Spec.DeploymentSpec.Name)
CompareDeploymentsSpec(data.Resources.Deployments[0].Spec, deployment)
})
}
}

func DeployUsers(data *model.TestDataProvider) {
By("create users", func() {
kubecli.Apply(data.Resources.GetResourceFolder()+"/user/", "-n", data.Resources.Namespace)
})
By("check database users Attributes", func() {
Eventually(CheckIfUsersExist(data.Resources), "2m", "10s").Should(BeTrue())
CheckUsersAttributes(data)
})
By("Deploy application for user", func() {
CheckUsersCanUseApp(data)
})
}

// DeployUserResourcesAction deploy all user resources, wait, and check results
func DeployUserResourcesAction(data *model.TestDataProvider) {
DeployProjectAndWait(data, 1)
DeployDeployment(data)
DeployUsers(data)
}

func DeleteDBUsersApps(data model.TestDataProvider) {
By("Delete dbusers applications", func() {
for _, user := range data.Resources.Users {
Expand All @@ -574,34 +457,6 @@ func DeleteDBUsersApps(data model.TestDataProvider) {
})
}

func DeleteUserResources(data *model.TestDataProvider) {
DeleteUserResourcesDeployment(data)
DeleteUserResourcesProject(data)
}

func DeleteUserResourcesDeployment(data *model.TestDataProvider) {
By("Delete deployment", func() {
kubecli.Delete(data.Resources.Deployments[0].DeploymentFileName(data.Resources), "-n", data.Resources.Namespace)
Eventually(
CheckIfDeploymentExist(data.Resources),
"10m", "1m",
).Should(BeFalse(), "Deployment should be deleted from Atlas")
})
}

func DeleteUserResourcesProject(data *model.TestDataProvider) {
By("Delete project", func() {
kubecli.Delete(data.Resources.ProjectPath, "-n", data.Resources.Namespace)
Eventually(
func(g Gomega) bool {
aClient := atlas.GetClientOrFail()
return aClient.IsProjectExists(g, data.Resources.ProjectID)
},
"5m", "20s",
).Should(BeFalse(), "Project should be deleted from Atlas")
})
}

func DeleteTestDataProject(data *model.TestDataProvider) {
By("Delete project", func() {
Expect(data.K8SClient.Get(data.Context, types.NamespacedName{Name: data.Project.Name, Namespace: data.Project.Namespace}, data.Project)).Should(Succeed())
Expand Down Expand Up @@ -648,6 +503,16 @@ func DeleteTestDataDeployments(data *model.TestDataProvider) {
})
}

func DeleteTestDataUsers(data *model.TestDataProvider) {
By("Delete Users", func() {
for _, user := range data.Users {
Expect(data.K8SClient.Get(data.Context, types.NamespacedName{Name: data.Project.Name, Namespace: data.Project.Namespace}, data.Project)).Should(Succeed())
Expect(data.K8SClient.Get(data.Context, types.NamespacedName{Name: user.Name, Namespace: user.Namespace}, user)).Should(Succeed())
Expect(data.K8SClient.Delete(data.Context, user)).Should(Succeed())
}
})
}

func DeleteAtlasGlobalKeyIfExist(data model.TestDataProvider) {
if data.Resources.AtlasKeyAccessType.GlobalLevelKey {
By("Delete Global API key for test", func() {
Expand Down
6 changes: 0 additions & 6 deletions test/e2e/alert_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package e2e_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
"k8s.io/apimachinery/pkg/types"

v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
Expand All @@ -12,18 +11,13 @@ import (
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/api/atlas"
kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/data"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
)

var _ = Describe("Alert configuration tests", Label("alert-config"), func() {
var testData *model.TestDataProvider

_ = BeforeEach(func() {
Eventually(kubecli.GetVersionOutput()).Should(Say(K8sVersion))
})

_ = AfterEach(func() {
GinkgoWriter.Write([]byte("\n"))
GinkgoWriter.Write([]byte("===============================================\n"))
Expand Down
5 changes: 0 additions & 5 deletions test/e2e/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ package e2e_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"

"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions"
kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/data"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
)

var _ = Describe("Annotations base test.", Label("deployment-annotations-ns"), func() {
var testData *model.TestDataProvider

BeforeEach(func() {
Eventually(kubecli.GetVersionOutput()).Should(Say(K8sVersion))
})
AfterEach(func() {
GinkgoWriter.Write([]byte("\n"))
GinkgoWriter.Write([]byte("===============================================\n"))
Expand Down
6 changes: 0 additions & 6 deletions test/e2e/auditing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ package e2e_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"

v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions"
kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/data"
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
)

var _ = Describe("UserLogin", Label("auditing"), func() {
var testData *model.TestDataProvider

_ = BeforeEach(func() {
Eventually(kubecli.GetVersionOutput()).Should(Say(K8sVersion))
})

_ = AfterEach(func() {
GinkgoWriter.Write([]byte("\n"))
GinkgoWriter.Write([]byte("===============================================\n"))
Expand Down
Loading