@@ -29,6 +29,23 @@ MOCKGEN_VERSION := 0.6.0 # renovate: datasource=github-releases depName=uber-go/
2929
3030GOPROXY =https://proxy.golang.org
3131
32+ # Directories to run golangci-lint in
33+ LINT_DIRS := . api properties tests/e2e \
34+ third_party/github.com/banzaicloud/operator-tools \
35+ third_party/github.com/banzaicloud/k8s-objectmatcher \
36+ third_party/github.com/banzaicloud/go-cruise-control
37+
38+ # Directories to run licensei check/cache in
39+ LICENSE_CHECK_DIRS := . \
40+ third_party/github.com/banzaicloud/operator-tools \
41+ third_party/github.com/banzaicloud/k8s-objectmatcher \
42+ third_party/github.com/banzaicloud/go-cruise-control
43+
44+ # Directories to run licensei header in
45+ LICENSE_HEADER_DIRS := \
46+ third_party/github.com/banzaicloud/k8s-objectmatcher \
47+ third_party/github.com/banzaicloud/go-cruise-control
48+
3249# Use BIN_DIR to form an absolute, stable path regardless of `cd` usage
3350CONTROLLER_GEN = $(BIN_DIR ) /controller-gen
3451
@@ -62,6 +79,16 @@ clean: ## Clean build artifacts and test binaries
6279 fi
6380 @rm -f cover.out
6481 @rm -f manager_image_patch.yaml
82+ @echo " Cleaning third_party/github.com/banzaicloud/operator-tools..."
83+ @if [ -d " third_party/github.com/banzaicloud/operator-tools/bin" ]; then \
84+ chmod -R u+w third_party/github.com/banzaicloud/operator-tools/bin/ 2> /dev/null || true ; \
85+ rm -rf third_party/github.com/banzaicloud/operator-tools/bin/; \
86+ fi
87+ @echo " Cleaning third_party/github.com/banzaicloud/k8s-objectmatcher..."
88+ @if [ -d " third_party/github.com/banzaicloud/k8s-objectmatcher/bin" ]; then \
89+ chmod -R u+w third_party/github.com/banzaicloud/k8s-objectmatcher/bin/ 2> /dev/null || true ; \
90+ rm -rf third_party/github.com/banzaicloud/k8s-objectmatcher/bin/; \
91+ fi
6592
6693bin/golangci-lint : bin/golangci-lint-${GOLANGCI_VERSION} # # Symlink golangi-lint-<version> into versionless golangci-lint.
6794 @ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
@@ -72,14 +99,22 @@ bin/golangci-lint-${GOLANGCI_VERSION}: ## Download versioned golangci-lint.
7299
73100.PHONY : lint
74101lint : bin/golangci-lint # # Run linter analysis.
75- bin/golangci-lint run -c ./.golangci.yml --timeout=5m
76- cd api && ../bin/golangci-lint run -c ../.golangci.yml --timeout=5m
77- cd properties && ../bin/golangci-lint run -c ../.golangci.yml --timeout=5m
78- cd tests/e2e && ../../bin/golangci-lint run -c .golangci.yml --timeout=5m
102+ @for dir in $(LINT_DIRS ) ; do \
103+ echo " Running lint in $$ dir" ; \
104+ (cd $$ dir && $( CURDIR) /bin/golangci-lint run -c $( CURDIR) /.golangci.yml --timeout=5m) || exit 1; \
105+ done
106+
107+ .PHONY : lint-fix
108+ lint-fix : bin/golangci-lint # # Run linter with automatic fixes.
109+ @for dir in $(LINT_DIRS ) ; do \
110+ echo " Running lint-fix in $$ dir" ; \
111+ (cd $$ dir && $( CURDIR) /bin/golangci-lint run -c $( CURDIR) /.golangci.yml --fix --timeout=5m) || exit 1; \
112+ done
79113
80- .PHONY : lint-fix # # Run linter with automatic fixes.
81- lint-fix : bin/golangci-lint # # Run linter
82- @bin/golangci-lint run -v --fix
114+ .PHONY : lint-clean
115+ lint-clean : bin/golangci-lint # # Clean linter cache.
116+ @echo " Cleaning golangci-lint cache..."
117+ bin/golangci-lint cache clean
83118
84119bin/licensei : bin/licensei-${LICENSEI_VERSION} # # Symlink licensei-<version> into versionless licensei.
85120 @ln -sf licensei-${LICENSEI_VERSION} bin/licensei
@@ -90,11 +125,24 @@ bin/licensei-${LICENSEI_VERSION}: ## Download versioned licensei.
90125
91126.PHONY : license-check
92127license-check : bin/licensei # # Run license check.
93- bin/licensei check
128+ @for dir in $(LICENSE_CHECK_DIRS ) ; do \
129+ echo " Running license check in $$ dir..." ; \
130+ (cd $$ dir && $( CURDIR) /bin/licensei check) || exit 1; \
131+ done
94132
95133.PHONY : license-cache
96134license-cache : bin/licensei # # Generate license cache.
97- bin/licensei cache
135+ @for dir in $(LICENSE_CHECK_DIRS ) ; do \
136+ echo " Generating license cache in $$ dir..." ; \
137+ (cd $$ dir && $( CURDIR) /bin/licensei cache) || exit 1; \
138+ done
139+
140+ .PHONY : license
141+ license : bin/licensei # # Add license headers to source files.
142+ @for dir in $(LICENSE_HEADER_DIRS ) ; do \
143+ echo " Adding license headers in $$ dir..." ; \
144+ (cd $$ dir && $( CURDIR) /bin/licensei header) || exit 1; \
145+ done
98146
99147install-kustomize : # # Install kustomize.
100148 @ if ! which bin/kustomize & > /dev/null; then\
@@ -113,6 +161,15 @@ test: generate fmt vet bin/setup-envtest
113161 -test.paniconexit0 \
114162 -timeout 1h
115163 cd properties && go test -coverprofile cover.out -cover -failfast -v -covermode=count ./pkg/... ./internal/...
164+ @echo " Running tests in third_party/github.com/banzaicloud/operator-tools..."
165+ cd third_party/github.com/banzaicloud/operator-tools && \
166+ KUBEBUILDER_ASSETS=$$($(BIN_DIR ) /setup-envtest --print path --bin-dir $(BIN_DIR ) use $(ENVTEST_K8S_VERSION ) ) \
167+ go test ./... -v -failfast
168+ @echo " Running tests in third_party/github.com/banzaicloud/k8s-objectmatcher..."
169+ cd third_party/github.com/banzaicloud/k8s-objectmatcher && go test ./...
170+ @echo " Running tests in third_party/github.com/banzaicloud/go-cruise-control..."
171+ cd third_party/github.com/banzaicloud/go-cruise-control && \
172+ go test -v -parallel 2 -failfast ./... -cover -covermode=count -coverprofile cover.out -test.v -test.paniconexit0
116173
117174# Run e2e tests
118175test-e2e :
@@ -158,15 +215,38 @@ fmt: ## Run go fmt against code.
158215 cd api && go fmt ./...
159216 cd properties && go fmt ./...
160217 cd tests/e2e && go fmt ./...
218+ @echo " Running fmt in third_party/github.com/banzaicloud/k8s-objectmatcher..."
219+ cd third_party/github.com/banzaicloud/k8s-objectmatcher && go fmt ./...
220+ @echo " Running fmt in third_party/github.com/banzaicloud/go-cruise-control..."
221+ cd third_party/github.com/banzaicloud/go-cruise-control && go fmt ./...
161222
162223vet : # # Run go vet against code.
163224 go vet ./...
164225 cd api && go fmt ./...
165226 cd properties && go vet ./...
166227 cd tests/e2e && go vet ./...
228+ @echo " Running vet in third_party/github.com/banzaicloud/k8s-objectmatcher..."
229+ cd third_party/github.com/banzaicloud/k8s-objectmatcher && go vet ./...
230+ @echo " Running vet in third_party/github.com/banzaicloud/go-cruise-control..."
231+ cd third_party/github.com/banzaicloud/go-cruise-control && go vet ./...
167232
168233generate : bin/controller-gen gen-license-header # # Generate source code for APIs, Mocks, etc.
169234 cd api && $(CONTROLLER_GEN ) object:headerFile=$(BOILERPLATE_DIR ) /header.go.generated.txt paths=" ./..."
235+ @echo " Running generate in third_party/github.com/banzaicloud/operator-tools..."
236+ cd third_party/github.com/banzaicloud/operator-tools && \
237+ $(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/secret/... && \
238+ $(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/volume/... && \
239+ $(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/prometheus/... && \
240+ $(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/types/... && \
241+ $(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/typeoverride/... && \
242+ $(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/helm/...
243+ @echo " Generating type documentation for operator-tools..."
244+ cd third_party/github.com/banzaicloud/operator-tools && go run cmd/docs.go
245+
246+ .PHONY : check-diff
247+ check-diff : generate # # Check for uncommitted changes
248+ @echo " Checking for uncommitted changes ..."
249+ git diff --exit-code
170250
171251docker-build : # # Build the operator docker image.
172252 docker build . -t ${IMG}
0 commit comments