Skip to content

Commit f23b0b9

Browse files
authored
style: update makefile help msg according to k8s best practices (opendatahub-io#583)
<!--- Provide a general summary of your changes in the Title above --> ## Description update makefile help msg according to k8s best practices. help message before this change: <img width="699" height="256" alt="image" src="https://github.com/user-attachments/assets/8edb7311-e06d-408e-8641-148badba0f58" /> help message after this change: <img width="674" height="426" alt="image" src="https://github.com/user-attachments/assets/e3e05d0c-5073-4367-8ce3-2fe21fdb23f0" /> ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Merge criteria: <!--- This PR will be merged by any repository approver when it meets all the points in the checklist --> <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] The commits are squashed in a cohesive manner and have meaningful messages. - [x] Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious). - [x] The developer has manually tested the changes and verified that the changes work <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Enhanced build system help documentation with dynamic, categorized target descriptions for improved developer experience. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Nir Rozenbaum <nrozenba@redhat.com>
1 parent 17deedb commit f23b0b9

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

maas-controller/Makefile

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
# MaaS Controller Makefile
22
# Build and deploy the MaaS control plane (MaaSModelRef, MaaSAuthPolicy, MaaSSubscription)
33

4+
##@ General
5+
6+
# The help target prints out all targets with their descriptions organized
7+
# beneath their categories. The categories are represented by '##@' and the
8+
# target descriptions by '##'. The awk command is responsible for reading the
9+
# entire set of makefiles included in this invocation, looking for lines of the
10+
# file as xyz: ## something, and then pretty-format the target and help. Then,
11+
# if there's a line with ##@ something, that gets pretty-printed as a category.
12+
# More info on the usage of ANSI control characters for terminal formatting:
13+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
14+
# More info on the awk command:
15+
# http://linuxcommand.org/lc3_adv_awk.php
16+
17+
.PHONY: help
18+
help: ## Display this help.
19+
@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)
20+
@echo ""
21+
@echo "\033[1mOptional build arguments\033[0m (e.g. \033[36mmake build GO_STRICTFIPS=true\033[0m):"
22+
@echo " \033[36mGO_STRICTFIPS=true\033[0m strict FIPS runtime for \033[36mbuild\033[0m / \033[36mrun\033[0m / \033[36mbuild-image\033[0m / \033[36mbuild-image-konflux\033[0m"
23+
424
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
525

626
include tools.mk
727

8-
.PHONY: build run test tidy lint install uninstall generate manifests verify-codegen help
9-
10-
help:
11-
@echo "MaaS Controller make targets:"
12-
@echo " make build - build manager binary to bin/manager"
13-
@echo " make run - build and run manager locally"
14-
@echo " make test - run tests"
15-
@echo " make lint - run golangci-lint"
16-
@echo " make generate - generate deepcopy code for API types"
17-
@echo " make manifests - generate CRD manifests"
18-
@echo " make install - apply deployment/base/maas-controller/default (CRDs, RBAC, deployment)"
19-
@echo " make uninstall - delete deployment/base/maas-controller/default resources"
20-
@echo " make verify-codegen - run generate + manifests and fail if files changed (CI check)"
21-
@echo " make build-image - build container image; override with REPO=... TAG=..."
22-
@echo " make build-image-konflux - build container image using Dockerfile.konflux"
23-
@echo " make push-image - push container image to registry"
24-
@echo ""
25-
@echo "FIPS options:"
26-
@echo " make build GO_STRICTFIPS=true - build with FIPS strict runtime"
27-
2828
BINARY_NAME := manager
2929
BUILD_DIR := $(PROJECT_DIR)/bin
3030

31+
# Go build environment (override on the CLI, e.g. make build GO_STRICTFIPS=true).
32+
# Strict FIPS uses GOEXPERIMENT=strictfipsruntime; keep CGO_ENABLED=1 for that path.
3133
GOOS ?= $(shell go env GOOS)
3234
GOARCH ?= $(shell go env GOARCH)
3335
GO_STRICTFIPS ?= false
3436

35-
CGO_ENABLED ?= 1
37+
CGO_ENABLED ?= 1
3638

3739
ifeq ($(GO_STRICTFIPS),true)
3840
GOEXPERIMENT ?= strictfipsruntime
@@ -49,21 +51,24 @@ endif
4951
CONTROLLER_GEN_VERSION ?= v0.16.4
5052
CONTROLLER_GEN = $(BUILD_DIR)/controller-gen
5153

52-
## Container image
53-
include container.mk
54+
##@ Development
5455

55-
build: tidy $(BUILD_DIR)
56+
.PHONY: build
57+
build: tidy $(BUILD_DIR) ## build manager binary to bin/manager
5658
$(GO_ENV) go build -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/manager
5759

5860
$(BUILD_DIR):
5961
mkdir -p $(BUILD_DIR)
6062

61-
run: build
63+
.PHONY: run
64+
run: build ## build and run manager locally
6265
$(BUILD_DIR)/$(BINARY_NAME)
6366

