Skip to content

Commit 4ddc71c

Browse files
committed
Improve Makefile help
Signed-off-by: Adrian Orive <[email protected]>
1 parent 14b27b4 commit 4ddc71c

File tree

10 files changed

+378
-318
lines changed

10 files changed

+378
-318
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ endif
4040
# http://linuxcommand.org/lc3_adv_awk.php
4141

4242
.PHONY: help
43-
help: ## Display this help
43+
help: ## Display this help
4444
@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)
4545

4646
##@ Build
@@ -96,7 +96,7 @@ test: ## Run the unit tests (used in the CI)
9696
./test.sh
9797

9898
.PHONY: test-coverage
99-
test-coverage: ## Run coveralls
99+
test-coverage: ## Run coveralls
100100
# remove all coverage files if exists
101101
- rm -rf *.out
102102
# run the go tests and gen the file coverage-all used to do the integration with coverrals.io

pkg/plugins/golang/v2/scaffolds/internal/templates/makefile.go

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -67,60 +67,75 @@ else
6767
GOBIN=$(shell go env GOBIN)
6868
endif
6969
70-
all: manager
70+
all: build
7171
72-
# Run tests
73-
test: generate fmt vet manifests
72+
##@ General
73+
74+
# The help target prints out all targets with their descriptions organized
75+
# beneath their categories. The categories are represented by '##@' and the
76+
# target descriptions by '##'. The awk commands is responsible for reading the
77+
# entire set of makefiles included in this invocation, looking for lines of the
78+
# file as xyz: ## something, and then pretty-format the target and help. Then,
79+
# if there's a line with ##@ something, that gets pretty-printed as a category.
80+
# More info on the usage of ANSI control characters for terminal formatting:
81+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
82+
# More info on the awk command:
83+
# http://linuxcommand.org/lc3_adv_awk.php
84+
85+
help: ## Display this help.
86+
@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)
87+
88+
##@ Development
89+
90+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
91+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
92+
93+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
94+
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
95+
96+
fmt: ## Run go fmt against code.
97+
go fmt ./...
98+
99+
vet: ## Run go vet against code.
100+
go vet ./...
101+
102+
test: manifests generate fmt vet ## Run tests.
74103
go test ./... -coverprofile cover.out
75104
76-
# Build manager binary
77-
manager: generate fmt vet
105+
##@ Build
106+
107+
build: generate fmt vet ## Build manager binary.
78108
go build -o bin/manager main.go
79109
80-
# Run against the configured Kubernetes cluster in ~/.kube/config
81-
run: generate fmt vet manifests
110+
# Backwards compatibility
111+
manager: build ## Build manager binary (alias for build target).
112+
113+
run: manifests generate fmt vet ## Run a controller from your host.
82114
go run ./main.go
83115
84-
# Install CRDs into a cluster
85-
install: manifests kustomize
116+
docker-build: test ## Build docker image with the manager.
117+
docker build -t ${IMG} .
118+
119+
docker-push: ## Push docker image with the manager.
120+
docker push ${IMG}
121+
122+
##@ Deployment
123+
124+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
86125
$(KUSTOMIZE) build config/crd | kubectl apply -f -
87126
88-
# Uninstall CRDs from a cluster
89-
uninstall: manifests kustomize
127+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
90128
$(KUSTOMIZE) build config/crd | kubectl delete -f -
91129
92-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
93-
deploy: manifests kustomize
130+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
94131
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
95132
$(KUSTOMIZE) build config/default | kubectl apply -f -
96133
97-
# Generate manifests e.g. CRD, RBAC etc.
98-
manifests: controller-gen
99-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
100-
101-
# Run go fmt against code
102-
fmt:
103-
go fmt ./...
134+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
135+
$(KUSTOMIZE) build config/default | kubectl delete -f -
104136
105-
# Run go vet against code
106-
vet:
107-
go vet ./...
108-
109-
# Generate code
110-
generate: controller-gen
111-
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
112-
113-
# Build the docker image
114-
docker-build: test
115-
docker build . -t ${IMG}
116-
117-
# Push the docker image
118-
docker-push:
119-
docker push ${IMG}
120137
121-
# find or download controller-gen
122-
# download controller-gen if necessary
123-
controller-gen:
138+
controller-gen: ## Download controller-gen locally if necessary.
124139
ifeq (, $(shell which controller-gen))
125140
@{ \
126141
set -e ;\
@@ -135,7 +150,7 @@ else
135150
CONTROLLER_GEN=$(shell which controller-gen)
136151
endif
137152
138-
kustomize:
153+
kustomize: ## Download kustomize locally if necessary.
139154
ifeq (, $(shell which kustomize))
140155
@{ \
141156
set -e ;\

pkg/plugins/golang/v3/scaffolds/internal/templates/makefile.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ else
7070
GOBIN=$(shell go env GOBIN)
7171
endif
7272
73-
all: manager
73+
all: build
7474
75-
##@ Targets
75+
##@ General
7676
7777
# The help target prints out all targets with their descriptions organized
7878
# beneath their categories. The categories are represented by '##@' and the
@@ -85,26 +85,49 @@ all: manager
8585
# More info on the awk command:
8686
# http://linuxcommand.org/lc3_adv_awk.php
8787
88-
.PHONY: help
89-
help: ## Display this help.
88+
help: ## Display this help.
9089
@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)
9190
91+
##@ Development
92+
93+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
94+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
95+
96+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
97+
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
98+
99+
fmt: ## Run go fmt against code.
100+
go fmt ./...
101+
102+
vet: ## Run go vet against code.
103+
go vet ./...
104+
92105
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
93-
test: generate fmt vet manifests ## Run tests.
106+
test: manifests generate fmt vet ## Run tests.
94107
mkdir -p ${ENVTEST_ASSETS_DIR}
95108
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/{{ .ControllerRuntimeVersion }}/hack/setup-envtest.sh
96109
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
97110
98-
manager: generate fmt vet ## Build manager binary.
111+
##@ Build
112+
113+
build: generate fmt vet ## Build manager binary.
99114
go build -o bin/manager main.go
100115
101-
run: generate fmt vet manifests ## Run a controller from your host.
116+
run: manifests generate fmt vet ## Run a controller from your host.
102117
go run ./main.go
103118
104-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
119+
docker-build: test ## Build docker image with the manager.
120+
docker build -t ${IMG} .
121+
122+
docker-push: ## Push docker image with the manager.
123+
docker push ${IMG}
124+
125+
##@ Deployment
126+
127+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
105128
$(KUSTOMIZE) build config/crd | kubectl apply -f -
106129
107-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
130+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
108131
$(KUSTOMIZE) build config/crd | kubectl delete -f -
109132
110133
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
@@ -115,33 +138,10 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
115138
$(KUSTOMIZE) build config/default | kubectl delete -f -
116139
117140
118-
manifests: controller-gen ## Generate manifests e.g. CRD, RBAC, etc.
119-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
120-
121-
fmt: ## Run go fmt against code.
122-
go fmt ./...
123-
124-
125-
vet: ## Run go vet against code.
126-
go vet ./...
127-
128-
generate: controller-gen ## Generate code.
129-
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
130-
131-
132-
docker-build: test ## Build the docker image for the controller.
133-
docker build -t ${IMG} .
134-
135-
136-
docker-push: ## Push the docker image for the controller.
137-
docker push ${IMG}
138-
139-
140141
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
141142
controller-gen: ## Download controller-gen locally if necessary.
142143
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@{{ .ControllerToolsVersion }})
143144
144-
145145
KUSTOMIZE = $(shell pwd)/bin/kustomize
146146
kustomize: ## Download kustomize locally if necessary.
147147
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@{{ .KustomizeVersion }})

