@@ -40,6 +40,8 @@ export DOCKER_CLI_EXPERIMENTAL := enabled
40
40
TOOLS_DIR := $(ROOT ) /hack/tools
41
41
TOOLS_BIN_DIR := $(TOOLS_DIR ) /bin
42
42
BIN_DIR := bin
43
+ GO_APIDIFF_BIN := $(BIN_DIR ) /go-apidiff
44
+ GO_APIDIFF := $(TOOLS_DIR ) /$(GO_APIDIFF_BIN )
43
45
44
46
export PATH := $(abspath $(TOOLS_BIN_DIR ) ) :$(PATH )
45
47
@@ -54,6 +56,7 @@ CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
54
56
GOLANGCI_LINT := $(TOOLS_BIN_DIR ) /golangci-lint
55
57
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR ) /kustomize)
56
58
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR ) /setup-envtest)
59
+ GOTESTSUM := $(abspath $(TOOLS_BIN_DIR ) /gotestsum)
57
60
58
61
# Define Docker related variables. Releases should modify and double check these vars.
59
62
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
@@ -83,6 +86,8 @@ help: ## Display this help
83
86
# # Testing
84
87
# # --------------------------------------
85
88
89
+ ARTIFACTS ?= ${ROOT}/_artifacts
90
+
86
91
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST ) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ) )
87
92
88
93
.PHONY : test
@@ -93,38 +98,77 @@ test: $(SETUP_ENVTEST) ## Run unit and integration tests
93
98
test-verbose : # # Run tests with verbose settings.
94
99
TEST_ARGS=" $( TEST_ARGS) -v" $(MAKE ) test
95
100
101
+ .PHONY : test-junit
102
+ test-junit : $(SETUP_ENVTEST ) $(GOTESTSUM ) # # Run tests with verbose setting and generate a junit report
103
+ set +o errexit; (KUBEBUILDER_ASSETS=" $( KUBEBUILDER_ASSETS) " go test -json ./... $( TEST_ARGS) ; echo $$ ? > $( ARTIFACTS) /junit.exitcode) | tee $(ARTIFACTS ) /junit.stdout
104
+ $(GOTESTSUM ) --junitfile $(ARTIFACTS ) /junit.xml --raw-command cat $(ARTIFACTS ) /junit.stdout
105
+ exit $$(cat $(ARTIFACTS ) /junit.exitcode )
106
+
96
107
# # --------------------------------------
97
108
# # Binaries
98
109
# # --------------------------------------
99
110
100
111
.PHONY : operator
101
112
operator : # # Build operator binary
102
- go build -ldflags " $( LDFLAGS) " -o $(BIN_DIR ) /operator sigs.k8s.io/cluster-api-operator
113
+ go build -trimpath - ldflags " $( LDFLAGS) " -o $(BIN_DIR ) /operator sigs.k8s.io/cluster-api-operator
103
114
104
115
$(CONTROLLER_GEN ) : $(TOOLS_DIR ) /go.mod # Build controller-gen from tools folder.
105
116
cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
106
117
107
- $(GOLANGCI_LINT ) : $(TOOLS_DIR ) /go.mod # Build golangci-lint from tools folder.
108
- cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
109
-
110
118
$(KUSTOMIZE ) : # Build kustomize from tools folder.
111
119
$(ROOT ) /hack/ensure-kustomize.sh
112
120
113
121
$(SETUP_ENVTEST ) : $(TOOLS_DIR ) /go.mod # Build setup-envtest from tools folder.
114
122
cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /setup-envtest sigs.k8s.io/controller-runtime/tools/setup-envtest
115
123
124
+ $(GOTESTSUM ) : $(TOOLS_DIR ) /go.mod # Build gotestsum from tools folder.
125
+ cd $(TOOLS_DIR ) ; go build -tags=tools -o $(BIN_DIR ) /gotestsum gotest.tools/gotestsum
126
+
127
+ $(GOLANGCI_LINT ) : .github/workflows/golangci-lint.yml # Download golanci-lint using hack script into tools folder.
128
+ hack/ensure-golangci-lint.sh \
129
+ -b $(TOOLS_DIR ) /$(BIN_DIR ) \
130
+ $(shell cat .github/workflows/golangci-lint.yml | grep version | sed 's/.* version: //')
131
+
132
+ $(GO_APIDIFF ) : $(TOOLS_DIR ) /go.mod # Build go-apidiff from tools folder.
133
+ cd $(TOOLS_DIR ) && go build -tags=tools -o $(GO_APIDIFF_BIN ) github.com/joelanford/go-apidiff
134
+
116
135
kustomize : $(KUSTOMIZE ) # # Build a local copy of kustomize.
117
136
118
137
# # --------------------------------------
119
- # # Linting
138
+ # # Lint / Verify
120
139
# # --------------------------------------
121
140
122
141
.PHONY : lint lint-full
123
- lint : $(GOLANGCI_LINT ) # # Lint codebase
124
- $(GOLANGCI_LINT ) run -v
142
+ lint : $(GOLANGCI_LINT ) # # Lint the codebase
143
+ $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
144
+ cd $(TOOLS_DIR ) ; $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
145
+
146
+ .PHONY : lint-fix
147
+ lint-fix : $(GOLANGCI_LINT ) # # Lint the codebase and run auto-fixers if supported by the linter
148
+ GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE ) lint
149
+
150
+ .PHONY : apidiff
151
+ apidiff : $(GO_APIDIFF ) # # Check for API differences
152
+ $(GO_APIDIFF ) $(shell git rev-parse origin/main) --print-compatible
153
+
154
+ .PHONY : verify
155
+ verify :
156
+ $(MAKE ) verify-modules
157
+ $(MAKE ) verify-gen
125
158
126
- lint-full : $(GOLANGCI_LINT ) # # Run slower linters to detect possible issues
127
- $(GOLANGCI_LINT ) run -v --fast=false
159
+ .PHONY : verify-modules
160
+ verify-modules : modules
161
+ @if ! (git diff --quiet HEAD -- go.sum go.mod $( TOOLS_DIR) /go.mod $( TOOLS_DIR) /go.sum); then \
162
+ git diff; \
163
+ echo " go module files are out of date" ; exit 1; \
164
+ fi
165
+
166
+ .PHONY : verify-gen
167
+ verify-gen : generate
168
+ @if ! (git diff --quiet HEAD); then \
169
+ git diff; \
170
+ echo " generated files are out of date, run make generate" ; exit 1; \
171
+ fi
128
172
129
173
# # --------------------------------------
130
174
# # Generate / Manifests
@@ -170,7 +214,7 @@ docker-pull-prerequisites:
170
214
171
215
.PHONY : docker-build
172
216
docker-build : # # Build the docker image for management cluster operator
173
- DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY ) --build-arg ARCH=$(ARCH ) --build-arg ldflags=" $( LDFLAGS) " . -f $( ROOT ) Dockerfile - t $(CONTROLLER_IMG ) -$(ARCH ) :$(TAG )
217
+ DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY ) --build-arg ARCH=$(ARCH ) --build-arg ldflags=" $( LDFLAGS) " . -t $(CONTROLLER_IMG ) -$(ARCH ) :$(TAG )
174
218
$(MAKE ) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG ) -$(ARCH ) MANIFEST_TAG=$(TAG ) TARGET_RESOURCE=" ./config/default/manager_image_patch.yaml"
175
219
$(MAKE ) set-manifest-pull-policy TARGET_RESOURCE=" ./config/default/manager_pull_policy.yaml"
176
220
@@ -281,21 +325,3 @@ clean-bin: ## Remove all generated binaries
281
325
clean-release : # # Remove the release folder
282
326
rm -rf $(RELEASE_DIR )
283
327
284
- .PHONY : verify
285
- verify :
286
- $(MAKE ) verify-modules
287
- $(MAKE ) verify-gen
288
-
289
- .PHONY : verify-modules
290
- verify-modules : modules
291
- @if ! (git diff --quiet HEAD -- go.sum go.mod $( TOOLS_DIR) /go.mod $( TOOLS_DIR) /go.sum); then \
292
- git diff; \
293
- echo " go module files are out of date" ; exit 1; \
294
- fi
295
-
296
- .PHONY : verify-gen
297
- verify-gen : generate
298
- @if ! (git diff --quiet HEAD); then \
299
- git diff; \
300
- echo " generated files are out of date, run make generate" ; exit 1; \
301
- fi
0 commit comments