Skip to content

Commit cc24191

Browse files
authored
CLOUDP-84848-bundle (#186)
1 parent 51d1614 commit cc24191

File tree

6 files changed

+200
-23
lines changed

6 files changed

+200
-23
lines changed

.github/workflows/test.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ jobs:
8282
env:
8383
# uncomment the below for local testing
8484
# DOCKER_REPO: ${{ env.DOCKER_REGISTRY }}/mongodb-atlas-kubernetes-operator
85+
DOCKER_REGISTRY: docker.io
86+
DOCKER_BUNDLES_REPO: mongodbinternal/mongodb-atlas-kubernetes-bundles-prerelease
8587
DOCKER_REPO: mongodb/mongodb-atlas-kubernetes-operator-prerelease
8688
strategy:
8789
fail-fast: false
8890
matrix:
8991
# k8s: ["1.17-kind", "1.19-kind", "1.17-opeshift"] # <supported platform version>-<platform>
9092
k8s: ["v1.18.15-kind"] # <K8sGitVersion>-<Platform>
91-
test: ["cluster-ns", "cluster-wide"]
93+
test: ["cluster-ns", "cluster-wide", "bundle-test"]
9294
steps:
9395

9496
- name: Check out code
@@ -105,6 +107,20 @@ jobs:
105107
VERSION: ${{ steps.prepare.outputs.tag }}
106108
ENV: dev
107109

110+
- name: Change path for the test
111+
run: |
112+
sed -i -e 's/cloud.mongodb.com/cloud-qa.mongodb.com/' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
113+
114+
- name: Push bundle-image for the test
115+
uses: docker/build-push-action@v1
116+
with:
117+
username: ${{ secrets.DOCKER_USERNAME }}
118+
password: ${{ secrets.DOCKER_PASSWORD }}
119+
repository: ${{ env.DOCKER_BUNDLES_REPO }}
120+
registry: ${{ env.DOCKER_REGISTRY }}
121+
tags: ${{ steps.prepare.outputs.tag }}
122+
dockerfile: bundle.Dockerfile
123+
108124
- name: Set properties
109125
id: properties
110126
run: |
@@ -135,13 +151,20 @@ jobs:
135151
sudo apt-get install -y mongocli
136152
mongocli --version
137153
154+
- name: Install operator-sdk-v1.4.2
155+
run: |
156+
wget https://github.com/operator-framework/operator-sdk/releases/download/v1.4.2/operator-sdk_linux_amd64
157+
chmod +x operator-sdk_linux_amd64 && sudo mv operator-sdk_linux_amd64 /usr/local/bin/operator-sdk
158+
operator-sdk version
159+
138160
- name: Run e2e test
139161
if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }}
140162
env:
141163
MCLI_PUBLIC_API_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }}
142164
MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
143165
MCLI_ORG_ID: ${{ secrets.ATLAS_ORG_ID}}
144166
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/"
167+
BUNDLE_IMAGE: "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_BUNDLES_REPO}}:${{ steps.prepare.outputs.tag }}"
145168
K8S_PLATFORM: "${{ steps.properties.outputs.k8s_platform }}"
146169
K8S_VERSION: "${{ steps.properties.outputs.k8s_version }}"
147170
TEST_NAME: "${{ matrix.test }}"

scripts/e2e_local.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@ public_key=$(grep "ATLAS_PUBLIC_KEY" .actrc | cut -d "=" -f 2)
77
private_key=$(grep "ATLAS_PRIVATE_KEY" .actrc | cut -d "=" -f 2)
88
org_id=$(grep "ATLAS_ORG_ID" .actrc | cut -d "=" -f 2)
99
# this is the format how it's pushed by act -j build-push
10-
image=$(grep "DOCKER_REGISTRY" .env | cut -d "=" -f 2)/mongodb-atlas-kubernetes-operator:$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)
10+
image=$(grep "DOCKER_REGISTRY" .env | cut -d "=" -f 2)/$(grep "DOCKER_REPO" .env | cut -d "=" -f 2):$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)
1111

12-
export MCLI_OPS_MANAGER_URL="https://cloud-qa.mongodb.com/"
13-
export MCLI_PUBLIC_API_KEY="${public_key}"
14-
export MCLI_PRIVATE_API_KEY="${private_key}"
15-
export MCLI_ORG_ID="${org_id}"
1612
export INPUT_IMAGE_URL="${image}"
1713
export INPUT_ENV=dev
18-
1914
./.github/actions/gen-install-scripts/entrypoint.sh
15+
# TODO temporary change line
16+
sed -i -e 's/cloud.mongodb.com/cloud-qa.mongodb.com/' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
2017

2118
docker build -t "${image}" .
2219
docker push "${image}"
2320

