Skip to content

Commit 33c0748

Browse files
authored
Cloudp-80268 e2e initial (#84)
1 parent 8a36b59 commit 33c0748

File tree

22 files changed

+707
-9
lines changed

22 files changed

+707
-9
lines changed

.github/actions/deploy/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cd - && kustomize build config/dev | kubectl apply -f -
1515

1616
# Ensuring the Atlas credentials Secret
1717
kubectl delete secrets my-atlas-key --ignore-not-found -n "${ns}"
18-
kubectl create secret generic my-atlas-key --from-literal="orgId=${INPUT_ATLAS_ORG_ID}" --from-literal="publicApiKey=${INPUT_ATLAS_PUBLIC_KEY}" --from-literal="privateApiKey=${INPUT_ATLAS_PRIVATE_KEY}" -n mongodb-atlas-kubernetes-system
18+
kubectl create secret generic my-atlas-key --from-literal="orgId=${INPUT_ATLAS_ORG_ID}" --from-literal="publicApiKey=${INPUT_ATLAS_PUBLIC_KEY}" --from-literal="privateApiKey=${INPUT_ATLAS_PRIVATE_KEY}" -n "${ns}"
1919

2020
# Wait for the Operator to start
2121
cmd="while ! kubectl -n ${ns} get pods -l control-plane=controller-manager -o jsonpath={.items[0].status.phase} 2>/dev/null | grep -q Running ; do printf .; sleep 1; done"

.github/actions/gen-install-scripts/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ inputs:
44
IMAGE_URL:
55
description: "Operator image"
66
required: true
7+
ENV:
8+
description: "Kustomize patch name (enviroment configuration patch)"
9+
required: true
710
runs:
811
using: 'docker'
912
image: 'Dockerfile'
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/sh
22

33
target_dir="deploy"
4-
mkdir "${target_dir}"
4+
mkdir -p "${target_dir}"
55

66
# Generate configuration and save it to `all-in-one`
77
controller-gen crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
88
cd config/manager && kustomize edit set image controller="${INPUT_IMAGE_URL}"
9-
cd - && kustomize build config/default > "${target_dir}"/all-in-one.yaml
9+
cd - && kustomize build "config/${INPUT_ENV}" > "${target_dir}/all-in-one.yaml"
1010

11-
cat "${target_dir}"/all-in-one.yaml
11+
cat "${target_dir}/all-in-one.yaml"

.github/workflows/push-image.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# Triggered by Pull Request or Manually (from GitHub UI) events
2+
# TODO remove after removing scripts/e2e_local.sh
23

34
name: Publish image to Registry
45

56
on:
6-
pull_request:
7-
push:
8-
branches:
9-
- main
107
workflow_dispatch:
118

129
jobs:

.github/workflows/test.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- run: go version
2626
- name: Run testing
2727
run: CGO_ENABLED=0 go test -v $(go list ./pkg/...)
28+
2829
int-test:
2930
name: Integration tests
3031
runs-on: ubuntu-latest
@@ -43,3 +44,98 @@ jobs:
4344
ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }}
4445
ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
4546

