-
Notifications
You must be signed in to change notification settings - Fork 106
Cloudp-80268 e2e initial #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fd04284
initial e2e
leo-ri ad5c9d5
chore: linters check
leo-ri 45ccd9f
Merge branch 'main' into e2ev2
leo-ri 6715fc0
Merge
leo-ri b3fe94e
tests: e2e local workaround
leo-ri cd6a4d2
check
leo-ri 796d16f
merge test workflows
leo-ri 1c164fd
change timeout for update
leo-ri 2c427da
lint
leo-ri 3a2fa6e
Merge branch 'main' into CLOUDP-80268-e2e
leo-ri 66400de
fixed go mod
leo-ri c27f16a
conf update
leo-ri ac46abb
lint
leo-ri d07e5a1
Merge branch 'main' into CLOUDP-80268-e2e
leo-ri bdf7a75
gomod
leo-ri 2680c08
fix export, waiting project
leo-ri ab4e33b
lint + fixes
leo-ri b2807fc
split cli.go into kubectl and mongocli
leo-ri 7300d28
check kube statename
leo-ri 5da2bd0
move kube/mongocli to different package
leo-ri a3eb569
Update cli.go
leo-ri fcb5bb1
renaming
leo-ri 7dff40f
Merge branch 'main' into CLOUDP-80268-e2e
leo-ri 8c736e3
Merge branch 'main' into CLOUDP-80268-e2e
leo-ri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| #!/bin/sh | ||
|
|
||
| target_dir="deploy" | ||
| mkdir "${target_dir}" | ||
| mkdir -p "${target_dir}" | ||
|
|
||
| # Generate configuration and save it to `all-in-one` | ||
| controller-gen crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
| cd config/manager && kustomize edit set image controller="${INPUT_IMAGE_URL}" | ||
| cd - && kustomize build config/default > "${target_dir}"/all-in-one.yaml | ||
| cd - && kustomize build "config/${INPUT_ENV}" > "${target_dir}/all-in-one.yaml" | ||
|
|
||
| cat "${target_dir}"/all-in-one.yaml | ||
| cat "${target_dir}/all-in-one.yaml" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ jobs: | |
| - run: go version | ||
| - name: Run testing | ||
| run: CGO_ENABLED=0 go test -v $(go list ./pkg/...) | ||
|
|
||
| int-test: | ||
| name: Integration tests | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -43,3 +44,98 @@ jobs: | |
| ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }} | ||
| ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }} | ||
|
|
||
| prepare-e2e: | ||
| name: Prepare E2E configuration and image | ||
| needs: [unit-test] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
|
|
||
| - name: Check out code | ||
| uses: actions/checkout@v2.3.1 | ||
|
|
||
| - name: Prepare tag | ||
| id: prepare | ||
| uses: ./.github/actions/set-tag | ||
|
|
||
| - name: Push Atlas Operator to Registry | ||
| uses: docker/build-push-action@v1 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
| repository: ${{ secrets.DOCKER_REPO }} | ||
| registry: ${{ secrets.DOCKER_REGISTRY }} | ||
| tags: ${{ steps.prepare.outputs.tag }} | ||
|
|
||
| e2e: | ||
| name: E2E tests | ||
| needs: prepare-e2e | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| # k8s: ["1.17-kind", "1.19-kind", "1.17-opeshift"] # <supported platform version>-<platform> | ||
| k8s: ["v1.18.15-kind"] # <K8sGitVersion>-<Platform> | ||
| test: ["all-in-one"] # TODO refactor | ||
| steps: | ||
|
|
||
| - name: Check out code | ||
| uses: actions/checkout@v2.3.1 | ||
|
|
||
| - name: Prepare tag | ||
| id: prepare | ||
| uses: ./.github/actions/set-tag | ||
|
|
||
| - name: Generate configuration for the tests | ||
| uses: ./.github/actions/gen-install-scripts | ||
| with: | ||
| IMAGE_URL: ${{ secrets.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }} | ||
| ENV: dev | ||
|
|
||
| - name: Set properties | ||
| id: properties | ||
| run: | | ||
| version=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $1}') | ||
| platform=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $2}') | ||
| echo "::set-output name=k8s_version::$version" | ||
| echo "::set-output name=k8s_platform::$platform" | ||
|
|
||
| # run if platform = kind #TODO | ||
| - name: Create k8s Kind Cluster | ||
antonlisovenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }} | ||
| uses: helm/kind-action@v1.1.0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good to know there is an action for Kind already! |
||
| with: | ||
| node_image: kindest/node:${{ steps.properties.outputs.k8s_version }} | ||
| cluster_name: ${{ matrix.k8s }} | ||
|
|
||
| - name: Setup Go | ||
| if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }} | ||
| uses: actions/setup-go@v2 | ||
| with: | ||
| go-version: '1.15.6' | ||
|
|
||
| - name: Install MongoCLI | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y mongocli | ||
| mongocli --version | ||
|
|
||
| - name: Run e2e test | ||
| if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }} | ||
| env: | ||
| MCLI_PUBLIC_API_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }} | ||
| MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }} | ||
| MCLI_ORG_ID: ${{ secrets.ATLAS_ORG_ID}} | ||
| MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/" | ||
| K8S_PLATFORM: "${{ steps.properties.outputs.k8s_platform }}" | ||
| K8S_VERSION: "${{ steps.properties.outputs.k8s_version }}" | ||
| TEST_NAME: "${{ matrix.test }}" | ||
| run: | | ||
| kubectl version | ||
|
|
||
| go version | ||
| go get github.com/onsi/ginkgo/ginkgo && \ | ||
| go get github.com/onsi/gomega/... | ||
| ginkgo ./test/e2e -x -focus "${TEST_NAME}" | ||
|
|
||
|
|
||
| # TODO if int test failed - stop e2e, add job for cleanup Atlas projects/clusters | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
|
|
||
| namespace: mongodb-atlas-kubernetes-system | ||
|
|
||
| resources: | ||
| - ../default | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/bin/sh | ||
| act -j build-push | ||
|
|
||
| public_key=$(grep "ATLAS_PUBLIC_KEY" .actrc | cut -d "=" -f 2) | ||
| private_key=$(grep "ATLAS_PRIVATE_KEY" .actrc | cut -d "=" -f 2) | ||
| org_id=$(grep "ATLAS_ORG_ID" .actrc | cut -d "=" -f 2) | ||
| image=$(grep "DOCKER_REPO" .actrc | cut -d "=" -f 2):$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD) | ||
|
|
||
| export MCLI_OPS_MANAGER_URL="https://cloud-qa.mongodb.com/" | ||
| export MCLI_PUBLIC_API_KEY="${public_key}" | ||
| export MCLI_PRIVATE_API_KEY="${private_key}" | ||
| export MCLI_ORG_ID="${org_id}" | ||
| export INPUT_IMAGE_URL="${image}" | ||
| export INPUT_ENV=dev | ||
|
|
||
| ./.github/actions/gen-install-scripts/entrypoint.sh | ||
|
|
||
| ginkgo -v -x test/e2e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "os/exec" | ||
|
|
||
| . "github.com/onsi/ginkgo" | ||
| "github.com/onsi/gomega/gexec" | ||
| ) | ||
|
|
||
| func Execute(command string, args ...string) *gexec.Session { | ||
| // GinkgoWriter.Write([]byte("\n " + command + " " + strings.Join(args, " "))) // TODO for the local run only | ||
| cmd := exec.Command(command, args...) | ||
| session, _ := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
| return session | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package kube | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "encoding/json" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| . "github.com/onsi/gomega/gbytes" | ||
|
|
||
| v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" | ||
| cli "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/cli" | ||
| ) | ||
|
|
||
| // GenKubeVersion | ||
| func GenKubeVersion(fullVersion string) string { | ||
| version := strings.Split(fullVersion, ".") | ||
| return fmt.Sprintf("Major:\"%s\", Minor:\"%s\"", version[0], version[1]) | ||
| } | ||
|
|
||
| // GetPodStatus status.phase | ||
| func GetPodStatus(ns string) func() string { | ||
| return func() string { | ||
| session := cli.Execute("kubectl", "get", "pods", "-l", "control-plane=controller-manager", "-o", "jsonpath={.items[0].status.phase}", "-n", ns) | ||
| return string(session.Wait("1m").Out.Contents()) | ||
| } | ||
| } | ||
|
|
||
| // GetGeneration .status.observedGeneration | ||
| func GetGeneration(ns string) func() string { | ||
| return func() string { | ||
| session := cli.Execute("kubectl", "get", "atlascluster.atlas.mongodb.com/atlascluster-sample", "-n", ns, "-o", "jsonpath={.status.observedGeneration}") | ||
| return string(session.Wait("1m").Out.Contents()) | ||
| } | ||
| } | ||
|
|
||
| // GetStatusCondition .status.conditions.type=Ready.status | ||
| func GetStatusCondition(ns string, atlasname string) func() string { | ||
| return func() string { | ||
| session := cli.Execute("kubectl", "get", atlasname, "-n", ns, "-o", "jsonpath={.status.conditions[?(@.type=='Ready')].status}") | ||
| return string(session.Wait("1m").Out.Contents()) | ||
| } | ||
| } | ||
|
|
||
| // GetProjectResource | ||
| func GetProjectResource(namespace, rName string) v1.AtlasProject { | ||
| session := cli.Execute("kubectl", "get", rName, "-n", namespace, "-o", "json") | ||
| output := session.Wait("1m").Out.Contents() | ||
| var project v1.AtlasProject | ||
| ExpectWithOffset(1, json.Unmarshal(output, &project)).ShouldNot(HaveOccurred()) | ||
| return project | ||
| } | ||
|
|
||
| // GetClusterResource | ||
| func GetClusterResource(namespace, rName string) v1.AtlasCluster { | ||
| session := cli.Execute("kubectl", "get", rName, "-n", namespace, "-o", "json") | ||
| output := session.Wait("1m").Out.Contents() | ||
| var cluster v1.AtlasCluster | ||
| ExpectWithOffset(1, json.Unmarshal(output, &cluster)).ShouldNot(HaveOccurred()) | ||
| return cluster | ||
| } | ||
|
|
||
| func GetK8sClusterStateName(ns, rName string) func() string { | ||
| return func() string { | ||
| return GetClusterResource(ns, rName).Status.StateName | ||
| } | ||
| } | ||
|
|
||
| func DeleteNamespace(ns string) *Buffer { | ||
| session := cli.Execute("kubectl", "delete", "namespace", ns) | ||
| return session.Wait().Out | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems, that if we push the dev image here - there's no need in the "Publish image to Registry" workflow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed push trigger from build image workflow, but I would like to leave this workflow for a while until I am sure that e2e are stable