21+
#bundles
22+
bundle_image=$(grep "DOCKER_REGISTRY" .env | cut -d "=" -f 2)/$(grep "DOCKER_BUNDLES_REPO" .env | cut -d "=" -f 2):$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD) #Registry is nessary
23+
export BUNDLE_IMAGE="${bundle_image}"
24+
docker build -f bundle.Dockerfile -t "${bundle_image}" .
25+
docker push "${bundle_image}"
26+
27+
export MCLI_OPS_MANAGER_URL="https://cloud-qa.mongodb.com/"
28+
export MCLI_PUBLIC_API_KEY="${public_key}"
29+
export MCLI_PRIVATE_API_KEY="${private_key}"
30+
export MCLI_ORG_ID="${org_id}"
2431
ginkgo --focus "${focus_key}" -nodes=3 -x -v test/e2e/

test/e2e/bundle_test.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package e2e_test
2+
3+
import (
4+
"os"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
9+
. "github.com/onsi/gomega/gbytes"
10+
"github.com/onsi/gomega/gexec"
11+
12+
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli"
13+
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kube"
14+
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/mongocli"
15+
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/config"
16+
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
17+
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/utils"
18+
)
19+
20+
var _ = Describe("[bundle-test] User can", func() {
21+
var userSpec model.UserInputs
22+
var imageURL string
23+
24+
var _ = BeforeEach(func() {
25+
imageURL = os.Getenv("BUNDLE_IMAGE")
26+
Expect(imageURL).ShouldNot(BeEmpty(), "SetUP BUNDLE_IMAGE")
27+
})
28+
var _ = AfterEach(func() {
29+
By("Atfer each.", func() {
30+
if CurrentGinkgoTestDescription().Failed {
31+
GinkgoWriter.Write([]byte("Resources wasn't clean"))
32+
utils.SaveToFile(
33+
"output/operator-logs.txt",
34+
kube.GetManagerLogs(config.DefaultOperatorNS),
35+
)
36+
SaveK8sResources(
37+
[]string{"deploy"},
38+
"default",
39+
)
40+
SaveK8sResources(
41+
[]string{"atlasclusters", "atlasdatabaseusers", "atlasprojects"},
42+
userSpec.Namespace,
43+
)
44+
} else {
45+
Eventually(kube.DeleteNamespace(userSpec.Namespace)).Should(Say("deleted"), "Cant delete namespace after testing")
46+
}
47+
})
48+
})
49+
50+
It("User can install", func() {
51+
Eventually(cli.Execute("operator-sdk", "olm", "install"), "5m").Should(gexec.Exit(0))
52+
Eventually(cli.Execute("operator-sdk", "run", "bundle", imageURL), "5m").Should(gexec.Exit(0))
53+
54+
By("User creates configuration for a new Project and Cluster", func() {
55+
userSpec = model.NewUserInputs(
56+
"only-key",
57+
[]model.DBUser{
58+
*model.NewDBUser("reader").
59+
WithSecretRef("dbuser-secret-u1").
60+
AddRole("readWrite", "Ships", ""),
61+
},
62+
)
63+
64+
utils.SaveToFile(
65+
userSpec.ProjectPath,
66+
model.NewProject().
67+
ProjectName(userSpec.ProjectName).
68+
SecretRef(userSpec.KeyName).
69+
WithIpAccess("0.0.0.0/0", "everyone").
70+
CompleteK8sConfig(userSpec.K8sProjectName),
71+
)
72+
userSpec.Clusters = append(userSpec.Clusters, model.LoadUserClusterConfig(config.ClusterSample))
73+
userSpec.Clusters[0].Spec.Project.Name = userSpec.K8sProjectName
74+
userSpec.Clusters[0].ObjectMeta.Name = "cluster-from-bundle"
75+
utils.SaveToFile(
76+
userSpec.Clusters[0].ClusterFileName(userSpec),
77+
utils.JSONToYAMLConvert(userSpec.Clusters[0]),
78+
)
79+
})
80+
81+
By("Apply configuration", func() {
82+
kube.CreateNamespace(userSpec.Namespace)
83+
kube.CreateApiKeySecret(userSpec.KeyName, userSpec.Namespace)
84+
kube.Apply(userSpec.GetResourceFolder(), "-n", userSpec.Namespace)
85+
for _, user := range userSpec.Users {
86+
user.SaveConfigurationTo(userSpec.ProjectPath)
87+
kube.CreateUserSecret(user.Spec.PasswordSecret.Name, userSpec.Namespace)
88+
}
89+
kube.Apply(userSpec.GetResourceFolder()+"/user/", "-n", userSpec.Namespace)
90+
})
91+
92+
By("Wait project creation", func() {
93+
waitProject(userSpec, "1")
94+
userSpec.ProjectID = kube.GetProjectResource(userSpec.Namespace, userSpec.K8sFullProjectName).Status.ID
95+
})
96+
97+
By("Wait cluster creation", func() {
98+
waitCluster(userSpec, "1")
99+
})
100+
101+
By("Check attributes", func() {
102+
uCluster := mongocli.GetClustersInfo(userSpec.ProjectID, userSpec.Clusters[0].Spec.Name)
103+
compareClustersSpec(userSpec.Clusters[0].Spec, uCluster)
104+
})
105+
106+
By("check database users Attibutes", func() {
107+
Eventually(checkIfUsersExist(userSpec), "2m", "10s").Should(BeTrue())
108+
checkUsersAttributes(userSpec)
109+
})
110+
111+
By("Deploy application for user", func() {
112+
// kube apply application
113+
// send data
114+
// retrieve data
115+
checkUsersCanUseApplication(30005, userSpec)
116+
})
117+
118+
By("Delete cluster", func() {
119+
kube.Delete(userSpec.Clusters[0].ClusterFileName(userSpec), "-n", userSpec.Namespace)
120+
Eventually(
121+
checkIfClusterExist(userSpec),
122+
"10m", "1m",
123+
).Should(BeFalse(), "Cluster should be deleted from Atlas")
124+
})
125+
126+
By("Delete project", func() {
127+
kube.Delete(userSpec.ProjectPath, "-n", userSpec.Namespace)
128+
Eventually(
129+
func() bool {
130+
return mongocli.IsProjectInfoExist(userSpec.ProjectID)
131+
},
132+
"5m", "20s",
133+
).Should(BeFalse(), "Project should be deleted from Atlas")
134+
})
135+
})
136+
})

