diff --git a/.github/workflows/test-int.yml b/.github/workflows/test-int.yml index ba0486a9c1..7b42a49871 100644 --- a/.github/workflows/test-int.yml +++ b/.github/workflows/test-int.yml @@ -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: @@ -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: diff --git a/Makefile b/Makefile index a72132c484..abff9a3372 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/devbox.json b/devbox.json index ba78809292..b747765e7c 100644 --- a/devbox.json +++ b/devbox.json @@ -20,6 +20,7 @@ "operator-sdk@1.36.1", "shellcheck@latest", "golangci-lint@1.60", - "kubernetes-controller-tools@0.16.1" + "kubernetes-controller-tools@0.16.1", + "setup-envtest@0.18.2" ] } diff --git a/devbox.lock b/devbox.lock index cf469070e5..881de9c99a 100644 --- a/devbox.lock +++ b/devbox.lock @@ -1037,6 +1037,54 @@ } } }, + "setup-envtest@0.18.2": { + "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", diff --git a/scripts/int_local.sh b/scripts/int_local.sh deleted file mode 100755 index 0511383b80..0000000000 --- a/scripts/int_local.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -eou pipefail - -if [ -z "${label+x}" ]; then - label="" -fi - -cluster_wide_labels=("ClusterWide") - -int_test_folder=int -if [[ ${cluster_wide_labels[*]} =~ ${label} ]]; then - int_test_folder=int/clusterwide -fi -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) - -export MCLI_OPS_MANAGER_URL="${MCLI_OPS_MANAGER_URL:-https://cloud-qa.mongodb.com/}" -export MCLI_PUBLIC_API_KEY="${MCLI_PUBLIC_API_KEY:-$public_key}" -export MCLI_PRIVATE_API_KEY="${MCLI_PRIVATE_API_KEY:-$private_key}" -export MCLI_ORG_ID="${MCLI_ORG_ID:-$org_id}" - -AKO_INT_TEST=1 ginkgo run --race --label-filter="${label}" --timeout 80m -v ./test/${int_test_folder} -coverprofile cover.out