diff --git a/CMakeLists.txt b/CMakeLists.txt index 902d7d5f1b1..a6721b15e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/operators/constellation-node-operator/BUILD.bazel b/operators/constellation-node-operator/BUILD.bazel index 03f05ed9527..a57c9791b6e 100644 --- a/operators/constellation-node-operator/BUILD.bazel +++ b/operators/constellation-node-operator/BUILD.bazel @@ -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"], +) diff --git a/operators/constellation-node-operator/Makefile b/operators/constellation-node-operator/Makefile index 3653b23fb95..ca2bd09068d 100644 --- a/operators/constellation-node-operator/Makefile +++ b/operators/constellation-node-operator/Makefile @@ -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 diff --git a/operators/constellation-node-operator/controllers/BUILD.bazel b/operators/constellation-node-operator/controllers/BUILD.bazel index c6b689aa6e8..f4a30061eb3 100644 --- a/operators/constellation-node-operator/controllers/BUILD.bazel +++ b/operators/constellation-node-operator/controllers/BUILD.bazel @@ -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 = [ + "//operators/constellation-node-operator:crd_bases", + "//operators/constellation-node-operator:external_crds", + "//operators/envtest:tools", ], embed = [":controllers"], + # keep + env = { + "KUBEBUILDER_ASSETS": "../../../$(rootpath //operators/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", ], ) diff --git a/operators/constellation-node-operator/sgreconciler/BUILD.bazel b/operators/constellation-node-operator/sgreconciler/BUILD.bazel index f37609ed9bd..066938bfafd 100644 --- a/operators/constellation-node-operator/sgreconciler/BUILD.bazel +++ b/operators/constellation-node-operator/sgreconciler/BUILD.bazel @@ -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 = [ + "//operators/constellation-node-operator:crd_bases", + "//operators/envtest:tools", + ], embed = [":sgreconciler"], + # keep + env = { + "KUBEBUILDER_ASSETS": "../../../$(rootpath //operators/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", ], )