operators: use bazel to run operator envtests

This commit is contained in:
Malte Poll 2023-08-16 22:09:56 +02:00 committed by Malte Poll
parent 0be3d4b132
commit 5cf2a59c2c
5 changed files with 72 additions and 12 deletions

View File

@ -3,7 +3,7 @@ project(constellation LANGUAGES C)
enable_testing()
add_test(NAME integration-node-operator COMMAND make test WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/operators/constellation-node-operator)
# TODO(malt3): Remove this once every integration test is migrated to Bazel
add_test(NAME integration-csi COMMAND bash -c "go test -tags integration -c ./test/ && sudo ./test.test -test.v" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/csi)
add_test(NAME integration-dm COMMAND bash -c "go test -tags integration -c ./test/ && sudo ./test.test -test.v" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/disk-mapper/internal)
add_test(NAME integration-license COMMAND bash -c "go test -tags integration" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/internal/license)

View File

@ -68,3 +68,15 @@ oci_image(
],
visibility = ["//visibility:public"],
)
filegroup(
name = "crd_bases",
srcs = glob(["config/crd/bases/*.yaml"]),
visibility = ["//visibility:public"],
)
filegroup(
name = "external_crds",
srcs = glob(["external/**/*.yaml"]),
visibility = ["//visibility:public"],
)

View File

@ -48,8 +48,6 @@ endif
# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_TAG_BASE):v$(VERSION)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.1
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
@ -103,8 +101,8 @@ vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -tags integration -coverprofile cover.out
test: manifests generate fmt vet ## Run tests.
bazel test //operators/constellation-node-operator/...
##@ Build
@ -161,7 +159,6 @@ $(LOCALBIN):
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
@ -178,11 +175,6 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q

View File

@ -47,20 +47,43 @@ go_library(
go_test(
name = "controllers_test",
srcs = [
"autoscalingstrategy_controller_env_test.go",
"client_test.go",
"joiningnode_controller_env_test.go",
"nodeversion_controller_env_test.go",
"nodeversion_controller_test.go",
"nodeversion_watches_test.go",
"pendingnode_controller_env_test.go",
"pendingnode_controller_test.go",
"scalinggroup_controller_env_test.go",
"scalinggroup_controller_test.go",
"schemes_test.go",
"suite_test.go",
],
# keep
count = 1,
# keep
data = [
"//bazel/envtest:tools",
"//operators/constellation-node-operator:crd_bases",
"//operators/constellation-node-operator:external_crds",
],
embed = [":controllers"],
# keep
env = {
"KUBEBUILDER_ASSETS": "../../../$(rootpath //bazel/envtest:tools)",
},
# keep
gotags = ["integration"],
deps = [
"//3rdparty/node-maintenance-operator/api/v1beta1",
"//internal/constants",
"//operators/constellation-node-operator/api/v1alpha1",
"@com_github_onsi_ginkgo_v2//:ginkgo",
"@com_github_onsi_gomega//:gomega",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@io_k8s_api//apps/v1:apps",
"@io_k8s_api//core/v1:core",
"@io_k8s_apimachinery//pkg/api/errors",
"@io_k8s_apimachinery//pkg/api/meta",
@ -70,8 +93,14 @@ go_test(
"@io_k8s_apimachinery//pkg/types",
"@io_k8s_apimachinery//pkg/version",
"@io_k8s_client_go//kubernetes/scheme",
"@io_k8s_client_go//rest",
"@io_k8s_sigs_controller_runtime//:controller-runtime",
"@io_k8s_sigs_controller_runtime//pkg/client",
"@io_k8s_sigs_controller_runtime//pkg/envtest",
"@io_k8s_sigs_controller_runtime//pkg/event",
"@io_k8s_sigs_controller_runtime//pkg/log",
"@io_k8s_sigs_controller_runtime//pkg/log/zap",
"@io_k8s_sigs_controller_runtime//pkg/reconcile",
"@io_k8s_utils//clock/testing",
],
)

View File

@ -33,19 +33,46 @@ go_library(
go_test(
name = "sgreconciler_test",
srcs = ["scalinggroup_controller_test.go"],
srcs = [
"scalinggroup_controller_env_test.go",
"scalinggroup_controller_test.go",
"suite_test.go",
],
# keep
count = 1,
# keep
data = [
"//bazel/envtest:tools",
"//operators/constellation-node-operator:crd_bases",
],
embed = [":sgreconciler"],
# keep
env = {
"KUBEBUILDER_ASSETS": "../../../$(rootpath //bazel/envtest:tools)",
},
# keep
gotags = ["integration"],
deps = [
"//internal/constants",
"//operators/constellation-node-operator/api/v1alpha1",
"//operators/constellation-node-operator/internal/cloud/api",
"//operators/constellation-node-operator/internal/constants",
"//operators/constellation-node-operator/internal/executor",
"@com_github_onsi_ginkgo_v2//:ginkgo",
"@com_github_onsi_gomega//:gomega",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@io_k8s_api//apps/v1:apps",
"@io_k8s_api//core/v1:core",
"@io_k8s_apimachinery//pkg/api/errors",
"@io_k8s_apimachinery//pkg/apis/meta/v1:meta",
"@io_k8s_apimachinery//pkg/runtime/schema",
"@io_k8s_apimachinery//pkg/types",
"@io_k8s_client_go//kubernetes/scheme",
"@io_k8s_client_go//rest",
"@io_k8s_sigs_controller_runtime//pkg/client",
"@io_k8s_sigs_controller_runtime//pkg/envtest",
"@io_k8s_sigs_controller_runtime//pkg/log",
"@io_k8s_sigs_controller_runtime//pkg/log/zap",
],
)