Skip to content

Commit

Permalink
update envtest and unify integration tests running
Browse files Browse the repository at this point in the history
  • Loading branch information
helderjs committed Oct 8, 2024
1 parent 07b7711 commit 1b4b76b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 44 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/test-int.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
fail-fast: false
matrix:
test: ["AtlasProject", "AtlasDeployment && !AtlasDeploymentSharding", "AtlasDatabaseUser", "AtlasDataFederation", "AtlasFederatedAuth", "AtlasDeploymentSharding", "AtlasStreams"]
path: [ "./test/int" ]
target: [ "test/int" ]
nodes: [12]
include:
- test: "ClusterWide"
path: "./test/int/clusterwide"
target: "test/int/clusterwide"
nodes: 1

steps:
Expand All @@ -47,17 +47,12 @@ jobs:
ATLAS_ORG_ID: ${{ secrets.ATLAS_ORG_ID }}
ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }}
ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
TEST_NAME: ${{ matrix.test }}
PARALLEL_NODES: ${{ matrix.nodes }}
GINKGO_FILTER_LABEL: ${{ matrix.test }}
GINKGO_NODES: ${{ matrix.nodes }}
GO111MODULE: on
GINKGO_EDITOR_INTEGRATION: "true"
run: |
devbox run -- '
sudo curl -Lo setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.0/hack/setup-envtest.sh &&
sudo mkdir -p /usr/local/kubebuilder/bin &&
sudo /bin/bash -c "source setup-envtest.sh && fetch_envtest_tools /usr/local/kubebuilder" &&
cd ${{ matrix.path }} &&
AKO_INT_TEST=1 ginkgo --label-filter="${TEST_NAME}" --timeout 90m --v --nodes="${PARALLEL_NODES}" --flake-attempts=1 --race --cover --coverpkg=github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/...'
devbox run -- 'make ${{ matrix.target }}'
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
35 changes: 26 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ OPERATOR_NAMESPACE = mongodb-atlas-system
ATLAS_DOMAIN = https://cloud-qa.mongodb.com/
ATLAS_KEY_SECRET_NAME = mongodb-atlas-operator-api-key

# Envtest configuration params
ENVTEST_ASSETS_DIR ?= $(shell pwd)/bin
ENVTEST_K8S_VERSION ?= 1.30.0
KUBEBUILDER_ASSETS ?= $(ENVTEST_ASSETS_DIR)/k8s/$(ENVTEST_K8S_VERSION)-$(TARGET_OS)-$(TARGET_ARCH)

# Ginkgo configuration
GINKGO_NODES ?= 12
GINKGO_EDITOR_INTEGRATION ?= true
GINKGO_OPTS = -vv --randomize-all --output-interceptor-mode=none --trace --timeout 90m --flake-attempts=1 --race --nodes=$(GINKGO_NODES) --cover --coverpkg=github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/...
GINKGO_FILTER_LABEL ?=
ifneq ($(GINKGO_FILTER_LABEL),)
GINKGO_FILTER_LABEL_OPT := --label-filter="$(GINKGO_FILTER_LABEL)"
endif
GINKGO=ginkgo run $(GINKGO_OPTS) $(GINKGO_FILTER_LABEL_OPT) $(shell pwd)/$@

BASE_GO_PACKAGE = github.com/mongodb/mongodb-atlas-kubernetes/v2
GO_LICENSES = go-licenses
GO_LICENSES_VERSION = 1.6.0
Expand Down Expand Up @@ -157,16 +172,18 @@ check-licenses: licenses-up-to-date ## Check licenses are compliant with our res
unit-test:
go test -race -cover $(GO_UNIT_TEST_FOLDERS)

.PHONY: int-test
int-test: ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
int-test: ENVTEST_K8S_VERSION = 1.26.1
# magical env that if specified makes the test output 0 on successful runs
# https://github.com/onsi/ginkgo/blob/master/ginkgo/run_command.go#L130
int-test: export GINKGO_EDITOR_INTEGRATION="true"
int-test: generate manifests ## Run integration tests. Sample with labels: `make int-test label=AtlasProject` or `make int-test label='AtlasDeployment && !slow'`
## Run integration tests. Sample with labels: `make test/int GINKGO_FILTER_LABEL=AtlasProject`
test/int: envtest
AKO_INT_TEST=1 KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) $(GINKGO)

test/int/clusterwide: envtest
AKO_INT_TEST=1 KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) $(GINKGO)

envtest: envtest-assets
KUBEBUILDER_ASSETS=$(shell setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) -p path)

envtest-assets:
mkdir -p $(ENVTEST_ASSETS_DIR)
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
export ENVTEST_K8S_VERSION=$(ENVTEST_K8S_VERSION) && source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); ./scripts/int_local.sh $(label)

.PHONY: e2e
e2e: run-kind ## Run e2e test. Command `make e2e label=cluster-ns` run cluster-ns test
Expand Down
3 changes: 2 additions & 1 deletion devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"[email protected]",
"shellcheck@latest",
"[email protected]",
"[email protected]"
"[email protected]",
"[email protected]"
]
}
48 changes: 48 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,54 @@
}
}
},
"[email protected]": {
"last_modified": "2024-09-10T15:01:03Z",
"resolved": "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269#setup-envtest",
"source": "devbox-search",
"version": "0.18.2",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/kc22jbvb811zysi9245w4nimyipr2dyz-setup-envtest-0.18.2",
"default": true
}
],
"store_path": "/nix/store/kc22jbvb811zysi9245w4nimyipr2dyz-setup-envtest-0.18.2"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/0x6wm35hdh1h1lpcq2s5akj2y1s17apy-setup-envtest-0.18.2",
"default": true
}
],
"store_path": "/nix/store/0x6wm35hdh1h1lpcq2s5akj2y1s17apy-setup-envtest-0.18.2"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/mhv8afglwwy8ajb1c5s4xdc0c3p1s9m7-setup-envtest-0.18.2",
"default": true
}
],
"store_path": "/nix/store/mhv8afglwwy8ajb1c5s4xdc0c3p1s9m7-setup-envtest-0.18.2"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/7rlfhmyxv2hnhqjrj1xmgy6ygkis8fwm-setup-envtest-0.18.2",
"default": true
}
],
"store_path": "/nix/store/7rlfhmyxv2hnhqjrj1xmgy6ygkis8fwm-setup-envtest-0.18.2"
}
}
},
"shellcheck@latest": {
"last_modified": "2024-09-10T15:01:03Z",
"resolved": "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269#shellcheck",
Expand Down
24 changes: 0 additions & 24 deletions scripts/int_local.sh

This file was deleted.

0 comments on commit 1b4b76b

Please sign in to comment.