Skip to content

Commit c58accc

Browse files
committed
Makefile: fix issues with repeated evaluations
1 parent 79d64e8 commit c58accc

File tree

2 files changed

+85
-70
lines changed

2 files changed

+85
-70
lines changed

.goreleaser.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ builds:
99
asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}"
1010
gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}"
1111
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
12-
tags:
13-
- "{{ .Env.GO_BUILD_TAGS }}"
1412
goos:
1513
- linux
1614
goarch:

Makefile

Lines changed: 85 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22
# Configuration Variables #
33
###########################
44
# Image URL to use all building/pushing image targets
5-
export IMAGE_REPO ?= quay.io/operator-framework/operator-controller
6-
export IMAGE_TAG ?= devel
7-
export CERT_MGR_VERSION ?= v1.9.0
8-
export CATALOGD_VERSION ?= $(shell go list -mod=mod -m -f "{{.Version}}" github.com/operator-framework/catalogd)
9-
export KAPP_VERSION ?= $(shell go list -mod=mod -m -f "{{.Version}}" github.com/vmware-tanzu/carvel-kapp-controller)
10-
export RUKPAK_VERSION=$(shell go list -mod=mod -m -f "{{.Version}}" github.com/operator-framework/rukpak)
11-
export WAIT_TIMEOUT ?= 60s
12-
IMG?=$(IMAGE_REPO):$(IMAGE_TAG)
13-
TESTDATA_DIR := testdata
5+
ifeq (, $(IMAGE_REPO))
6+
IMAGE_REPO := quay.io/operator-framework/operator-controller
7+
endif
8+
export IMAGE_REPO
9+
10+
ifeq (, $(IMAGE_TAG))
11+
IMAGE_TAG := devel
12+
endif
13+
export IMAGE_TAG
14+
15+
IMG := $(IMAGE_REPO):$(IMAGE_TAG)
16+
17+
18+
# Define dependency versions (use go.mod if we also use Go code from dependency)
19+
export CERT_MGR_VERSION := v1.9.0
20+
export CATALOGD_VERSION := $(shell go list -mod=mod -m -f "{{.Version}}" github.com/operator-framework/catalogd)
21+
export KAPP_VERSION := $(shell go list -mod=mod -m -f "{{.Version}}" github.com/vmware-tanzu/carvel-kapp-controller)
22+
export RUKPAK_VERSION := $(shell go list -mod=mod -m -f "{{.Version}}" github.com/operator-framework/rukpak)
23+
export WAIT_TIMEOUT := 60s
1424

1525
# By default setup-envtest will write to $XDG_DATA_HOME, or $HOME/.local/share if that is not defined.
1626
# If $HOME is not set, we need to specify a binary directory to prevent an error in setup-envtest.
@@ -23,34 +33,28 @@ endif
2333
# bingo manages consistent tooling versions for things like kind, kustomize, etc.
2434
include .bingo/Variables.mk
2535

26-
# ARTIFACT_PATH is the absolute path to the directory where the operator-controller e2e tests will store the artifacts
27-
# for example: ARTIFACT_PATH=/tmp/artifacts make test
28-
export ARTIFACT_PATH ?=
29-
30-
OPERATOR_CONTROLLER_NAMESPACE ?= operator-controller-system
31-
KIND_CLUSTER_NAME ?= operator-controller
36+
KIND_CLUSTER_NAME := operator-controller
3237
# Not guaranteed to have patch releases available and node image tags are full versions (i.e v1.28.0 - no v1.28, v1.29, etc.)
3338
# The KIND_NODE_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
3439
# and sets major version to "1" and the patch version to "0". For example, a client-go version of v0.28.5
3540
# will map to a KIND_NODE_VERSION of 1.28.0
36-
KIND_NODE_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.0/')
37-
KIND_CLUSTER_IMAGE ?= kindest/node:v${KIND_NODE_VERSION}
38-
39-
CONTAINER_RUNTIME ?= docker
41+
KIND_NODE_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.0/')
42+
KIND_CLUSTER_IMAGE := kindest/node:v$(KIND_NODE_VERSION)
4043

41-
KUSTOMIZE_BUILD_DIR ?= config/default
42-
43-
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
44-
ifeq (,$(shell go env GOBIN))
45-
GOBIN=$(shell go env GOPATH)/bin
44+
ifneq (, $(shell command -v docker 2>/dev/null))
45+
CONTAINER_RUNTIME := docker
46+
else ifneq (, $(shell command -v podman 2>/dev/null))
47+
CONTAINER_RUNTIME := podman
4648
else
47-
GOBIN=$(shell go env GOBIN)
49+
$(error Could not find docker or podman in path!)
4850
endif
4951

