@@ -98,37 +98,6 @@ clobber:
9898 $(MAKE ) -C proto clobber
9999 rm -rf $(CURDIR ) /.cache
100100
101- # #
102- # # === TOOLS === #
103-
104- GOLANGCI_LINT_VERSION ?= v1.61.0
105-
106- TOOLBIN ?= $(CURDIR ) /.cache/tools
107- $(TOOLBIN ) :
108- mkdir -p $(TOOLBIN )
109-
110- GOLANGCI_LINT ?= $(TOOLBIN ) /golangci-lint
111- # .PHONY: golangci-lint
112- # golangci-lint: $(GOLANGCI_LINT)
113- $(GOLANGCI_LINT ) : $(TOOLBIN )
114- $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
115-
116- # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
117- # $1 - target path with name of binary
118- # $2 - package url which can be installed
119- # $3 - specific version of package
120- define go-install-tool
121- @[ -f "$(1 ) -$(3 ) " ] || { \
122- set -e; \
123- package=$(2 ) @$(3 ) ;\
124- echo "Downloading $${package}" ;\
125- rm -f $(1 ) || true ;\
126- GOBIN=$(TOOLBIN ) go install $${package} ;\
127- mv $(1 ) $(1 ) -$(3 ) ;\
128- } ;\
129- ln -sf $(1 ) -$(3 ) $(1 )
130- endef
131-
132101# #
133102# # === INTERMEDIATES === #
134103
@@ -160,3 +129,88 @@ golangci-lint-fix.%: $(GOLANGCI_LINT)
160129
161130.PHONY : FORCE # use this to force phony behavior for targets with pattern rules
162131FORCE :
132+
133+ # #@ Deployment
134+
135+ .PHONY : cluster
136+ cluster : kind ctlptl # # Create Kind cluster and local registry
137+ $(CTLPTL ) apply -f ctlptl.yaml
138+
139+ .PHONY : cluster-reset
140+ cluster-reset : kind ctlptl # # Delete Kind cluster
141+ $(CTLPTL ) delete -f ctlptl.yaml
142+
143+ ifndef ignore-not-found
144+ ignore-not-found = false
145+ endif
146+
147+ .PHONY : deploy
148+ deploy : .gen kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
149+ $(KUSTOMIZE ) build . | $(KUBECTL ) apply -f -
150+
151+ .PHONY : undeploy
152+ undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
153+ $(KUSTOMIZE ) build . | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
154+
155+ # #@ Tools
156+
157+ # # Location to install dependencies to
158+ TOOLBIN ?= $(CURDIR ) /.cache/tools
159+ $(TOOLBIN ) :
160+ mkdir -p $(TOOLBIN )
161+
162+ # # Tool Binaries
163+ CHAINSAW ?= $(TOOLBIN ) /chainsaw
164+ CTLPTL ?= $(TOOLBIN ) /ctlptl
165+ GOLANGCI_LINT ?= $(LOCALBIN ) /golangci-lint
166+ KIND ?= $(TOOLBIN ) /kind
167+ KUBECTL ?= kubectl # # Special case, we do not manage it via tools.go
168+ KUSTOMIZE ?= $(TOOLBIN ) /kustomize
169+
170+ # # Tool Versions
171+ CHAINSAW_VERSION ?= $(shell grep 'github.com/kyverno/chainsaw ' ./hack/tools/go.mod | cut -d ' ' -f 2)
172+ CTLPTL_VERSION ?= $(shell grep 'github.com/tilt-dev/ctlptl ' ./hack/tools/go.mod | cut -d ' ' -f 2)
173+ GOLANGCI_LINT_VERSION ?= $(shell grep 'github.com/golangci/golangci-lint ' ./hack/tools/go.mod | cut -d ' ' -f 2)
174+ KIND_VERSION ?= $(shell grep 'sigs.k8s.io/kind ' ./hack/tools/go.mod | cut -d ' ' -f 2)
175+ KUSTOMIZE_VERSION ?= $(shell grep 'sigs.k8s.io/kustomize/kustomize/v5 ' ./hack/tools/go.mod | cut -d ' ' -f 2)
176+
177+ .PHONY : chainsaw
178+ chainsaw : $(CHAINSAW )$(CHAINSAW_VERSION ) # # Download chainsaw locally if necessary.
179+ $(CHAINSAW )$(CHAINSAW_VERSION ) : $(TOOLBIN )
180+ $(call go-install-tool,$(CHAINSAW ) ,github.com/kyverno/chainsaw,$(CHAINSAW_VERSION ) )
181+
182+ .PHONY : ctlptl
183+ ctlptl : $(CTLPTL )$(CTLPTL_VERSION ) # # Download ctlptl locally if necessary.
184+ $(CTLPTL )$(CTLPTL_VERSION ) : $(TOOLBIN )
185+ $(call go-install-tool,$(CTLPTL ) ,github.com/tilt-dev/ctlptl/cmd/ctlptl,$(CTLPTL_VERSION ) )
186+
187+ .PHONY : golangci-lint
188+ golangci-lint : $(GOLANGCI_LINT )$(GOLANGCI_LINT_VERSION ) # # Download golangci-lint locally if necessary.
189+ $(GOLANGCI_LINT )$(GOLANGCI_LINT_VERSION ) : $(LOCALBIN )
190+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
191+
192+ .PHONY : kind
193+ kind : $(KIND )$(KIND_VERSION ) # # Download kind locally if necessary.
194+ $(KIND )$(KIND_VERSION ) : $(TOOLBIN )
195+ $(call go-install-tool,$(KIND ) ,sigs.k8s.io/kind,$(KIND_VERSION ) )
196+
197+ .PHONY : kustomize
198+ kustomize : $(KUSTOMIZE )$(KUSTOMIZE_VERSION ) # # Download kustomize locally if necessary.
199+ $(KUSTOMIZE )$(KUSTOMIZE_VERSION ) : $(TOOLBIN )
200+ $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
201+
202+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
203+ # $1 - target path with name of binary
204+ # $2 - package url which can be installed
205+ # $3 - specific version of package
206+ define go-install-tool
207+ @[ -f "$(1 ) -$(3 ) " ] || { \
208+ set -e; \
209+ package=$(2 ) @$(3 ) ;\
210+ echo "Downloading $${package}" ;\
211+ rm -f $(1 ) || true ;\
212+ GOBIN=$(TOOLBIN ) go install $${package} ;\
213+ mv $(1 ) $(1 ) -$(3 ) ;\
214+ } ;\
215+ ln -sf $(1 ) -$(3 ) $(1 )
216+ endef
0 commit comments