Skip to content

Commit 6fe2ff0

Browse files
authored
CLOUDP-153400: Remove kubectl (#841)
* Remove kubectl
1 parent 36ed2e7 commit 6fe2ff0

27 files changed

+264
-485
lines changed

.github/workflows/test-e2e.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ jobs:
193193
wget https://github.com/operator-framework/operator-sdk/releases/download/v1.22.0/operator-sdk_linux_amd64 -q
194194
chmod +x operator-sdk_linux_amd64 && sudo mv operator-sdk_linux_amd64 /usr/local/bin/operator-sdk
195195
operator-sdk version
196+
- name: Print kubectl version
197+
run: |
198+
kubectl version
196199
- name: Install CRDs if needed
197200
if: ${{ !( matrix.test == 'helm-update' || matrix.test == 'helm-wide' || matrix.test == 'bundle-test' ) }}
198201
run: |
@@ -203,7 +206,7 @@ jobs:
203206
MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
204207
MCLI_ORG_ID: ${{ secrets.ATLAS_ORG_ID}}
205208
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/"
206-
IMAGE_URL: ${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}
209+
IMAGE_URL: "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}"
207210
BUNDLE_IMAGE: "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_BUNDLES_REPO}}:${{ steps.prepare.outputs.tag }}"
208211
K8S_PLATFORM: "${{ steps.properties.outputs.k8s_platform }}"
209212
K8S_VERSION: "${{ steps.properties.outputs.k8s_version }}"

test/e2e/actions/project_flow.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ func ProjectCreationFlow(userData *model.TestDataProvider) {
3131
}
3232

3333
func PrepareOperatorConfigurations(userData *model.TestDataProvider) manager.Manager {
34-
By(fmt.Sprintf("Create namespace %s", userData.Resources.Namespace))
35-
Expect(k8s.CreateNamespace(userData.Context, userData.K8SClient, userData.Resources.Namespace)).Should(Succeed())
36-
k8s.CreateDefaultSecret(userData.Context, userData.K8SClient, config.DefaultOperatorGlobalKey, userData.Resources.Namespace)
37-
if !userData.Resources.AtlasKeyAccessType.GlobalLevelKey {
38-
CreateConnectionAtlasKey(userData)
39-
}
34+
CreateNamespaceAndSecrets(userData)
4035
logPath := path.Join("output", userData.Resources.Namespace)
4136
mgr, err := k8s.RunOperator(&k8s.Config{
4237
Namespace: userData.Resources.Namespace,
@@ -52,3 +47,12 @@ func PrepareOperatorConfigurations(userData *model.TestDataProvider) manager.Man
5247
Expect(err).NotTo(HaveOccurred())
5348
return mgr
5449
}
50+
51+
func CreateNamespaceAndSecrets(userData *model.TestDataProvider) {
52+
By(fmt.Sprintf("Create namespace %s", userData.Resources.Namespace))
53+
Expect(k8s.CreateNamespace(userData.Context, userData.K8SClient, userData.Resources.Namespace)).Should(Succeed())
54+
k8s.CreateDefaultSecret(userData.Context, userData.K8SClient, config.DefaultOperatorGlobalKey, userData.Resources.Namespace)
55+
if !userData.Resources.AtlasKeyAccessType.GlobalLevelKey {
56+
CreateConnectionAtlasKey(userData)
57+
}
58+
}

test/e2e/actions/steps.go

Lines changed: 21 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
146131
func 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-
173151
func 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-
284250
func 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

336302
func 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-
353315
func 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-
569452
func 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-
605460
func 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+
651516
func DeleteAtlasGlobalKeyIfExist(data model.TestDataProvider) {
652517
if data.Resources.AtlasKeyAccessType.GlobalLevelKey {
653518
By("Delete Global API key for test", func() {

test/e2e/alert_config_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package e2e_test
33
import (
44
. "github.com/onsi/ginkgo/v2"
55
. "github.com/onsi/gomega"
6-
. "github.com/onsi/gomega/gbytes"
76
"k8s.io/apimachinery/pkg/types"
87

98
v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
@@ -12,18 +11,13 @@ import (
1211
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr"
1312
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions"
1413
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/api/atlas"
15-
kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
1614
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/data"
1715
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
1816
)
1917

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

23-
_ = BeforeEach(func() {
24-
Eventually(kubecli.GetVersionOutput()).Should(Say(K8sVersion))
25-
})
26-
2721
_ = AfterEach(func() {
2822
GinkgoWriter.Write([]byte("\n"))
2923
GinkgoWriter.Write([]byte("===============================================\n"))

test/e2e/annotations_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@ package e2e_test
33
import (
44
. "github.com/onsi/ginkgo/v2"
55
. "github.com/onsi/gomega"
6-
. "github.com/onsi/gomega/gbytes"
76

87
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions"
9-
kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
108
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/data"
119
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
1210
)
1311

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

17-
BeforeEach(func() {
18-
Eventually(kubecli.GetVersionOutput()).Should(Say(K8sVersion))
19-
})
2015
AfterEach(func() {
2116
GinkgoWriter.Write([]byte("\n"))
2217
GinkgoWriter.Write([]byte("===============================================\n"))

test/e2e/auditing_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@ package e2e_test
33
import (
44
. "github.com/onsi/ginkgo/v2"
55
. "github.com/onsi/gomega"
6-
. "github.com/onsi/gomega/gbytes"
76

87
v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
98
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
109
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr"
1110
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions"
12-
kubecli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli/kubecli"
1311
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/data"
1412
"github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/model"
1513
)
1614

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

20-
_ = BeforeEach(func() {
21-
Eventually(kubecli.GetVersionOutput()).Should(Say(K8sVersion))
22-
})
23-
2418
_ = AfterEach(func() {
2519
GinkgoWriter.Write([]byte("\n"))
2620
GinkgoWriter.Write([]byte("===============================================\n"))

0 commit comments

Comments
 (0)