testdata/project-v2-addon/Makefile

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,75 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14-
all: manager
14+
all: build
1515

16-
# Run tests
17-
test: generate fmt vet manifests
16+
##@ General
17+
18+
# The help target prints out all targets with their descriptions organized
19+
# beneath their categories. The categories are represented by '##@' and the
20+
# target descriptions by '##'. The awk commands is responsible for reading the
21+
# entire set of makefiles included in this invocation, looking for lines of the
22+
# file as xyz: ## something, and then pretty-format the target and help. Then,
23+
# if there's a line with ##@ something, that gets pretty-printed as a category.
24+
# More info on the usage of ANSI control characters for terminal formatting:
25+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
26+
# More info on the awk command:
27+
# http://linuxcommand.org/lc3_adv_awk.php
28+
29+
help: ## Display this help.
30+
@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)
31+
32+
##@ Development
33+
34+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
35+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
36+
37+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
38+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
39+
40+
fmt: ## Run go fmt against code.
41+
go fmt ./...
42+
43+
vet: ## Run go vet against code.
44+
go vet ./...
45+
46+
test: manifests generate fmt vet ## Run tests.
1847
go test ./... -coverprofile cover.out
1948

20-
# Build manager binary
21-
manager: generate fmt vet
49+
##@ Build
50+
51+
build: generate fmt vet ## Build manager binary.
2252
go build -o bin/manager main.go
2353

24-
# Run against the configured Kubernetes cluster in ~/.kube/config
25-
run: generate fmt vet manifests
54+
# Backwards compatibility
55+
manager: build ## Build manager binary (alias for build target).
56+
57+
run: manifests generate fmt vet ## Run a controller from your host.
2658
go run ./main.go
2759

28-
# Install CRDs into a cluster
29-
install: manifests kustomize
60+
docker-build: test ## Build docker image with the manager.
61+
docker build -t ${IMG} .
62+
63+
docker-push: ## Push docker image with the manager.
64+
docker push ${IMG}
65+
66+
##@ Deployment
67+
68+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
3069
$(KUSTOMIZE) build config/crd | kubectl apply -f -
3170

32-
# Uninstall CRDs from a cluster
33-
uninstall: manifests kustomize
71+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
3472
$(KUSTOMIZE) build config/crd | kubectl delete -f -
3573

36-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
37-
deploy: manifests kustomize
74+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
3875
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
3976
$(KUSTOMIZE) build config/default | kubectl apply -f -
4077

41-
# Generate manifests e.g. CRD, RBAC etc.
42-
manifests: controller-gen
43-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
44-
45-
# Run go fmt against code
46-
fmt:
47-
go fmt ./...
78+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
79+
$(KUSTOMIZE) build config/default | kubectl delete -f -
4880

49-
# Run go vet against code
50-
vet:
51-
go vet ./...
52-
53-
# Generate code
54-
generate: controller-gen
55-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
56-
57-
# Build the docker image
58-
docker-build: test
59-
docker build . -t ${IMG}
60-
61-
# Push the docker image
62-
docker-push:
63-
docker push ${IMG}
6481

65-
# find or download controller-gen
66-
# download controller-gen if necessary
67-
controller-gen:
82+
controller-gen: ## Download controller-gen locally if necessary.
6883
ifeq (, $(shell which controller-gen))
6984
@{ \
7085
set -e ;\
@@ -79,7 +94,7 @@ else
7994
CONTROLLER_GEN=$(shell which controller-gen)
8095
endif
8196

82-
kustomize:
97+
kustomize: ## Download kustomize locally if necessary.
8398
ifeq (, $(shell which kustomize))
8499
@{ \
85100
set -e ;\

0 commit comments

Comments
 (0)