@@ -13,62 +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 # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
28- $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./api/..."
27+ generate : generate-deepcopy # # 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/..."
2932
3033.PHONY : generate-client
31- generate-client : client-gen informer-gen lister-gen # # Generate typed client.
34+ generate-client : # # Generate typed client
3235 ./hack/genclient.sh
3336
3437.PHONY : fmt
35- fmt : # # Run go fmt against code.
38+ fmt : # # Run go fmt against code
3639 go fmt ./...
3740
3841.PHONY : vet
39- vet : # # Run go vet against code.
42+ vet : # # Run go vet against code
4043 go vet ./...
4144
4245# #@ Testing
4346
4447.PHONY : test
45- test : manifests generate fmt vet envtest # # Run tests.
48+ test : manifests generate-deepcopy fmt vet envtest # # Run tests
4649 KUBEBUILDER_ASSETS=" $( LOCALBIN) /k8s/current" go test ./... -coverprofile cover.out
4750
4851# #@ Build
4952
5053.PHONY : build
51- build : generate fmt vet # # Build manager binary.
54+ build : generate-deepcopy fmt vet # # Build manager binary
5255 go build -o bin/manager main.go
5356
5457.PHONY : run
55- run : manifests generate fmt vet # # Run a controller from your host.
58+ run : manifests generate-deepcopy fmt vet # # Run a controller from your host
5659 go run ./main.go
5760
58- # Build docker image in current architecture and tag it as ${IMG}.
61+ # Build docker image in current architecture and tag it as ${IMG}
5962.PHONY : docker-build
60- docker-build : # # Build docker image with the manager.
63+ docker-build : # # Build docker image with the manager
6164 docker build -t ${IMG} .
6265
63- # Push docker image to the target specified in ${IMG}.
66+ # Push docker image to the target specified in ${IMG}
6467.PHONY : docker-push
65- docker-push : # # Push docker image with the manager.
68+ docker-push : # # Push docker image with the manager
6669 docker push ${IMG}
6770
68- # Build and push docker image for all given platforms.
71+ # Build and push docker image for all given platforms
6972PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
7073.PHONY : docker-buildx
71- 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
7275 - docker buildx create --name project-v3-builder
7376 docker buildx use project-v3-builder
7477 - docker buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} .
@@ -79,53 +82,41 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
7982# # Location to install dependencies to
8083LOCALBIN ?= $(shell pwd) /bin
8184$(LOCALBIN ) :
82- mkdir -p $(LOCALBIN )
83-
84- # # Tool Binaries
85- CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
86- CLIENT_GEN ?= $(LOCALBIN ) /client-gen
87- INFORMER_GEN ?= $(LOCALBIN ) /informer-gen
88- LISTER_GEN ?= $(LOCALBIN ) /lister-gen
89- SETUP_ENVTEST ?= $(LOCALBIN ) /setup-envtest
90-
91- # # Tool Versions
92- CONTROLLER_TOOLS_VERSION ?= v0.16.1
93- CODE_GENERATOR_VERSION ?= v0.29.8
94- SETUP_ENVTEST_VERSION ?= latest
85+ @mkdir -p $(LOCALBIN )
9586
9687.PHONY : controller-gen
97- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
98- $(CONTROLLER_GEN ) : $(LOCALBIN )
99- test -s $(LOCALBIN ) /controller-gen || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
100-
101- .PHONY : client-gen
102- client-gen : $(CLIENT_GEN ) # # Download client-gen locally if necessary.
103- $(CLIENT_GEN ) : $(LOCALBIN )
104- test -s $(LOCALBIN ) /client-gen || GOBIN=$(LOCALBIN ) go install k8s.io/code-generator/cmd/client-gen@$(CODE_GENERATOR_VERSION )
105-
106- .PHONY : informer-gen
107- informer-gen : $(INFORMER_GEN ) # # Download informer-gen locally if necessary.
108- $(INFORMER_GEN ) : $(LOCALBIN )
109- test -s $(LOCALBIN ) /informer-gen || GOBIN=$(LOCALBIN ) go install k8s.io/code-generator/cmd/informer-gen@$(CODE_GENERATOR_VERSION )
110-
111- .PHONY : lister-gen
112- lister-gen : $(LISTER_GEN ) # # Download lister-gen locally if necessary.
113- $(LISTER_GEN ) : $(LOCALBIN )
114- 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
11598
11699.PHONY : setup-envtest
117- setup-envtest : $(SETUP_ENVTEST ) # # Download setup-envtest locally if necessary.
118- $(SETUP_ENVTEST ) : $(LOCALBIN )
119- 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
120110
121111.PHONY : envtest
122- envtest : setup-envtest
123- ENVTESTDIR=$$($(SETUP_ENVTEST ) use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path) ; \
124- chmod -R u+w $$ ENVTESTDIR ; \
125- 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 && \
126116 ln -s $$ ENVTESTDIR $(LOCALBIN ) /k8s/current
127117
128118# #@ Manage Content
119+
129120.PHONY : update-content
130121update-content : # # Update external resources used by this repository.
131122 rm -rf pkg/operator/data/charts
0 commit comments