Skip to content

Commit f93df96

Browse files
authored
Merge pull request #6 from BlaineEXE/prow-targets
clean up makefile and CI targets
2 parents a29e5f6 + 215cc7a commit f93df96

File tree

4 files changed

+75
-68
lines changed

4 files changed

+75
-68
lines changed

Makefile

+59-68
Original file line numberDiff line numberDiff line change
@@ -23,67 +23,83 @@ help: ## Display this help.
2323
# If GOARCH is not set in the env, find it
2424
GOARCH ?= $(shell go env GOARCH)
2525

26-
##
27-
## ==== ARGS ===== #
26+
#
27+
# ==== ARGS =====
28+
#
2829

29-
## Container build tool compatible with `docker` API
30+
# Container build tool compatible with `docker` API
3031
DOCKER ?= docker
3132

32-
## Platform for 'build'
33+
# Tool compatible with `kubectl` API
34+
KUBECTL ?= kubectl
35+
36+
# Platform for 'build'
3337
PLATFORM ?= linux/$(GOARCH)
3438

35-
## Additional args for 'build'
39+
# Additional args for 'build'
3640
BUILD_ARGS ?=
3741

38-
## Image tag for controller image build
42+
# Image tag for controller image build
3943
CONTROLLER_TAG ?= cosi-controller:latest
4044

41-
## Image tag for sidecar image build
45+
# Image tag for sidecar image build
4246
SIDECAR_TAG ?= cosi-provisioner-sidecar:latest
4347

44-
## Location to install dependencies to
45-
TOOLBIN ?= $(CURDIR)/.cache/tools
46-
$(TOOLBIN):
47-
mkdir -p $(TOOLBIN)
48-
4948
##@ Development
5049

51-
.PHONY: all .gen
52-
.gen: generate codegen # can be done in parallel with 'make -j'
53-
.NOTPARALLEL: all # codegen must be finished before fmt/vet
54-
all: .gen fmt vet build ## Build all targets, plus their prerequisites (faster with 'make -j')
55-
5650
.PHONY: generate
5751
generate: controller/Dockerfile sidecar/Dockerfile ## Generate files
5852
$(MAKE) -C client crds
5953
$(MAKE) -C proto generate
54+
%/Dockerfile: hack/Dockerfile.in hack/gen-dockerfile.sh
55+
hack/gen-dockerfile.sh $* > "$@"
6056

6157
.PHONY: codegen
6258
codegen: codegen.client codegen.proto ## Generate code
59+
codegen.%: FORCE
60+
$(MAKE) -C $* codegen
6361

6462
.PHONY: fmt
6563
fmt: fmt.client fmt.controller fmt.sidecar ## Format code
64+
fmt.%: FORCE
65+
cd $* && go fmt ./...
6666

6767
.PHONY: vet
6868
vet: vet.client vet.controller vet.sidecar ## Vet code
69+
vet.%: FORCE
70+
cd $* && go vet ./...
6971

7072
.PHONY: test
71-
test: .test.proto test.client test.controller test.sidecar ## Run tests including unit tests
73+
test: .test.proto test.client test.controller test.sidecar ## Run all unit tests including vet and fmt
74+
test.%: fmt.% vet.% FORCE
75+
cd $* && go test ./...
76+
.PHONY: .test.proto
77+
.test.proto: # gRPC proto has a special unit test
78+
$(MAKE) -C proto check
7279

7380
.PHONY: test-e2e
7481
test-e2e: chainsaw # Run e2e tests against the K8s cluster specified in ~/.kube/config. It requires both controller and driver deployed. If you need to create a cluster beforehand, consider using 'cluster' and 'deploy' targets.
7582
$(CHAINSAW) test --values ./test/e2e/values.yaml
7683

7784
.PHONY: lint
7885
lint: golangci-lint.client golangci-lint.controller golangci-lint.sidecar ## Run all linters (suggest `make -k`)
86+
golangci-lint.%: golangci-lint
87+
cd $* && $(GOLANGCI_LINT) run --config $(CURDIR)/.golangci.yaml --new
7988

