Skip to content

Commit

Permalink
Improve generate-* targets in Makefile (kubernetes-sigs#1061)
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri authored and k8s-ci-robot committed Jun 24, 2019
1 parent c11ed81 commit 320b7f4
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 56 deletions.
135 changes: 80 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,37 @@ all: test manager clusterctl
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\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
Expand All @@ -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 \
Expand All @@ -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))
Expand All @@ -123,34 +150,17 @@ 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))

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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hack/verify_clientset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 320b7f4

Please sign in to comment.