# The generated source files might not comply with the current go formatting, so format them explicitly.
go fmt ./api/...
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
# Dynamically derived from the k8s.io/api dependency version in go.mod (v0.X.Y -> 1.X),
# since not all patch versions are re-published.
ENVTEST_K8S_VERSION ?= $(shell go list -m -f '{{.Version}}' k8s.io/api | sed 's/^v0\.\([0-9]*\).*/1.\1/')
.PHONY: test
test: manifests generate fmt vet ## Run go unit tests
go test$(shell go list ./... | grep -v '^github.com/stackrox/rox/operator/tests') -coverprofile cover.out
test-integration: manifests generate fmt vet envtest ## Run go integration tests
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./tests/... -coverprofile cover-integration.out
test-helm: ## Run operator helm chart tests.
ROX_PRODUCT_BRANDING=RHACS_BRANDING $(MAKE) chart # Setting the env var to produce the rhacs- flavor assumed by the subsequent test.
go test -tags operator_helmtest -count=1 -v ./tests/chart/...
check-ci-setup: ## Make sure this target is not started in CI environment.
$(SILENT)if [ -n"$${CI:-}" ];thenecho"Setup error: operator should be installed and started by OLM.">&2;exit 1;fi
.PHONY: run
run: check-ci-setup manifests generate ensure-rox-main-image-exists fmt vet quick-run ## Run operator from your host without deploying it to a cluster.
.PHONY: quick-run
quick-run: ## Same as run, but without ensuring dependencies.
@if [[ -n"$$MAIN_IMAGE_TAG" ]];then\
echo"MAIN_IMAGE_TAG=$$MAIN_IMAGE_TAG specified, using related images with this tag.";\
cd build/dist &&$(KUSTOMIZE) edit set image controller=${IMG}
mkdir -p dist
$(KUSTOMIZE) build build/dist > dist/install.yaml
.PHONY: chart
chart: kubebuilder manifests ## Generate a helm chart with all necessary resources.
# The dependency above makes sure protos are up to date, so we can skip this time-consuming process below
# by specifying the SKIP env var. Otherwise each target that kubebuilder invokes (and there is a bunch) would regen protos.
rm -rf dist/chart
# Run the sed and kubebuilder as a single command, propagating the VERSION from when the directory is still pristine, to prevent -dirty suffix while PROJECT is modified.
set -e; \
if [[ "$(ROX_IMAGE_FLAVOR)" = opensource ]]; then sed -i'.bak' -e 's,^projectName: rhacs-operator,projectName: stackrox-operator,' PROJECT; fi; \
cd config/scorecard-versioned && $(KUSTOMIZE) edit set image quay.io/operator-framework/scorecard-test=quay.io/operator-framework/scorecard-test:$(OPERATOR_SDK_VERSION)