8089
.PHONY: lint-fix
8190
lint-fix: golangci-lint-fix.client golangci-lint-fix.controller golangci-lint-fix.sidecar ## Run all linters and perform fixes where possible (suggest `make -k`)
91+
golangci-lint-fix.%: golangci-lint
92+
cd $* && $(GOLANGCI_LINT) run --config $(CURDIR)/.golangci.yaml --new --fix
8293

8394
##@ Build
8495

96+
.PHONY: all .gen
97+
.gen: generate codegen # can be done in parallel with 'make -j'
98+
.NOTPARALLEL: all # codegen must be finished before fmt/vet
99+
all: .gen fmt vet build ## Build all container images, plus their prerequisites (faster with 'make -j')
100+
85101
.PHONY: build
86-
build: build.controller build.sidecar ## Build all container images for development
102+
build: build.controller build.sidecar ## Build container images without prerequisites
87103

88104
.PHONY: build.controller build.sidecar
89105
build.controller: controller/Dockerfile ## Build only the controller container image
@@ -92,49 +108,15 @@ build.sidecar: sidecar/Dockerfile ## Build only the sidecar container image
92108
$(DOCKER) build --file sidecar/Dockerfile --platform $(PLATFORM) $(BUILD_ARGS) --tag $(SIDECAR_TAG) .
93109

94110
.PHONY: clean
95-
## Clean build environment
96-
clean:
111+
clean: ## Clean build environment
97112
$(MAKE) -C proto clean
98113

99114
.PHONY: clobber
100-
## Clean build environment and cached tools
101-
clobber:
115+
clobber: ## Clean build environment and cached tools
102116
$(MAKE) -C proto clobber
103117
rm -rf $(TOOLBIN)
104118
rm -rf $(CURDIR)/.cache
105119

106-
##
107-
## === INTERMEDIATES === #
108-
109-
%/Dockerfile: hack/Dockerfile.in hack/gen-dockerfile.sh
110-
hack/gen-dockerfile.sh $* > "$@"
111-
112-
codegen.%: FORCE
113-
$(MAKE) -C $* codegen
114-
115-
fmt.%: FORCE
116-
cd $* && go fmt ./...
117-
118-
vet.%: FORCE
119-
cd $* && go vet ./...
120-
121-
test.%: fmt.% vet.% FORCE
122-
cd $* && go test ./...
123-
124-
# golangci-lint --new flag only complains about new code
125-
golangci-lint.%: $(GOLANGCI_LINT)
126-
cd $* && $(GOLANGCI_LINT) run --config $(CURDIR)/.golangci.yaml --new
127-
128-
golangci-lint-fix.%: $(GOLANGCI_LINT)
129-
cd $* && $(GOLANGCI_LINT) run --config $(CURDIR)/.golangci.yaml --new --fix
130-
131-
.PHONY: .test.proto
132-
.test.proto: # gRPC proto has a special unit test
133-
$(MAKE) -C proto check
134-
135-
.PHONY: FORCE # use this to force phony behavior for targets with pattern rules
136-
FORCE:
137-
138120
##@ Deployment
139121

140122
.PHONY: cluster
@@ -146,52 +128,58 @@ cluster-reset: kind ctlptl ## Delete Kind cluster
146128
$(CTLPTL) delete -f ctlptl.yaml
147129

148130
.PHONY: deploy
149-
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. The 'generate' and 'codegen' targets should be run manually, and are expected to be run at least once before the 'deploy' target, as those are not cached.
131+
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config
150132
$(KUSTOMIZE) build . | $(KUBECTL) apply -f -
151133

152134
.PHONY: undeploy
153-
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
135+
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config
154136
$(KUSTOMIZE) build . | $(KUBECTL) delete --ignore-not-found=true -f -
155137

156-
##@ Tools
138+
#
139+
# ===== Tools =====
140+
#
141+
142+
# Location to install dependencies to
143+
TOOLBIN ?= $(CURDIR)/.cache/tools
144+
$(TOOLBIN):
145+
mkdir -p $(TOOLBIN)
157146

158-
## Tool Binaries
147+
# Tool Binaries
159148
CHAINSAW ?= $(TOOLBIN)/chainsaw
160149
CTLPTL ?= $(TOOLBIN)/ctlptl
161-
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
150+
GOLANGCI_LINT ?= $(TOOLBIN)/golangci-lint
162151
KIND ?= $(TOOLBIN)/kind
163-
KUBECTL ?= kubectl ## Special case, we do not manage it via tools.go
164152
KUSTOMIZE ?= $(TOOLBIN)/kustomize
165153