52+
KUSTOMIZE_BUILD_DIR := config/default
53+
5054
# Setting SHELL to bash allows bash commands to be executed by recipes.
5155
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
52-
SHELL = /usr/bin/env bash -o pipefail
53-
.SHELLFLAGS = -ec
56+
SHELL := /usr/bin/env bash -o pipefail
57+
.SHELLFLAGS := -ec
5458

5559
# Disable -j flag for make
5660
.NOTPARALLEL:
@@ -83,7 +87,7 @@ help-extended: #HELP Display extended help.
8387

8488
.PHONY: lint
8589
lint: $(GOLANGCI_LINT) #HELP Run golangci linter.
86-
$(GOLANGCI_LINT) run --build-tags $(GO_BUILD_TAGS) $(GOLANGCI_LINT_ARGS)
90+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_ARGS)
8791

8892
.PHONY: tidy
8993
tidy: #HELP Update dependencies.
@@ -114,38 +118,38 @@ test: manifests generate fmt vet test-unit test-e2e #HELP Run all tests.
114118

115119
.PHONY: e2e
116120
e2e: $(SETUP_ENVTEST) #EXHELP Run the e2e tests.
117-
go test -tags $(GO_BUILD_TAGS) -v ./test/e2e/...
121+
go test -v ./test/e2e/...
118122

119-
export REG_PKG_NAME=registry-operator
120-
export PLAIN_PKG_NAME=plain-operator
121-
export CATALOG_IMG=${E2E_REGISTRY_NAME}.${E2E_REGISTRY_NAMESPACE}.svc:5000/test-catalog:e2e
123+
E2E_REGISTRY_NAME := docker-registry
124+
E2E_REGISTRY_NAMESPACE := operator-controller-e2e
125+
export REG_PKG_NAME := registry-operator
126+
export PLAIN_PKG_NAME := plain-operator
127+
export CATALOG_IMG := $(E2E_REGISTRY_NAME).$(E2E_REGISTRY_NAMESPACE).svc:5000/test-catalog:e2e
122128
.PHONY: test-ext-dev-e2e
123129
test-ext-dev-e2e: $(SETUP_ENVTEST) $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension create, upgrade and delete tests.
124-
test/extension-developer-e2e/setup.sh $(OPERATOR_SDK) $(CONTAINER_RUNTIME) $(KUSTOMIZE) $(KIND) $(KIND_CLUSTER_NAME) ${E2E_REGISTRY_NAMESPACE}
125-
go test -tags $(GO_BUILD_TAGS) -v ./test/extension-developer-e2e/...
130+
test/extension-developer-e2e/setup.sh $(OPERATOR_SDK) $(CONTAINER_RUNTIME) $(KUSTOMIZE) $(KIND) $(KIND_CLUSTER_NAME) $(E2E_REGISTRY_NAMESPACE)
131+
go test -v ./test/extension-developer-e2e/...
126132

127133
.PHONY: test-unit
128-
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
129-
UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/)
134+
ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
135+
UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/)
130136
test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests
131-
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out
137+
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && go test -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out
132138

133-
E2E_REGISTRY_NAME=docker-registry
134-
E2E_REGISTRY_NAMESPACE=operator-controller-e2e
135139
image-registry: ## Setup in-cluster image registry
136-
./test/tools/image-registry.sh ${E2E_REGISTRY_NAMESPACE} ${E2E_REGISTRY_NAME}
140+
./test/tools/image-registry.sh $(E2E_REGISTRY_NAMESPACE) $(E2E_REGISTRY_NAME)
137141

138142
build-push-e2e-catalog: ## Build the testdata catalog used for e2e tests and push it to the image registry
139-
./test/tools/build-push-e2e-catalog.sh ${E2E_REGISTRY_NAMESPACE} ${CATALOG_IMG}
143+
./test/tools/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(CATALOG_IMG)
140144

141145
.PHONY: test-e2e
142-
test-e2e: KIND_CLUSTER_NAME=operator-controller-e2e
143-
test-e2e: KUSTOMIZE_BUILD_DIR=config/e2e
144-
test-e2e: GO_BUILD_FLAGS=-cover
146+
test-e2e: KIND_CLUSTER_NAME := operator-controller-e2e
147+
test-e2e: KUSTOMIZE_BUILD_DIR := config/e2e
148+
test-e2e: GO_BUILD_FLAGS := -cover
145149
test-e2e: run image-registry build-push-e2e-catalog kind-load-test-artifacts e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster
146150

