Skip to content

Commit

Permalink
operators: use bazel to run operator envtests
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Aug 17, 2023
1 parent 13b03b1 commit fc321ad
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions operators/constellation-node-operator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
12 changes: 2 additions & 10 deletions operators/constellation-node-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions operators/constellation-node-operator/controllers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
)
29 changes: 28 additions & 1 deletion operators/constellation-node-operator/sgreconciler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

0 comments on commit fc321ad

Please sign in to comment.