166-
## Tool Versions
154+
# Tool Versions
167155
CHAINSAW_VERSION ?= $(shell grep 'github.com/kyverno/chainsaw ' ./hack/tools/go.mod | cut -d ' ' -f 2)
168156
CTLPTL_VERSION ?= $(shell grep 'github.com/tilt-dev/ctlptl ' ./hack/tools/go.mod | cut -d ' ' -f 2)
169157
GOLANGCI_LINT_VERSION ?= $(shell grep 'github.com/golangci/golangci-lint ' ./hack/tools/go.mod | cut -d ' ' -f 2)
170158
KIND_VERSION ?= $(shell grep 'sigs.k8s.io/kind ' ./hack/tools/go.mod | cut -d ' ' -f 2)
171159
KUSTOMIZE_VERSION ?= $(shell grep 'sigs.k8s.io/kustomize/kustomize/v5 ' ./hack/tools/go.mod | cut -d ' ' -f 2)
172160

173161
.PHONY: chainsaw
174-
chainsaw: $(CHAINSAW)$(CHAINSAW_VERSION) ## Download chainsaw locally if necessary.
162+
chainsaw: $(CHAINSAW)$(CHAINSAW_VERSION)
175163
$(CHAINSAW)$(CHAINSAW_VERSION): $(TOOLBIN)
176164
$(call go-install-tool,$(CHAINSAW),github.com/kyverno/chainsaw,$(CHAINSAW_VERSION))
177165

178166
.PHONY: ctlptl
179-
ctlptl: $(CTLPTL)$(CTLPTL_VERSION) ## Download ctlptl locally if necessary.
167+
ctlptl: $(CTLPTL)$(CTLPTL_VERSION)
180168
$(CTLPTL)$(CTLPTL_VERSION): $(TOOLBIN)
181169
$(call go-install-tool,$(CTLPTL),github.com/tilt-dev/ctlptl/cmd/ctlptl,$(CTLPTL_VERSION))
182170

183171
.PHONY: golangci-lint
184-
golangci-lint: $(GOLANGCI_LINT)$(GOLANGCI_LINT_VERSION) ## Download golangci-lint locally if necessary.
185-
$(GOLANGCI_LINT)$(GOLANGCI_LINT_VERSION): $(LOCALBIN)
172+
golangci-lint: $(GOLANGCI_LINT)$(GOLANGCI_LINT_VERSION)
173+
$(GOLANGCI_LINT)$(GOLANGCI_LINT_VERSION): $(TOOLBIN)
186174
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
187175

188176
.PHONY: kind
189-
kind: $(KIND)$(KIND_VERSION) ## Download kind locally if necessary.
177+
kind: $(KIND)$(KIND_VERSION)
190178
$(KIND)$(KIND_VERSION): $(TOOLBIN)
191179
$(call go-install-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))
192180

193181
.PHONY: kustomize
194-
kustomize: $(KUSTOMIZE)$(KUSTOMIZE_VERSION) ## Download kustomize locally if necessary.
182+
kustomize: $(KUSTOMIZE)$(KUSTOMIZE_VERSION)
195183
$(KUSTOMIZE)$(KUSTOMIZE_VERSION): $(TOOLBIN)
196184
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
197185

@@ -210,3 +198,6 @@ mv $(1) $(1)-$(3) ;\
210198
} ;\
211199
ln -sf $(1)-$(3) $(1)
212200
endef
201+
202+
.PHONY: FORCE # use this to force phony behavior for targets with pattern rules
203+
FORCE:

hack/cloudbuild.sh

100644100755
File mode changed.

hack/prow-check-generate.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
set -o xtrace
5+
6+
# TODO: make fmt generate codegen
7+
# TODO: check git for file changes
8+
echo "intentionally running no commands"

hack/prow-e2e.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
set -o xtrace
5+
6+
# TODO: set up prow environment as needed
7+
# TODO: run e2e tests
8+
echo "intentionally running no commands"

0 commit comments

Comments
 (0)