From 320b7f4f734af4fac121615ac4f59b89be5a7752 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Mon, 24 Jun 2019 13:00:37 -0700 Subject: [PATCH] Improve generate-* targets in Makefile (#1061) Signed-off-by: Vince Prignano --- Makefile | 135 +++++++++++++++++++++++---------------- hack/verify_clientset.sh | 2 +- 2 files changed, 81 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 5d0167f25dbe..e591a337f8b5 100644 --- a/Makefile +++ b/Makefile @@ -38,49 +38,37 @@ all: test manager clusterctl help: ## Display this help @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) -.PHONY: gazelle -gazelle: ## Run Bazel Gazelle - (which bazel && ./hack/update-bazel.sh) || true +## -------------------------------------- +## Testing +## -------------------------------------- -.PHONY: dep-ensure -dep-ensure: ## Runs dep-ensure and rebuilds Bazel gazelle files. - find vendor -name 'BUILD.bazel' -delete - (which dep && dep ensure -v) || true - $(MAKE) gazelle +.PHONY: test +test: generate lint ## Run tests + $(MAKE) test-go .PHONY: test -test: gazelle verify generate fmt vet manifests ## Run tests +test-go: ## Run tests go test -v -tags=integration ./pkg/... ./cmd/... +## -------------------------------------- +## Binaries +## -------------------------------------- + .PHONY: manager -manager: generate fmt vet ## Build manager binary +manager: lint-full ## Build manager binary go build -o bin/manager sigs.k8s.io/cluster-api/cmd/manager .PHONY: clusterctl -clusterctl: generate fmt vet ## Build clusterctl binary +clusterctl: lint-full ## Build clusterctl binary go build -o bin/clusterctl sigs.k8s.io/cluster-api/cmd/clusterctl .PHONY: run -run: generate fmt vet ## Run against the configured Kubernetes cluster in ~/.kube/config +run: lint ## Run against the configured Kubernetes cluster in ~/.kube/config go run ./cmd/manager/main.go -.PHONY: deploy -deploy: manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config - kustomize build config/default | kubectl apply -f - - -.PHONY: manifests -manifests: ## Generate manifests e.g. CRD, RBAC etc. - go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all - cp -f ./config/rbac/manager*.yaml ./config/ci/rbac/ - cp -f ./config/manager/manager*.yaml ./config/ci/manager/ - -.PHONY: fmt -fmt: ## Run go fmt against code - go fmt ./pkg/... ./cmd/... - -.PHONY: vet -vet: ## Run go vet against code - go vet ./pkg/... ./cmd/... +## -------------------------------------- +## Linting +## -------------------------------------- .PHONY: lint lint: dep-ensure ## Lint codebase @@ -89,13 +77,27 @@ lint: dep-ensure ## Lint codebase lint-full: dep-ensure ## Run slower linters to detect possible issues bazel run //:lint-full $(BAZEL_ARGS) +## -------------------------------------- +## Generate / Manifests +## -------------------------------------- + .PHONY: generate -generate: clientset dep-ensure ## Generate code - go generate ./pkg/... ./cmd/... +generate: ## Generate code + $(MAKE) generate-manifests + $(MAKE) generate-go $(MAKE) gazelle -.PHONY: clientset -clientset: ## Generate a typed clientset +.PHONY: generate-full +generate-full: dep-ensure ## Generate code + $(MAKE) generate-clientset + $(MAKE) generate + +.PHONY: generate-go +generate-go: ## Runs go generate + go generate ./pkg/... ./cmd/... + +.PHONY: generate-clientset +generate-clientset: ## Generate a typed clientset rm -rf pkg/client cd ./vendor/k8s.io/code-generator/cmd && go install ./client-gen ./lister-gen ./informer-gen $$GOPATH/bin/client-gen --clientset-name clientset --input-base sigs.k8s.io/cluster-api/pkg/apis \ @@ -109,11 +111,36 @@ clientset: ## Generate a typed clientset --listers-package sigs.k8s.io/cluster-api/pkg/client/listers_generated \ --output-package sigs.k8s.io/cluster-api/pkg/client/informers_generated \ --go-header-file=./hack/boilerplate/boilerplate.generatego.txt + +.PHONY: generate-manifests +generate-manifests: ## Generate manifests e.g. CRD, RBAC etc. + go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all + cp -f ./config/rbac/manager*.yaml ./config/ci/rbac/ + cp -f ./config/manager/manager*.yaml ./config/ci/manager/ + +.PHONY: gazelle +gazelle: ## Run Bazel Gazelle + (which bazel && ./hack/update-bazel.sh) || true + +.PHONY: dep-ensure +dep-ensure: ## Runs dep-ensure and rebuilds Bazel gazelle files. + find vendor -name 'BUILD.bazel' -delete + (which dep && dep ensure -v) || true $(MAKE) gazelle -.PHONY: clean -clean: ## Remove all generated files - rm -f bazel-* +## -------------------------------------- +## Docker +## -------------------------------------- + +.PHONY: docker-build +docker-build: generate lint-full ## Build the docker image for controller-manager + docker build --pull --build-arg ARCH=$(ARCH) . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG) + @echo "updating kustomize image patch file for manager resource" + hack/sed.sh -i.tmp -e 's@image: .*@image: '"${CONTROLLER_IMG}-$(ARCH):$(TAG)"'@' ./config/default/manager_image_patch.yaml + +.PHONY: docker-push +docker-push: docker-build ## Push the docker image + docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG) .PHONY: all-docker-build all-docker-build: $(addprefix sub-docker-build-,$(ALL_ARCH)) @@ -123,14 +150,8 @@ all-docker-build: $(addprefix sub-docker-build-,$(ALL_ARCH)) sub-docker-build-%: $(MAKE) ARCH=$* docker-build -.PHONY: docker-build -docker-build: generate fmt vet manifests ## Build the docker image for controller-manager - docker build --pull --build-arg ARCH=$(ARCH) . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG) - @echo "updating kustomize image patch file for manager resource" - hack/sed.sh -i.tmp -e 's@image: .*@image: '"${CONTROLLER_IMG}-$(ARCH):$(TAG)"'@' ./config/default/manager_image_patch.yaml - .PHONY:all-push ## Push all the architecture docker images and fat manifest docker image -all-push: all-docker-push push-manifest +all-push: all-docker-push docker-push-manifest .PHONY:all-docker-push ## Push all the architecture docker images all-docker-push: $(addprefix sub-docker-push-,$(ALL_ARCH)) @@ -138,19 +159,8 @@ all-docker-push: $(addprefix sub-docker-push-,$(ALL_ARCH)) sub-docker-push-%: $(MAKE) ARCH=$* docker-push -.PHONY: push-manifest -push-manifest: ## Push the fat manifest docker image. TODO: Update bazel build to push manifest once https://github.com/bazelbuild/rules_docker/issues/300 get merged - ## Minimum docker version 18.06.0 is required for creating and pushing manifest images - docker manifest create --amend $(CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CONTROLLER_IMG)\-&:$(TAG)~g") - @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CONTROLLER_IMG}:${TAG} ${CONTROLLER_IMG}-$${arch}:${TAG}; done - docker manifest push --purge ${CONTROLLER_IMG}:${TAG} - -.PHONY: docker-push -docker-push: docker-build ## Push the docker image - docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG) - .PHONY: docker-build-ci -docker-build-ci: generate fmt vet manifests ## Build the docker image for example provider +docker-build-ci: generate lint-full ## Build the docker image for example provider docker build --pull --build-arg ARCH=$(ARCH) . -f ./pkg/provider/example/container/Dockerfile -t $(EXAMPLE_PROVIDER_IMG)-$(ARCH):$(TAG) @echo "updating kustomize image patch file for ci" hack/sed.sh -i.tmp -e 's@image: .*@image: '"${EXAMPLE_PROVIDER_IMG}-$(ARCH):$(TAG)"'@' ./config/ci/manager_image_patch.yaml @@ -159,6 +169,21 @@ docker-build-ci: generate fmt vet manifests ## Build the docker image for exampl docker-push-ci: docker-build-ci ## Build the docker image for ci docker push "$(EXAMPLE_PROVIDER_IMG)-$(ARCH):$(TAG)" +.PHONY: docker-push-manifest +docker-push-manifest: ## Push the fat manifest docker image. TODO: Update bazel build to push manifest once https://github.com/bazelbuild/rules_docker/issues/300 get merged + ## Minimum docker version 18.06.0 is required for creating and pushing manifest images + docker manifest create --amend $(CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CONTROLLER_IMG)\-&:$(TAG)~g") + @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CONTROLLER_IMG}:${TAG} ${CONTROLLER_IMG}-$${arch}:${TAG}; done + docker manifest push --purge ${CONTROLLER_IMG}:${TAG} + +## -------------------------------------- +## Cleanup / Verification +## -------------------------------------- + +.PHONY: clean +clean: ## Remove all generated files + rm -f bazel-* + .PHONY: verify verify: ./hack/verify-boilerplate.sh diff --git a/hack/verify_clientset.sh b/hack/verify_clientset.sh index 8554bbac042f..22bc3be0e923 100755 --- a/hack/verify_clientset.sh +++ b/hack/verify_clientset.sh @@ -35,7 +35,7 @@ cleanup mkdir -p "${TMP_DIFFROOT}" cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" -make clientset +make generate-clientset gazelle echo "diffing ${DIFFROOT} against freshly generated codegen" ret=0