64-
test: tidy
67+
.PHONY: test
68+
test: tidy ## run tests
6569
go test ./...
6670

71+
.PHONY: tidy
6772
tidy:
6873
go mod tidy
6974

@@ -72,7 +77,8 @@ $(CONTROLLER_GEN): | $(BUILD_DIR)
7277
GOBIN=$(abspath $(BUILD_DIR)) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
7378

7479
LINT_FIX ?= false
75-
lint: $(GOLANGCI_LINT) ## Run golangci-lint (use LINT_FIX=true to fix lint issues)
80+
.PHONY: lint
81+
lint: $(GOLANGCI_LINT) ## run golangci-lint (use LINT_FIX=true to fix lint issues)
7682
ifeq ($(LINT_FIX),true)
7783
$(GOLANGCI_LINT) fmt
7884
$(GOLANGCI_LINT) run --fix
@@ -81,16 +87,16 @@ else
8187
$(GOLANGCI_LINT) run
8288
endif
8389

84-
# Generate deepcopy code for API types
85-
generate: $(CONTROLLER_GEN)
90+
.PHONY: generate
91+
generate: $(CONTROLLER_GEN) ## generate deepcopy code for API types
8692
$(CONTROLLER_GEN) object paths="./api/..."
8793

88-
# Generate CRD manifests
89-
manifests: $(CONTROLLER_GEN)
94+
.PHONY: manifests
95+
manifests: $(CONTROLLER_GEN) ## generate CRD manifests
9096
$(CONTROLLER_GEN) crd paths="./api/..." output:crd:dir=../deployment/base/maas-controller/crd/bases
9197

92-
# Run generate + manifests and verify no files changed (used by CI)
93-
verify-codegen: generate manifests
98+
.PHONY: verify-codegen
99+
verify-codegen: generate manifests ## run generate + manifests and fail if files changed (CI check)
94100
@if ! git diff --quiet HEAD -- api/ ../deployment/base/maas-controller/crd/bases/; then \
95101
echo "ERROR: Generated files are out of date. Please run 'make generate manifests' and commit the results."; \
96102
git diff --stat HEAD -- api/ ../deployment/base/maas-controller/crd/bases/; \
@@ -104,9 +110,16 @@ verify-codegen: generate manifests
104110
fi
105111
@echo "Generated files are up to date."
106112

113+
##@ Deployment
114+
107115
# Install CRDs, RBAC, and manager deployment (default: opendatahub namespace)
108-
install:
116+
.PHONY: install
117+
install: ## apply deployment/base/maas-controller/default (CRDs, RBAC, deployment)
109118
kubectl apply -k ../deployment/base/maas-controller/default
110119

111-
uninstall:
112-
kubectl delete -k ../deployment/base/maas-controller/default --ignore-not-found
120+
.PHONY: uninstall
121+
uninstall: ## delete deployment/base/maas-controller/default resources
122+
kubectl delete -k ../deployment/base/maas-controller/default --ignore-not-found
123+
124+
## Container image
125+
include container.mk

maas-controller/container.mk

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@ ifdef GOEXPERIMENT
1010
DOCKER_BUILD_ARGS += --build-arg GOEXPERIMENT=$(GOEXPERIMENT)
1111
endif
1212

13+
##@ Build
14+
1315
.PHONY: build-image
14-
build-image: ## Build container image (use REPO= and TAG= to specify image)
16+
build-image: ## Build container image (use REPO= and TAG= to specify image)
1517
@echo "Building container image $(FULL_IMAGE)..."
1618
$(CONTAINER_ENGINE) build $(DOCKER_BUILD_ARGS) $(CONTAINER_ENGINE_EXTRA_FLAGS) -t "$(FULL_IMAGE)" .
1719
@echo "Container image $(FULL_IMAGE) built successfully"
1820

1921
.PHONY: build-image-konflux
20-
build-image-konflux: ## Build container image with Dockerfile.konflux
22+
build-image-konflux: ## Build container image with Dockerfile.konflux
2123
@echo "Building container image $(FULL_IMAGE) using Dockerfile.konflux..."
2224
$(CONTAINER_ENGINE) build $(DOCKER_BUILD_ARGS) $(CONTAINER_ENGINE_EXTRA_FLAGS) -f Dockerfile.konflux -t "$(FULL_IMAGE)" .
2325
@echo "Container image $(FULL_IMAGE) built successfully"
2426

2527
.PHONY: push-image
26-
push-image: ## Push container image (use REPO= and TAG= to specify image)
28+
push-image: ## Push container image (use REPO= and TAG= to specify image)
2729
@echo "Pushing container image $(FULL_IMAGE)..."
2830
@$(CONTAINER_ENGINE) push "$(FULL_IMAGE)"
2931
@echo "Container image $(FULL_IMAGE) pushed successfully"
3032

31-
.PHONY: build-push-image
32-
build-push-image: build-image push-image ## Build and push container image
33+
.PHONY: build-push-image ## Build and push container image
34+
build-push-image: build-image push-image

0 commit comments

Comments
 (0)