diff --git a/Makefile b/Makefile index 272bffa724..080af8b7db 100644 --- a/Makefile +++ b/Makefile @@ -13,38 +13,51 @@ OPM_VERSION=v1.28.0 OPM=$(LOCALBIN)/opm-$(OPM_VERSION) .PHONY: \ + fmt \ + vet \ build \ - gen-protobuf \ - clean \ ocs-operator \ + ocs-metrics-exporter \ + gen-latest-csv \ + verify-latest-csv \ + gen-release-csv \ operator-bundle \ verify-operator-bundle \ - gen-latest-csv \ - gen-latest-deploy-yaml \ + operator-catalog \ + deps-update \ + verify-deps \ + gen-protobuf \ gen-latest-prometheus-rules-yamls \ + gen-latest-deploy-yaml \ verify-latest-deploy-yaml \ - verify-latest-csv \ cluster-deploy \ cluster-clean \ + unit-test \ functest \ shellcheck-test \ golangci-lint \ - update-generated \ ocs-operator-ci \ - unit-test \ - deps-update - -deps-update: - @echo "Running deps-update" - go mod tidy && go mod vendor + generate \ + manifests \ + verify-generated \ + run \ + clean \ + controller-gen \ + kustomize \ + operator-sdk \ + opm \ + install-noobaa \ + install-ocs + +fmt: + go fmt ./... -operator-sdk: - @echo "Ensuring operator-sdk" - hack/ensure-operator-sdk.sh +vet: + go vet ./... -build: deps-update generate gen-protobuf +build: fmt vet deps-update generate -ocs-operator: build +ocs-operator: build gen-protobuf @echo "Building the ocs-operator image" hack/build-operator.sh @@ -52,49 +65,54 @@ ocs-metrics-exporter: build @echo "Building the ocs-metrics-exporter image" hack/build-metrics-exporter.sh -gen-protobuf: - @echo "Generating protobuf files for gRPC services" - hack/gen-protobuf.sh - gen-latest-csv: operator-sdk manifests kustomize @echo "Generating latest development CSV version using predefined ENV VARs." hack/generate-latest-csv.sh -gen-release-csv: operator-sdk manifests kustomize - @echo "Generating unified CSV from sourced component-level operators" - hack/generate-unified-csv.sh - -gen-latest-deploy-yaml: - @echo "Generating latest deployment yaml file" - hack/gen-deployment-yaml.sh - -gen-latest-prometheus-rules-yamls: - @echo "Generating latest Prometheus rules yamls" - hack/gen-promethues-rules.sh - -verify-latest-deploy-yaml: gen-latest-deploy-yaml - @echo "Verifying deployment yaml changes" - hack/verify-latest-deploy-yaml.sh - verify-latest-csv: gen-latest-csv @echo "Verifying latest CSV" hack/verify-latest-csv.sh -verify-operator-bundle: operator-sdk - @echo "Verifying operator bundle" - hack/verify-operator-bundle.sh +# This target is used in DownStream build scripts +gen-release-csv: operator-sdk manifests kustomize + @echo "Generating unified CSV from sourced component-level operators" + hack/generate-unified-csv.sh operator-bundle: gen-latest-csv @echo "Building ocs operator bundle" hack/build-operator-bundle.sh -operator-catalog: +verify-operator-bundle: operator-sdk + @echo "Verifying operator bundle" + hack/verify-operator-bundle.sh + +operator-catalog: opm @echo "Building ocs catalog image in file based catalog format" hack/build-operator-catalog.sh -clean: - @echo "cleaning previous outputs" - hack/clean.sh +deps-update: + @echo "Running deps-update" + go mod tidy && go mod vendor + +verify-deps: deps-update + @echo "Verifying dependency files" + hack/verify-dependencies.sh + +gen-protobuf: + @echo "Generating protobuf files for gRPC services" + hack/gen-protobuf.sh + +gen-latest-prometheus-rules-yamls: + @echo "Generating latest Prometheus rules yamls" + hack/gen-promethues-rules.sh + +gen-latest-deploy-yaml: + @echo "Generating latest deployment yaml file" + hack/gen-deployment-yaml.sh + +verify-latest-deploy-yaml: gen-latest-deploy-yaml + @echo "Verifying deployment yaml changes" + hack/verify-latest-deploy-yaml.sh cluster-deploy: cluster-clean @echo "Deploying ocs to cluster" @@ -104,6 +122,9 @@ cluster-clean: @echo "Removing ocs install from cluster" hack/cluster-clean.sh +unit-test: + @echo "Executing unit tests" + hack/unit-test.sh functest: @echo "Running ocs developer functional test suite" @@ -117,16 +138,6 @@ golangci-lint: @echo "Running golangci-lint run" hack/golangci_lint.sh -lint: ## Run golangci-lint inside a container - source hack/common.sh; source hack/docker-common.sh; \ - $${IMAGE_BUILD_CMD} run --rm -v $${PROJECT_DIR}:/app:Z -w /app $${GO_LINT_IMG} golangci-lint run ./... - -# ignoring the functest dir since it requires an active cluster -# use 'make functest' to run just the functional tests -unit-test: - @echo "Executing unit tests" - hack/unit-test.sh - ocs-operator-ci: shellcheck-test golangci-lint unit-test verify-deps verify-generated verify-latest-csv verify-operator-bundle verify-latest-deploy-yaml # Generate code @@ -139,13 +150,7 @@ manifests: controller-gen @echo Updating generated manifests $(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true paths=./api/... webhook paths="./..." output:crd:artifacts:config=config/crd/bases -verify-deps: deps-update - @echo "Verifying dependency files" - hack/verify-dependencies.sh - -update-generated: generate manifests - -verify-generated: update-generated +verify-generated: generate manifests @echo "Verifying generated code and manifests" hack/verify-generated.sh @@ -157,6 +162,10 @@ run: manifests generate go vet ./... go run ./main.go $(ARGS) +clean: + @echo "cleaning previously fetched & built tools/binaries" + hack/clean.sh + # find or download controller-gen if necessary controller-gen: ifeq ($(wildcard ${CONTROLLER_GEN}),) @@ -173,6 +182,7 @@ endif kustomize: ifeq ($(wildcard ${KUSTOMIZE}),) @echo "Installing kustomize@${KUSTOMIZE_VERSION} at ${KUSTOMIZE}" + @mkdir -p $(LOCALBIN) @curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN) else ifneq ($(shell ${KUSTOMIZE} version | awk -F'[ /]' '/Version/{print $$2}'), $(KUSTOMIZE_VERSION)) @echo "Installing newer kustomize@${KUSTOMIZE_VERSION} at ${KUSTOMIZE}" diff --git a/hack/common.sh b/hack/common.sh index 99e8c49635..5865fd636e 100644 --- a/hack/common.sh +++ b/hack/common.sh @@ -8,13 +8,8 @@ GOARCH="${GOARCH:-amd64}" GOHOSTOS="$(go env GOHOSTOS)" GOHOSTARCH="$(go env GOHOSTARCH)" -GO_LINT_IMG_LOCATION="${GO_LINT_IMG_LOCATION:-golangci/golangci-lint}" -GO_LINT_IMG_TAG="${GO_LINT_IMG_TAG:-v1.49.0}" -GO_LINT_IMG="${GO_LINT_IMG:-${GO_LINT_IMG_LOCATION}:${GO_LINT_IMG_TAG}}" - # Current DEV version of the CSV -DEFAULT_CSV_VERSION="4.14.0" -CSV_VERSION="${CSV_VERSION:-${DEFAULT_CSV_VERSION}}" +CSV_VERSION="${CSV_VERSION:-4.14.0}" VERSION="${VERSION:-${CSV_VERSION}}" LDFLAGS="-X github.com/red-hat-storage/ocs-operator/v4/version.Version=${CSV_VERSION}" @@ -53,31 +48,18 @@ LATEST_ROOK_CSIADDONS_IMAGE="quay.io/csiaddons/k8s-sidecar:v0.6.0" # TODO: change image once the quay repo is changed LATEST_MUST_GATHER_IMAGE="quay.io/ocs-dev/ocs-must-gather:latest" -DEFAULT_IMAGE_REGISTRY="quay.io" -DEFAULT_REGISTRY_NAMESPACE="ocs-dev" -DEFAULT_IMAGE_TAG="latest" -DEFAULT_OPERATOR_IMAGE_NAME="ocs-operator" -DEFAULT_OPERATOR_BUNDLE_NAME="ocs-operator-bundle" -DEFAULT_FILE_BASED_CATALOG_NAME="ocs-operator-catalog" -DEFAULT_METRICS_EXPORTER_IMAGE_NAME="ocs-metrics-exporter" - -IMAGE_REGISTRY="${IMAGE_REGISTRY:-${DEFAULT_IMAGE_REGISTRY}}" -REGISTRY_NAMESPACE="${REGISTRY_NAMESPACE:-${DEFAULT_REGISTRY_NAMESPACE}}" -OPERATOR_IMAGE_NAME="${OPERATOR_IMAGE_NAME:-${DEFAULT_OPERATOR_IMAGE_NAME}}" -OPERATOR_BUNDLE_NAME="${OPERATOR_BUNDLE_NAME:-${DEFAULT_OPERATOR_BUNDLE_NAME}}" -FILE_BASED_CATALOG_NAME="${FILE_BASED_CATALOG_NAME:-${DEFAULT_FILE_BASED_CATALOG_NAME}}" -METRICS_EXPORTER_IMAGE_NAME="${METRICS_EXPORTER_IMAGE_NAME:-${DEFAULT_METRICS_EXPORTER_IMAGE_NAME}}" -IMAGE_TAG="${IMAGE_TAG:-${DEFAULT_IMAGE_TAG}}" - -DEFAULT_OPERATOR_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${OPERATOR_IMAGE_NAME}:${IMAGE_TAG}" -DEFAULT_BUNDLE_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${OPERATOR_BUNDLE_NAME}:${IMAGE_TAG}" -DEFAULT_FILE_BASED_CATALOG_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${FILE_BASED_CATALOG_NAME}:${IMAGE_TAG}" -DEFAULT_METRICS_EXPORTER_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${METRICS_EXPORTER_IMAGE_NAME}:${IMAGE_TAG}" - -OPERATOR_FULL_IMAGE_NAME="${OPERATOR_FULL_IMAGE_NAME:-${DEFAULT_OPERATOR_FULL_IMAGE_NAME}}" -BUNDLE_FULL_IMAGE_NAME="${BUNDLE_FULL_IMAGE_NAME:-${DEFAULT_BUNDLE_FULL_IMAGE_NAME}}" -FILE_BASED_CATALOG_FULL_IMAGE_NAME="${FILE_BASED_CATALOG_FULL_IMAGE_NAME:-${DEFAULT_FILE_BASED_CATALOG_FULL_IMAGE_NAME}}" -METRICS_EXPORTER_FULL_IMAGE_NAME="${METRICS_EXPORTER_FULL_IMAGE_NAME:-${DEFAULT_METRICS_EXPORTER_FULL_IMAGE_NAME}}" +IMAGE_REGISTRY="quay.io" +REGISTRY_NAMESPACE="ocs-dev" +IMAGE_TAG="latest" +OPERATOR_IMAGE_NAME="ocs-operator" +OPERATOR_BUNDLE_NAME="ocs-operator-bundle" +FILE_BASED_CATALOG_NAME="ocs-operator-catalog" +METRICS_EXPORTER_IMAGE_NAME="ocs-metrics-exporter" + +OPERATOR_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${OPERATOR_IMAGE_NAME}:${IMAGE_TAG}" +BUNDLE_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${OPERATOR_BUNDLE_NAME}:${IMAGE_TAG}" +FILE_BASED_CATALOG_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${FILE_BASED_CATALOG_NAME}:${IMAGE_TAG}" +METRICS_EXPORTER_FULL_IMAGE_NAME="${IMAGE_REGISTRY}/${REGISTRY_NAMESPACE}/${METRICS_EXPORTER_IMAGE_NAME}:${IMAGE_TAG}" NOOBAA_BUNDLE_FULL_IMAGE_NAME="quay.io/noobaa/noobaa-operator-bundle:master-20230718"