47+
prepare-e2e:
48+
name: Prepare E2E configuration and image
49+
needs: [unit-test]
50+
runs-on: ubuntu-latest
51+
steps:
52+
53+
- name: Check out code
54+
uses: actions/checkout@v2.3.1
55+
56+
- name: Prepare tag
57+
id: prepare
58+
uses: ./.github/actions/set-tag
59+
60+
- name: Push Atlas Operator to Registry
61+
uses: docker/build-push-action@v1
62+
with:
63+
username: ${{ secrets.DOCKER_USERNAME }}
64+
password: ${{ secrets.DOCKER_PASSWORD }}
65+
repository: ${{ secrets.DOCKER_REPO }}
66+
registry: ${{ secrets.DOCKER_REGISTRY }}
67+
tags: ${{ steps.prepare.outputs.tag }}
68+
69+
e2e:
70+
name: E2E tests
71+
needs: prepare-e2e
72+
runs-on: ubuntu-latest
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
# k8s: ["1.17-kind", "1.19-kind", "1.17-opeshift"] # <supported platform version>-<platform>
77+
k8s: ["v1.18.15-kind"] # <K8sGitVersion>-<Platform>
78+
test: ["all-in-one"] # TODO refactor
79+
steps:
80+
81+
- name: Check out code
82+
uses: actions/checkout@v2.3.1
83+
84+
- name: Prepare tag
85+
id: prepare
86+
uses: ./.github/actions/set-tag
87+
88+
- name: Generate configuration for the tests
89+
uses: ./.github/actions/gen-install-scripts
90+
with:
91+
IMAGE_URL: ${{ secrets.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}
92+
ENV: dev
93+
94+
- name: Set properties
95+
id: properties
96+
run: |
97+
version=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $1}')
98+
platform=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $2}')
99+
echo "::set-output name=k8s_version::$version"
100+
echo "::set-output name=k8s_platform::$platform"
101+
102+
# run if platform = kind #TODO
103+
- name: Create k8s Kind Cluster
104+
if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }}
105+
uses: helm/kind-action@v1.1.0
106+
with:
107+
node_image: kindest/node:${{ steps.properties.outputs.k8s_version }}
108+
cluster_name: ${{ matrix.k8s }}
109+
110+
- name: Setup Go
111+
if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }}
112+
uses: actions/setup-go@v2
113+
with:
114+
go-version: '1.15.6'
115+
116+
- name: Install MongoCLI
117+
run: |
118+
sudo apt-get update
119+
sudo apt-get install -y mongocli
120+
mongocli --version
121+
122+
- name: Run e2e test
123+
if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }}
124+
env:
125+
MCLI_PUBLIC_API_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }}
126+
MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
127+
MCLI_ORG_ID: ${{ secrets.ATLAS_ORG_ID}}
128+
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/"
129+
K8S_PLATFORM: "${{ steps.properties.outputs.k8s_platform }}"
130+
K8S_VERSION: "${{ steps.properties.outputs.k8s_version }}"
131+
TEST_NAME: "${{ matrix.test }}"
132+
run: |
133+
kubectl version
134+
135+
go version
136+
go get github.com/onsi/ginkgo/ginkgo && \
137+
go get github.com/onsi/gomega/...
138+
ginkgo ./test/e2e -x -focus "${TEST_NAME}"
139+
140+
141+
# TODO if int test failed - stop e2e, add job for cleanup Atlas projects/clusters

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,9 @@ issues:
8686
linters:
8787
- gochecknoglobals
8888
- wrapcheck
89+
- path: test/e2e
90+
linters:
91+
- errcheck
92+
- stylecheck
8993
max-issues-per-linter: 0
9094
max-same-issues: 0

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ int-test: generate manifests ## Run integration tests
4040
test -f $(ENVTEST_ASSETS_DIR)/setup-envtest.sh || curl -sSLo $(ENVTEST_ASSETS_DIR)/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.0/hack/setup-envtest.sh
4141
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); ginkgo -v -p -nodes=4 ./test/int -coverprofile cover.out
4242

43+
.PHONY: e2e
44+
e2e: run-kind
45+
./scripts/e2e_local.sh
46+
4347
.PHONY: manager
4448
manager: generate fmt vet ## Build manager binary
4549
go build -o bin/manager main.go

config/dev/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
namespace: mongodb-atlas-kubernetes-system
22

33
resources:
44
- ../default

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ require (
99
github.com/google/go-cmp v0.5.4
1010
github.com/mongodb-forks/digest v1.0.2
1111
github.com/onsi/ginkgo v1.14.2
12+
github.com/pborman/uuid v1.2.0
1213
github.com/onsi/gomega v1.10.5
1314
github.com/stretchr/testify v1.7.0
1415
go.mongodb.org/atlas v0.7.1
1516
go.uber.org/multierr v1.6.0 // indirect
1617
go.uber.org/zap v1.16.0
18+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
1719
k8s.io/api v0.18.6
1820
k8s.io/apimachinery v0.18.6
1921
k8s.io/client-go v0.18.6

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
265265
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
266266
github.com/openlyinc/pointy v1.1.2 h1:LywVV2BWC5Sp5v7FoP4bUD+2Yn5k0VNeRbU5vq9jUMY=
267267
github.com/openlyinc/pointy v1.1.2/go.mod h1:w2Sytx+0FVuMKn37xpXIAyBNhFNBIJGR/v2m7ik1WtM=
268+
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
268269
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
269270
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
270271
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=

0 commit comments

Comments
 (0)