@@ -13,59 +13,65 @@ all: build
1313# #@ General
1414
1515.PHONY : help
16- help : # # Display this help.
17- @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s \033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
16+ help : # # Display this help
17+ @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s \033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
1818
1919# #@ Development
2020
2121.PHONY : manifests
22- manifests : controller-gen # # Generate CustomResourceDefinition objects.
23- $(CONTROLLER_GEN ) crd paths=" ./api/..." output:crd:artifacts:config=crds ; \
22+ manifests : controller-gen # # Generate CustomResourceDefinition objects
23+ $(LOCALBIN ) /controller-gen crd paths=" ./api/..." output:crd:artifacts:config=crds && \
2424 test ! -d chart || test -e chart/crds || ln -s ../crds chart/crds
2525
2626.PHONY : generate
27- generate : controller-gen client-gen informer-gen lister-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations, and generate typed client.
28- $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./api/..."
27+ generate : generate-deepcopy generate-client # # Generate required code pieces
28+
29+ .PHONY : generate-deepcopy
30+ generate-deepcopy : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations
31+ $(LOCALBIN ) /controller-gen object:headerFile=" hack/boilerplate.go.txt" paths=" ./api/..."
32+
33+ .PHONY : generate-client
34+ generate-client : # # Generate typed client
2935 ./hack/genclient.sh
3036
3137.PHONY : fmt
32- fmt : # # Run go fmt against code.
38+ fmt : # # Run go fmt against code
3339 go fmt ./...
3440
3541.PHONY : vet
36- vet : # # Run go vet against code.
42+ vet : # # Run go vet against code
3743 go vet ./...
3844
3945# #@ Testing
4046
4147.PHONY : test
42- test : manifests generate fmt vet envtest # # Run tests.
48+ test : manifests generate-deepcopy fmt vet envtest # # Run tests
4349 KUBEBUILDER_ASSETS=" $( LOCALBIN) /k8s/current" go test ./... -coverprofile cover.out
4450
4551# #@ Build
4652
4753.PHONY : build
48- build : generate fmt vet # # Build manager binary.
54+ build : generate-deepcopy fmt vet # # Build manager binary
4955 go build -o bin/manager main.go
5056
5157.PHONY : run
52- run : manifests generate fmt vet # # Run a controller from your host.
58+ run : manifests generate-deepcopy fmt vet # # Run a controller from your host
5359 go run ./main.go
5460
55- # Build docker image in current architecture and tag it as ${IMG}.
61+ # Build docker image in current architecture and tag it as ${IMG}
5662.PHONY : docker-build
57- docker-build : # # Build docker image with the manager.
63+ docker-build : # # Build docker image with the manager
5864 docker build -t ${IMG} .
5965
60- # Push docker image to the target specified in ${IMG}.
66+ # Push docker image to the target specified in ${IMG}
6167.PHONY : docker-push
62- docker-push : # # Push docker image with the manager.
68+ docker-push : # # Push docker image with the manager
6369 docker push ${IMG}
6470
65- # Build and push docker image for all given platforms.
71+ # Build and push docker image for all given platforms
6672PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
6773.PHONY : docker-buildx
68- docker-buildx : # # Build and push docker image for the manager for cross-platform support.
74+ docker-buildx : # # Build and push docker image for the manager for cross-platform support
6975 - docker buildx create --name project-v3-builder
7076 docker buildx use project-v3-builder
7177 - docker buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} .
@@ -76,48 +82,35 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
7682# # Location to install dependencies to
7783LOCALBIN ?= $(shell pwd) /bin
7884$(LOCALBIN ) :
79- mkdir -p $(LOCALBIN )
80-
81- # # Tool Binaries
82- CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
83- CLIENT_GEN ?= $(LOCALBIN ) /client-gen
84- INFORMER_GEN ?= $(LOCALBIN ) /informer-gen
85- LISTER_GEN ?= $(LOCALBIN ) /lister-gen
86- SETUP_ENVTEST ?= $(LOCALBIN ) /setup-envtest
87-
88- # # Tool Versions
89- CONTROLLER_TOOLS_VERSION ?= v0.16.1
90- CODE_GENERATOR_VERSION ?= v0.29.8
91- SETUP_ENVTEST_VERSION ?= latest
85+ @mkdir -p $(LOCALBIN )
9286
9387.PHONY : controller-gen
94- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
95- $(CONTROLLER_GEN ) : $(LOCALBIN )
96- test -s $(LOCALBIN ) /controller-gen || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
97-
98- .PHONY : client-gen
99- client-gen : $(CLIENT_GEN ) # # Download client-gen locally if necessary.
100- $(CLIENT_GEN ) : $(LOCALBIN )
101- test -s $(LOCALBIN ) /client-gen || GOBIN=$(LOCALBIN ) go install k8s.io/code-generator/cmd/client-gen@$(CODE_GENERATOR_VERSION )
102-
103- .PHONY : informer-gen
104- informer-gen : $(INFORMER_GEN ) # # Download informer-gen locally if necessary.
105- $(INFORMER_GEN ) : $(LOCALBIN )
106- test -s $(LOCALBIN ) /informer-gen || GOBIN=$(LOCALBIN ) go install k8s.io/code-generator/cmd/informer-gen@$(CODE_GENERATOR_VERSION )
107-
108- .PHONY : lister-gen
109- lister-gen : $(LISTER_GEN ) # # Download lister-gen locally if necessary.
110- $(LISTER_GEN ) : $(LOCALBIN )
111- test -s $(LOCALBIN ) /lister-gen || GOBIN=$(LOCALBIN ) go install k8s.io/code-generator/cmd/lister-gen@$(CODE_GENERATOR_VERSION )
88+ controller-gen : $(LOCALBIN ) # # Install controller-gen
89+ @go mod download sigs.k8s.io/controller-tools && \
90+ VERSION=$$(go list -m -f '{{.Version}}' sigs.k8s.io/controller-tools ) && \
91+ if [ ! -L $( LOCALBIN) /controller-gen ] || [ " $$ (readlink $( LOCALBIN) /controller-gen)" != " controller-gen-$$ VERSION" ]; then \
92+ echo " Installing controller-gen $$ VERSION" && \
93+ rm -f $(LOCALBIN ) /controller-gen && \
94+ GOBIN=$(LOCALBIN ) go install $$(go list -m -f '{{.Dir}}' sigs.k8s.io/controller-tools ) /cmd/controller-gen && \
95+ mv $(LOCALBIN ) /controller-gen $(LOCALBIN ) /controller-gen-$$ VERSION && \
96+ ln -s controller-gen-$$ VERSION $(LOCALBIN ) /controller-gen; \
97+ fi
11298
11399.PHONY : setup-envtest
114- setup-envtest : $(SETUP_ENVTEST ) # # Download setup-envtest locally if necessary.
115- $(SETUP_ENVTEST ) : $(LOCALBIN )
116- test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION )
100+ setup-envtest : $(LOCALBIN ) # # Install setup-envtest
101+ @go mod download sigs.k8s.io/controller-runtime/tools/setup-envtest && \
102+ VERSION=$$(go list -m -f '{{.Version}}' sigs.k8s.io/controller-runtime/tools/setup-envtest ) && \
103+ if [ ! -L $( LOCALBIN) /setup-envtest ] || [ " $$ (readlink $( LOCALBIN) /setup-envtest)" != " setup-envtest-$$ VERSION" ]; then \
104+ echo " Installing setup-envtest $$ VERSION" && \
105+ rm -f $(LOCALBIN ) /setup-envtest && \
106+ GOBIN=$(LOCALBIN ) go install $$(go list -m -f '{{.Dir}}' sigs.k8s.io/controller-runtime/tools/setup-envtest ) && \
107+ mv $(LOCALBIN ) /setup-envtest $(LOCALBIN ) /setup-envtest-$$ VERSION && \
108+ ln -s setup-envtest-$$ VERSION $(LOCALBIN ) /setup-envtest; \
109+ fi
117110
118111.PHONY : envtest
119- envtest : setup-envtest
120- ENVTESTDIR=$$($(SETUP_ENVTEST ) use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path) ; \
121- chmod -R u+w $$ ENVTESTDIR ; \
122- rm -f $(LOCALBIN ) /k8s/current ; \
112+ envtest : setup-envtest # # Install envtest binaries
113+ @ ENVTESTDIR=$$($(LOCALBIN ) /setup-envtest use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path) && \
114+ chmod -R u+w $$ ENVTESTDIR && \
115+ rm -f $(LOCALBIN ) /k8s/current && \
123116 ln -s $$ ENVTESTDIR $(LOCALBIN ) /k8s/current
0 commit comments