From ca4ce939cd7562048481dabfe9f10002a950aa98 Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Thu, 2 May 2024 17:03:55 -0400 Subject: [PATCH] Makefile: avoid re-evaluating vars unnecessarily; other minor fixup Signed-off-by: Joe Lanford --- .goreleaser.yml | 5 -- Makefile | 168 ++++++++++++++++++++++++++---------------------- 2 files changed, 92 insertions(+), 81 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 439f75ae..1cc1d621 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,7 +11,6 @@ builds: - id: unpack main: ./cmd/unpack binary: unpack - tags: "{{.Env.GO_BUILD_TAGS}}" goos: - linux goarch: @@ -22,7 +21,6 @@ builds: - id: helm main: ./cmd/helm binary: helm - tags: "{{.Env.GO_BUILD_TAGS}}" goos: - linux goarch: @@ -33,7 +31,6 @@ builds: - id: core main: ./cmd/core binary: core - tags: "{{.Env.GO_BUILD_TAGS}}" goos: - linux goarch: @@ -44,7 +41,6 @@ builds: - id: webhooks main: ./cmd/webhooks binary: webhooks - tags: "{{.Env.GO_BUILD_TAGS}}" goos: - linux goarch: @@ -55,7 +51,6 @@ builds: - id: crdvalidator main: ./cmd/crdvalidator binary: crdvalidator - tags: "{{.Env.GO_BUILD_TAGS}}" goos: - linux goarch: diff --git a/Makefile b/Makefile index b70ac817..9a75abaa 100644 --- a/Makefile +++ b/Makefile @@ -3,45 +3,53 @@ ########################### ORG := github.com/operator-framework PKG := $(ORG)/rukpak -export IMAGE_REPO ?= quay.io/operator-framework/rukpak -export IMAGE_TAG ?= devel -export GO_BUILD_TAGS ?= '' -IMAGE?=$(IMAGE_REPO):$(IMAGE_TAG) -KIND_CLUSTER_NAME ?= rukpak -BIN_DIR := bin -TESTDATA_DIR := testdata -VERSION_PATH := $(PKG)/internal/version -GIT_COMMIT ?= $(shell git rev-parse HEAD) -PKGS = $(shell go list ./...) -export CERT_MGR_VERSION ?= v1.9.0 -RUKPAK_NAMESPACE ?= rukpak-system - -REGISTRY_NAME="docker-registry" -REGISTRY_NAMESPACE=rukpak-e2e -DNS_NAME=$(REGISTRY_NAME).$(REGISTRY_NAMESPACE).svc.cluster.local - -CONTAINER_RUNTIME ?= docker -KUBECTL ?= kubectl - -# setup-envtest on *nix uses XDG_DATA_HOME, falling back to HOME, as the default storage directory. Some CI setups -# don't have XDG_DATA_HOME set; in those cases, we set it here so setup-envtest functions correctly. This shouldn't -# affect developers. -export XDG_DATA_HOME ?= /tmp/.local/share -# bingo manages consistent tooling versions for things like kind, kustomize, etc. -include .bingo/Variables.mk +ifeq ($(origin IMAGE_REPO), undefined) +IMAGE_REPO := quay.io/operator-framework/rukpak +endif +export IMAGE_REPO +ifeq ($(origin IMAGE_TAG), undefined) +IMAGE_TAG := devel +endif +export IMAGE_TAG +IMAGE := $(IMAGE_REPO):$(IMAGE_TAG) + -# kernel-style V=1 build verbosity -ifeq ("$(origin V)", "command line") - BUILD_VERBOSE = $(V) +ifeq ($(origin KIND_CLUSTER_NAME), undefined) +KIND_CLUSTER_NAME := rukpak endif -ifeq ($(BUILD_VERBOSE),1) - Q = +export CERT_MGR_VERSION := v1.9.0 + +BIN_DIR := bin +VERSION_PATH := $(PKG)/internal/version +GIT_COMMIT := $(shell git rev-parse HEAD) +PKGS := $(shell go list ./...) +RUKPAK_NAMESPACE := rukpak-system + +REGISTRY_NAME := "docker-registry" +REGISTRY_NAMESPACE := rukpak-e2e +DNS_NAME := $(REGISTRY_NAME).$(REGISTRY_NAMESPACE).svc.cluster.local + +ifneq (, $(shell command -v docker 2>/dev/null)) +CONTAINER_RUNTIME := docker +else ifneq (, $(shell command -v podman 2>/dev/null)) +CONTAINER_RUNTIME := podman else - Q = @ +$(error Could not find docker or podman in path!) +endif + +# By default setup-envtest will write to $XDG_DATA_HOME, or $HOME/.local/share if that is not defined. +# If $HOME is not set, we need to specify a binary directory to prevent an error in setup-envtest. +# Useful for some CI/CD environments that set neither $XDG_DATA_HOME nor $HOME. +SETUP_ENVTEST_BIN_DIR_OVERRIDE := +ifeq ($(shell [[ $$HOME == "" || $$HOME == "/" ]] && [[ $$XDG_DATA_HOME == "" ]] && echo true ), true) + SETUP_ENVTEST_BIN_DIR_OVERRIDE += --bin-dir /tmp/envtest-binaries endif +# bingo manages consistent tooling versions for things like kind, kustomize, etc. +include .bingo/Variables.mk + ############### # Help Target # ############### @@ -61,28 +69,28 @@ help: ## Show this help screen ##@ code management: lint: $(GOLANGCI_LINT) ## Run golangci linter - $(Q)$(GOLANGCI_LINT) run --build-tags $(GO_BUILD_TAGS) $(GOLANGCI_LINT_ARGS) + $(GOLANGCI_LINT) run $(GOLANGCI_LINT_ARGS) tidy: ## Update dependencies - $(Q)go mod tidy + go mod tidy fmt: ## Format Go code - $(Q)go fmt ./... + go fmt ./... clean: ## Remove binaries and test artifacts @rm -rf bin generate: $(CONTROLLER_GEN) ## Generate code and manifests - $(Q)$(CONTROLLER_GEN) crd:crdVersions=v1,generateEmbeddedObjectMeta=true output:crd:dir=./manifests/base/apis/crds paths=./api/... - $(Q)$(CONTROLLER_GEN) webhook paths=./api/... paths=./internal/webhook/... output:stdout > ./manifests/base/apis/webhooks/resources/webhook.yaml - $(Q)$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/... - $(Q)$(CONTROLLER_GEN) rbac:roleName=core-admin \ + $(CONTROLLER_GEN) crd:crdVersions=v1,generateEmbeddedObjectMeta=true output:crd:dir=./manifests/base/apis/crds paths=./api/... + $(CONTROLLER_GEN) webhook paths=./api/... paths=./internal/webhook/... output:stdout > ./manifests/base/apis/webhooks/resources/webhook.yaml + $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/... + $(CONTROLLER_GEN) rbac:roleName=core-admin \ paths=./internal/controllers/bundledeployment/... \ paths=./internal/provisioner/plain/... \ paths=./internal/provisioner/registry/... \ output:stdout > ./manifests/base/core/resources/cluster_role.yaml - $(Q)$(CONTROLLER_GEN) rbac:roleName=webhooks-admin paths=./internal/webhook/... output:stdout > ./manifests/base/apis/webhooks/resources/cluster_role.yaml - $(Q)$(CONTROLLER_GEN) rbac:roleName=helm-provisioner-admin \ + $(CONTROLLER_GEN) rbac:roleName=webhooks-admin paths=./internal/webhook/... output:stdout > ./manifests/base/apis/webhooks/resources/cluster_role.yaml + $(CONTROLLER_GEN) rbac:roleName=helm-provisioner-admin \ paths=./internal/controllers/bundledeployment/... \ paths=./internal/provisioner/helm/... \ output:stdout > ./manifests/base/provisioners/helm/resources/cluster_role.yaml @@ -99,17 +107,16 @@ verify: tidy fmt generate ## Verify the current code generation and lint test: test-unit test-e2e ## Run the tests -ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/') -UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/) +ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/') +UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/) test-unit: $(SETUP_ENVTEST) ## Run the unit tests - eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out + eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && go test -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out FOCUS := $(if $(TEST),-v --focus "$(TEST)") -E2E_FLAGS ?= test-e2e: $(GINKGO) ## Run the e2e tests - $(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) --trace $(FOCUS) test/e2e + $(GINKGO) $(E2E_FLAGS) --trace $(FOCUS) test/e2e -e2e: KIND_CLUSTER_NAME=rukpak-e2e +e2e: KIND_CLUSTER_NAME := rukpak-e2e e2e: run image-registry local-git kind-load-bundles registry-load-bundles test-e2e kind-cluster-cleanup ## Run e2e tests against an ephemeral kind cluster kind-cluster: $(KIND) kind-cluster-cleanup ## Standup a kind cluster @@ -134,33 +141,33 @@ local-git: ## Setup in-cluster git repository install: generate cert-mgr install-manifests wait ## Install rukpak -MANIFESTS_DIR ?= manifests/overlays/cert-manager +MANIFESTS_DIR := manifests/overlays/cert-manager install-manifests: - $(KUBECTL) apply -k $(MANIFESTS_DIR) + kubectl apply -k $(MANIFESTS_DIR) wait: - $(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/core --timeout=60s - $(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/rukpak-webhooks --timeout=60s - $(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/helm-provisioner --timeout=60s - $(KUBECTL) wait --for=condition=Available --namespace=crdvalidator-system deployment/crd-validation-webhook --timeout=60s + kubectl wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/core --timeout=60s + kubectl wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/rukpak-webhooks --timeout=60s + kubectl wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/helm-provisioner --timeout=60s + kubectl wait --for=condition=Available --namespace=crdvalidator-system deployment/crd-validation-webhook --timeout=60s run: build-container kind-cluster kind-load install ## Build image, stop/start a local kind cluster, and run operator in that cluster -debug: MANIFESTS_DIR = test/tools/remotedebug ## Same as 'run' target with the addition of remote debugging available on port 40000 -debug: DEBUG_FLAGS = -gcflags="all=-N -l" -debug: KIND_CLUSTER_CONFIG = --config=./test/tools/remotedebug/kind-config.yaml +debug: MANIFESTS_DIR := test/tools/remotedebug ## Same as 'run' target with the addition of remote debugging available on port 40000 +debug: DEBUG_FLAGS := -gcflags="all=-N -l" +debug: KIND_CLUSTER_CONFIG := --config=./test/tools/remotedebug/kind-config.yaml debug: run debug-helper debug-helper: @echo '' - @echo "Remote Debugging for '$$($(KUBECTL) -n $(RUKPAK_NAMESPACE) get pods -l app=core -o name)' in namespace '$(RUKPAK_NAMESPACE)' now available through localhost:40000" + @echo "Remote Debugging for '$$(kubectl -n $(RUKPAK_NAMESPACE) get pods -l app=core -o name)' in namespace '$(RUKPAK_NAMESPACE)' now available through localhost:40000" cert-mgr: ## Install the certification manager - $(KUBECTL) apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MGR_VERSION)/cert-manager.yaml - $(KUBECTL) wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=60s + kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MGR_VERSION)/cert-manager.yaml + kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=60s uninstall: ## Remove all rukpak resources from the cluster - $(KUBECTL) delete -k $(MANIFESTS_DIR) + kubectl delete -k $(MANIFESTS_DIR) ################## # Build and Load # @@ -168,7 +175,7 @@ uninstall: ## Remove all rukpak resources from the cluster ##@ build/load: -BINARIES=core helm unpack webhooks crdvalidator +BINARIES := core helm unpack webhooks crdvalidator LINUX_BINARIES=$(join $(addprefix linux/,$(BINARIES)), ) .PHONY: build $(BINARIES) $(LINUX_BINARIES) build-container kind-load kind-load-bundles kind-cluster registry-load-bundles @@ -177,25 +184,25 @@ LINUX_BINARIES=$(join $(addprefix linux/,$(BINARIES)), ) build: $(BINARIES) $(LINUX_BINARIES): - CGO_ENABLED=0 GOOS=linux go build $(DEBUG_FLAGS) -tags $(GO_BUILD_TAGS) -o $(BIN_DIR)/$@ ./cmd/$(notdir $@) + CGO_ENABLED=0 GOOS=linux go build $(DEBUG_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$(notdir $@) $(BINARIES): - CGO_ENABLED=0 go build $(DEBUG_FLAGS) -tags $(GO_BUILD_TAGS) -o $(BIN_DIR)/$@ ./cmd/$@ $(DEBUG_FLAGS) + CGO_ENABLED=0 go build $(DEBUG_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$@ $(DEBUG_FLAGS) build-container: $(LINUX_BINARIES) ## Builds provisioner container image locally $(CONTAINER_RUNTIME) build -f Dockerfile -t $(IMAGE) $(BIN_DIR)/linux kind-load-bundles: $(KIND) ## Load the e2e testdata container images into a kind cluster - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/valid -t localhost/testdata/bundles/plain-v0:valid - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/dependent -t localhost/testdata/bundles/plain-v0:dependent - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/provides -t localhost/testdata/bundles/plain-v0:provides - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/empty -t localhost/testdata/bundles/plain-v0:empty - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/no-manifests -t localhost/testdata/bundles/plain-v0:no-manifests - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/invalid-missing-crds -t localhost/testdata/bundles/plain-v0:invalid-missing-crds - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/invalid-crds-and-crs -t localhost/testdata/bundles/plain-v0:invalid-crds-and-crs - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/subdir -t localhost/testdata/bundles/plain-v0:subdir - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/registry/valid -t localhost/testdata/bundles/registry:valid - $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/registry/invalid -t localhost/testdata/bundles/registry:invalid + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/valid -t localhost/testdata/bundles/plain-v0:valid + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/dependent -t localhost/testdata/bundles/plain-v0:dependent + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/provides -t localhost/testdata/bundles/plain-v0:provides + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/empty -t localhost/testdata/bundles/plain-v0:empty + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/no-manifests -t localhost/testdata/bundles/plain-v0:no-manifests + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/invalid-missing-crds -t localhost/testdata/bundles/plain-v0:invalid-missing-crds + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/invalid-crds-and-crs -t localhost/testdata/bundles/plain-v0:invalid-crds-and-crs + $(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/subdir -t localhost/testdata/bundles/plain-v0:subdir + $(CONTAINER_RUNTIME) build testdata/bundles/registry/valid -t localhost/testdata/bundles/registry:valid + $(CONTAINER_RUNTIME) build testdata/bundles/registry/invalid -t localhost/testdata/bundles/registry:invalid $(KIND) load docker-image localhost/testdata/bundles/plain-v0:valid --name $(KIND_CLUSTER_NAME) $(KIND) load docker-image localhost/testdata/bundles/plain-v0:dependent --name $(KIND_CLUSTER_NAME) $(KIND) load docker-image localhost/testdata/bundles/plain-v0:provides --name $(KIND_CLUSTER_NAME) @@ -220,11 +227,20 @@ registry-load-bundles: ## Load selected e2e testdata container images created in ##@ release: -export ENABLE_RELEASE_PIPELINE ?= false -release: GORELEASER_ARGS ?= --snapshot --clean +ifeq ($(origin ENABLE_RELEASE_PIPELINE), undefined) +ENABLE_RELEASE_PIPELINE := false +endif +export ENABLE_RELEASE_PIPELINE + +ifeq ($(origin release: GORELEASER_ARGS), undefined) +release: GORELEASER_ARGS := --snapshot --clean +endif release: $(GORELEASER) ## Run goreleaser $(GORELEASER) $(GORELEASER_ARGS) -quickstart: VERSION ?= $(shell git describe --abbrev=0 --tags) + +ifeq ($(origin VERSION), undefined) +VERSION := $(shell git describe --abbrev=0 --tags) +endif quickstart: $(KUSTOMIZE) generate ## Generate the installation release manifests $(KUSTOMIZE) build manifests/overlays/cert-manager | sed "s/:devel/:$(VERSION)/g" > rukpak.yaml