147151
.PHONY: extension-developer-e2e
148-
extension-developer-e2e: KIND_CLUSTER_NAME=operator-controller-ext-dev-e2e #EXHELP Run extension-developer e2e on local kind cluster
152+
extension-developer-e2e: KIND_CLUSTER_NAME := operator-controller-ext-dev-e2e #EXHELP Run extension-developer e2e on local kind cluster
149153
extension-developer-e2e: run image-registry test-ext-dev-e2e kind-clean
150154

151155
.PHONY: e2e-coverage
@@ -156,29 +160,29 @@ e2e-coverage:
156160
kind-load: $(KIND) #EXHELP Loads the currently constructed image onto the cluster.
157161
$(CONTAINER_RUNTIME) save $(IMG) | $(KIND) load image-archive /dev/stdin --name $(KIND_CLUSTER_NAME)
158162

159-
kind-deploy: export MANIFEST="./operator-controller.yaml"
163+
kind-deploy: export MANIFEST := ./operator-controller.yaml
160164
kind-deploy: manifests $(KUSTOMIZE) #EXHELP Install controller and dependencies onto the kind cluster.
161165
$(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) > operator-controller.yaml
162166
envsubst '$$CATALOGD_VERSION,$$CERT_MGR_VERSION,$$KAPP_VERSION,$$RUKPAK_VERSION,$$MANIFEST' < scripts/install.tpl.sh | bash -s
163167

164168
.PHONY: kind-cluster
165169
kind-cluster: $(KIND) #EXHELP Standup a kind cluster.
166-
-$(KIND) delete cluster --name ${KIND_CLUSTER_NAME}
170+
-$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)
167171
# kind-config.yaml can be deleted after upgrading to Kubernetes 1.30
168-
$(KIND) create cluster --name ${KIND_CLUSTER_NAME} --image ${KIND_CLUSTER_IMAGE} --config ./kind-config.yaml
169-
$(KIND) export kubeconfig --name ${KIND_CLUSTER_NAME}
172+
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_CLUSTER_IMAGE) --config ./kind-config.yaml
173+
$(KIND) export kubeconfig --name $(KIND_CLUSTER_NAME)
170174

171175
.PHONY: kind-clean
172176
kind-clean: $(KIND) #EXHELP Delete the kind cluster.
173-
$(KIND) delete cluster --name ${KIND_CLUSTER_NAME}
177+
$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)
174178