test/e2e/configuration_test.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
. "github.com/onsi/gomega/gbytes"
1212

1313
appclient "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/appclient"
14-
helm "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/helm"
1514
kube "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kube"
1615
mongocli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/mongocli"
1716

@@ -170,20 +169,7 @@ func mainCycle(clusterConfigurationFile string, resources model.UserInputs, port
170169
// kube apply application
171170
// send data
172171
// retrieve data
173-
for i, user := range resources.Users { // TODO in parallel(?)
174-
// data
175-
port := strconv.Itoa(i + portGroup)
176-
key := port
177-
data := fmt.Sprintf("{\"key\":\"%s\",\"shipmodel\":\"heavy\",\"hp\":150}", key)
178-
179-
helm.InstallTestApplication(resources, user, port)
180-
waitTestApplication(resources.Namespace, "app=test-app-"+user.Spec.Username)
181-
182-
app := appclient.NewTestAppClient(port)
183-
Expect(app.Get("")).Should(Equal("It is working"))
184-
Expect(app.Post(data)).ShouldNot(HaveOccurred())
185-
Expect(app.Get("/mongo/" + key)).Should(Equal(data))
186-
}
172+
checkUsersCanUseApplication(portGroup, resources)
187173
})
188174

189175
By("Update cluster\n", func() {

test/e2e/model/user_input.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ func (u *UserInputs) GetOperatorFolder() string {
5757
func (u *UserInputs) GetResourceFolder() string {
5858
return filepath.Dir(u.ProjectPath)
5959
}
60+
61+
func (u *UserInputs) GetUsersFolder() string {
62+
return filepath.Join(u.GetResourceFolder(), "user")
63+
}

test/e2e/user_input_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package e2e_test
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
7+
"strconv"
68

79
. "github.com/onsi/gomega"
810
. "github.com/onsi/gomega/gstruct"
911
"go.mongodb.org/atlas/mongodbatlas"
1012

13+
appclient "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/appclient"
14+
helm "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/helm"
1115
kube "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kube"
1216
mongocli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/mongocli"
1317
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
@@ -31,7 +35,7 @@ func waitCluster(input model.UserInputs, generation string) {
3135
).Should(Equal("IDLE"), "Atlas: Cluster status should be IDLE")
3236
}
3337

34-
func waitProject(input model.UserInputs, generation string) {
38+
func waitProject(input model.UserInputs, generation string) { //nolint:unparam // have cases only with generation=1
3539
EventuallyWithOffset(1, kube.GetStatusCondition(input.Namespace, input.K8sFullProjectName)).Should(Equal("True"), "Kubernetes resource: Project status `Ready` should be True")
3640
EventuallyWithOffset(1, kube.GetGeneration(input.Namespace, input.K8sFullProjectName)).Should(Equal(generation), "Kubernetes resource: Generation should be upgraded")
3741
EventuallyWithOffset(1, kube.GetProjectResource(input.Namespace, input.K8sFullProjectName).Status.ID).ShouldNot(BeNil(), "Kubernetes resource: Status has field with ProjectID")
@@ -137,3 +141,20 @@ func CopyKustomizeNamespaceOperator(input model.UserInputs) {
137141
)
138142
utils.SaveToFile(filepath.Join(fullPath, "kustomization.yaml"), data)
139143
}
144+
145+
func checkUsersCanUseApplication(portGroup int, userSpec model.UserInputs) {
146+
for i, user := range userSpec.Users { // TODO in parallel(?)/ingress
147+
// data
148+
port := strconv.Itoa(i + portGroup)
149+
key := port
150+
data := fmt.Sprintf("{\"key\":\"%s\",\"shipmodel\":\"heavy\",\"hp\":150}", key)
151+
152+
helm.InstallTestApplication(userSpec, user, port)
153+
waitTestApplication(userSpec.Namespace, "app=test-app-"+user.Spec.Username)
154+
155+
app := appclient.NewTestAppClient(port)
156+
Expect(app.Get("")).Should(Equal("It is working"))
157+
Expect(app.Post(data)).ShouldNot(HaveOccurred())
158+
Expect(app.Get("/mongo/" + key)).Should(Equal(data))
159+
}
160+
}

0 commit comments

Comments
 (0)