Skip to content

Commit f501d63

Browse files
authored
update envtest and unify integration tests running (#1851)
1 parent ed9518a commit f501d63

File tree

5 files changed

+81
-44
lines changed

5 files changed

+81
-44
lines changed

.github/workflows/test-int.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
test: ["AtlasProject", "AtlasDeployment && !AtlasDeploymentSharding", "AtlasDatabaseUser", "AtlasDataFederation", "AtlasFederatedAuth", "AtlasDeploymentSharding", "AtlasStreams"]
21-
path: [ "./test/int" ]
21+
target: [ "test/int" ]
2222
nodes: [12]
2323
include:
2424
- test: "ClusterWide"
25-
path: "./test/int/clusterwide"
25+
target: "test/int/clusterwide"
2626
nodes: 1
2727

2828
steps:
@@ -47,17 +47,12 @@ jobs:
4747
ATLAS_ORG_ID: ${{ secrets.ATLAS_ORG_ID }}
4848
ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }}
4949
ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
50-
TEST_NAME: ${{ matrix.test }}
51-
PARALLEL_NODES: ${{ matrix.nodes }}
50+
GINKGO_FILTER_LABEL: ${{ matrix.test }}
51+
GINKGO_NODES: ${{ matrix.nodes }}
5252
GO111MODULE: on
5353
GINKGO_EDITOR_INTEGRATION: "true"
5454
run: |
55-
devbox run -- '
56-
sudo curl -Lo setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.0/hack/setup-envtest.sh &&
57-
sudo mkdir -p /usr/local/kubebuilder/bin &&
58-
sudo /bin/bash -c "source setup-envtest.sh && fetch_envtest_tools /usr/local/kubebuilder" &&
59-
cd ${{ matrix.path }} &&
60-
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/...'
55+
devbox run -- 'make ${{ matrix.target }}'
6156
- name: Upload coverage to Codecov
6257
uses: codecov/codecov-action@v4
6358
with:

Makefile

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ OPERATOR_NAMESPACE = mongodb-atlas-system
8282
ATLAS_DOMAIN = https://cloud-qa.mongodb.com/
8383
ATLAS_KEY_SECRET_NAME = mongodb-atlas-operator-api-key
8484

85+
# Envtest configuration params
86+
ENVTEST_ASSETS_DIR ?= $(shell pwd)/bin
87+
ENVTEST_K8S_VERSION ?= 1.30.0
88+
KUBEBUILDER_ASSETS ?= $(ENVTEST_ASSETS_DIR)/k8s/$(ENVTEST_K8S_VERSION)-$(TARGET_OS)-$(TARGET_ARCH)
89+
90+
# Ginkgo configuration
91+
GINKGO_NODES ?= 12
92+
GINKGO_EDITOR_INTEGRATION ?= true
93+
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/...
94+
GINKGO_FILTER_LABEL ?=
95+
ifneq ($(GINKGO_FILTER_LABEL),)
96+
GINKGO_FILTER_LABEL_OPT := --label-filter="$(GINKGO_FILTER_LABEL)"
97+
endif
98+
GINKGO=ginkgo run $(GINKGO_OPTS) $(GINKGO_FILTER_LABEL_OPT) $(shell pwd)/$@
99+
85100
BASE_GO_PACKAGE = github.com/mongodb/mongodb-atlas-kubernetes/v2
86101
GO_LICENSES = go-licenses
87102
GO_LICENSES_VERSION = 1.6.0
@@ -157,16 +172,18 @@ check-licenses: licenses-up-to-date ## Check licenses are compliant with our res
157172
unit-test:
158173
go test -race -cover $(GO_UNIT_TEST_FOLDERS)
159174

160-
.PHONY: int-test
161-
int-test: ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
162-
int-test: ENVTEST_K8S_VERSION = 1.26.1
163-
# magical env that if specified makes the test output 0 on successful runs
164-
# https://github.com/onsi/ginkgo/blob/master/ginkgo/run_command.go#L130
165-
int-test: export GINKGO_EDITOR_INTEGRATION="true"
166-
int-test: generate manifests ## Run integration tests. Sample with labels: `make int-test label=AtlasProject` or `make int-test label='AtlasDeployment && !slow'`
175+
## Run integration tests. Sample with labels: `make test/int GINKGO_FILTER_LABEL=AtlasProject`
176+
test/int: envtest
177+
AKO_INT_TEST=1 KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) $(GINKGO)
178+
179+
test/int/clusterwide: envtest
180+
AKO_INT_TEST=1 KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) $(GINKGO)
181+
182+
envtest: envtest-assets
183+
KUBEBUILDER_ASSETS=$(shell setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) -p path)
184+
185+
envtest-assets:
167186
mkdir -p $(ENVTEST_ASSETS_DIR)
168-
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
169-
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)
170187

171188
.PHONY: e2e
172189
e2e: run-kind ## Run e2e test. Command `make e2e label=cluster-ns` run cluster-ns test

devbox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
"shellcheck@latest",
2222
23-
23+
24+
2425
]
2526
}

devbox.lock

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,54 @@
10371037
}
10381038
}
10391039
},
1040+
1041+
"last_modified": "2024-09-10T15:01:03Z",
1042+
"resolved": "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269#setup-envtest",
1043+
"source": "devbox-search",
1044+
"version": "0.18.2",
1045+
"systems": {
1046+
"aarch64-darwin": {
1047+
"outputs": [
1048+
{
1049+
"name": "out",
1050+
"path": "/nix/store/kc22jbvb811zysi9245w4nimyipr2dyz-setup-envtest-0.18.2",
1051+
"default": true
1052+
}
1053+
],
1054+
"store_path": "/nix/store/kc22jbvb811zysi9245w4nimyipr2dyz-setup-envtest-0.18.2"
1055+
},
1056+
"aarch64-linux": {
1057+
"outputs": [
1058+
{
1059+
"name": "out",
1060+
"path": "/nix/store/0x6wm35hdh1h1lpcq2s5akj2y1s17apy-setup-envtest-0.18.2",
1061+
"default": true
1062+
}
1063+
],
1064+
"store_path": "/nix/store/0x6wm35hdh1h1lpcq2s5akj2y1s17apy-setup-envtest-0.18.2"
1065+
},
1066+
"x86_64-darwin": {
1067+
"outputs": [
1068+
{
1069+
"name": "out",
1070+
"path": "/nix/store/mhv8afglwwy8ajb1c5s4xdc0c3p1s9m7-setup-envtest-0.18.2",
1071+
"default": true
1072+
}
1073+
],
1074+
"store_path": "/nix/store/mhv8afglwwy8ajb1c5s4xdc0c3p1s9m7-setup-envtest-0.18.2"
1075+
},
1076+
"x86_64-linux": {
1077+
"outputs": [
1078+
{
1079+
"name": "out",
1080+
"path": "/nix/store/7rlfhmyxv2hnhqjrj1xmgy6ygkis8fwm-setup-envtest-0.18.2",
1081+
"default": true
1082+
}
1083+
],
1084+
"store_path": "/nix/store/7rlfhmyxv2hnhqjrj1xmgy6ygkis8fwm-setup-envtest-0.18.2"
1085+
}
1086+
}
1087+
},
10401088
"shellcheck@latest": {
10411089
"last_modified": "2024-09-10T15:01:03Z",
10421090
"resolved": "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269#shellcheck",

scripts/int_local.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)