175179
.PHONY: kind-load-test-artifacts
176180
kind-load-test-artifacts: $(KIND) #EXHELP Load the e2e testdata container images into a kind cluster.
177-
$(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/registry-v1/prometheus-operator.v1.0.0 -t localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0
181+
$(CONTAINER_RUNTIME) build testdata/bundles/registry-v1/prometheus-operator.v1.0.0 -t localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0
178182
$(CONTAINER_RUNTIME) tag localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.1
179183
$(CONTAINER_RUNTIME) tag localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 localhost/testdata/bundles/registry-v1/prometheus-operator:v1.2.0
180184
$(CONTAINER_RUNTIME) tag localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 localhost/testdata/bundles/registry-v1/prometheus-operator:v2.0.0
181-
$(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/plain.v0.1.0 -t localhost/testdata/bundles/plain-v0/plain:v0.1.0
185+
$(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/plain.v0.1.0 -t localhost/testdata/bundles/plain-v0/plain:v0.1.0
182186
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 --name $(KIND_CLUSTER_NAME)
183187
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.1 --name $(KIND_CLUSTER_NAME)
184188
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.2.0 --name $(KIND_CLUSTER_NAME)
@@ -188,28 +192,35 @@ kind-load-test-artifacts: $(KIND) #EXHELP Load the e2e testdata container images
188192

189193
#SECTION Build
190194

191-
export VERSION ?= $(shell git describe --tags --always --dirty)
192-
export CGO_ENABLED ?= 0
193-
export GO_BUILD_ASMFLAGS ?= all=-trimpath=${PWD}
194-
export GO_BUILD_LDFLAGS ?= -s -w -X $(shell go list -m)/version.Version=$(VERSION)
195-
export GO_BUILD_GCFLAGS ?= all=-trimpath=${PWD}
196-
export GO_BUILD_TAGS ?= upstream
197-
export GO_BUILD_FLAGS ?=
195+
ifeq (,$(VERSION))
196+
VERSION := $(shell git describe --tags --always --dirty)
197+
endif
198+
export VERSION
199+
200+
ifeq (,$(CGO_ENABLED))
201+
CGO_ENABLED := 0
202+
endif
203+
export CGO_ENABLED
204+
205+
export GO_BUILD_ASMFLAGS := all=-trimpath=$(PWD)
206+
export GO_BUILD_LDFLAGS := -s -w -X $(shell go list -m)/version.Version=$(VERSION)
207+
export GO_BUILD_GCFLAGS := all=-trimpath=$(PWD)
208+
export GO_BUILD_FLAGS :=
198209

199-
BUILDCMD = go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(BUILDBIN)/manager ./cmd/manager
210+
BUILDCMD = go build $(GO_BUILD_FLAGS) -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(BUILDBIN)/manager ./cmd/manager
200211

201212
.PHONY: build-deps
202213
build-deps: manifests generate fmt vet
203214

204215
.PHONY: build go-build-local
205216
build: build-deps go-build-local #HELP Build manager binary for current GOOS and GOARCH. Default target.
206-
go-build-local: BUILDBIN = bin
217+
go-build-local: BUILDBIN := bin
207218
go-build-local:
208219
$(BUILDCMD)
209220

210221
.PHONY: build-linux go-build-linux
211222
build-linux: build-deps go-build-linux #EXHELP Build manager binary for GOOS=linux and local GOARCH.
212-
go-build-linux: BUILDBIN = bin/linux
223+
go-build-linux: BUILDBIN := bin/linux
213224
go-build-linux:
214225
GOOS=linux $(BUILDCMD)
215226

@@ -218,27 +229,33 @@ run: docker-build kind-cluster kind-load kind-deploy #HELP Build the operator-co
218229

219230
.PHONY: docker-build
220231
docker-build: build-linux #EXHELP Build docker image for operator-controller with GOOS=linux and local GOARCH.
221-
$(CONTAINER_RUNTIME) build -t ${IMG} -f Dockerfile ./bin/linux
232+
$(CONTAINER_RUNTIME) build -t $(IMG) -f Dockerfile ./bin/linux
222233

223234
#SECTION Release
235+
ifeq (, $(ENABLE_RELEASE_PIPELINE))
236+
ENABLE_RELEASE_PIPELINE := false
237+
endif
238+
ifeq (, $(GORELEASER_ARGS))
239+
GORELEASER_ARGS := --snapshot --clean
240+
endif
224241

225-
export ENABLE_RELEASE_PIPELINE ?= false
226-
export GORELEASER_ARGS ?= --snapshot --clean
242+
export ENABLE_RELEASE_PIPELINE
243+
export GORELEASER_ARGS
227244

228245
.PHONY: release
229246
release: $(GORELEASER) #EXHELP Runs goreleaser for the operator-controller. By default, this will run only as a snapshot and will not publish any artifacts unless it is run with different arguments. To override the arguments, run with "GORELEASER_ARGS=...". When run as a github action from a tag, this target will publish a full release.
230247
$(GORELEASER) $(GORELEASER_ARGS)
231248

232249
.PHONY: quickstart
233-
quickstart: export MANIFEST="https://github.com/operator-framework/operator-controller/releases/download/$(VERSION)/operator-controller.yaml"
250+
quickstart: export MANIFEST := https://github.com/operator-framework/operator-controller/releases/download/$(VERSION)/operator-controller.yaml
234251
quickstart: $(KUSTOMIZE) manifests #EXHELP Generate the installation release manifests and scripts.
235252
$(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) | sed "s/:devel/:$(VERSION)/g" > operator-controller.yaml
236253
envsubst '$$CATALOGD_VERSION,$$CERT_MGR_VERSION,$$KAPP_VERSION,$$RUKPAK_VERSION,$$MANIFEST' < scripts/install.tpl.sh > install.sh
237254

238255
##@ Docs
239256

240-
VENVDIR=$(abspath docs/.venv)
241-
REQUIREMENTS_TXT=docs/requirements.txt
257+
VENVDIR := $(abspath docs/.venv)
258+
REQUIREMENTS_TXT := docs/requirements.txt
242259

243260
.PHONY: build-docs
244261
build-docs: venv

0 commit comments

Comments
 (0)