Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
move controller-gen tool to golang.mk as generate target depends on it
Browse files Browse the repository at this point in the history
Signed-off-by: soorena776 <[email protected]>
  • Loading branch information
soorena776 committed Oct 4, 2019
1 parent 106ac5d commit b169d16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
21 changes: 18 additions & 3 deletions makelib/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ DEP := $(TOOLS_HOST_DIR)/dep-$(DEP_VERSION)
GOJUNIT := $(TOOLS_HOST_DIR)/go-junit-report
GOCOVER_COBERTURA := $(TOOLS_HOST_DIR)/gocover-cobertura
GOIMPORTS := $(TOOLS_HOST_DIR)/goimports
CONTROLLER_GEN_VERSION ?= v0.2.1
CONTROLLERGEN := $(TOOLS_HOST_DIR)/controller-gen

GO := go
GOHOST := GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) go
Expand Down Expand Up @@ -282,11 +284,11 @@ go.clean:
go.distclean:
@rm -rf $(GO_VENDOR_DIR) $(GO_PKG_DIR)

go.generate: $(GOIMPORTS)
go.generate: $(GOIMPORTS) $(CONTROLLERGEN)
@$(INFO) go generate $(PLATFORM)
@CGO_ENABLED=0 $(GOHOST) generate $(GO_COMMON_FLAGS) $(GO_PACKAGES) $(GO_INTEGRATION_TEST_PACKAGES) || $(FAIL)
@$(OK) go generate $(PLATFORM)
@CGO_ENABLED=0 CONTROLLERGEN=$(CONTROLLERGEN) $(GOHOST) generate $(GO_COMMON_FLAGS) $(GO_PACKAGES) $(GO_INTEGRATION_TEST_PACKAGES) || $(FAIL)
@find $(GO_SUBDIRS) $(GO_INTEGRATION_TESTS_SUBDIRS) -type f -name 'zz_generated*' -exec $(GOIMPORTS) -l -w -local $(GO_PROJECT) {} \;
@$(OK) go generate $(PLATFORM)


.PHONY: go.init go.build go.install go.test.unit go.test.integration go.test.codecov go.lint go.vet go.fmt go.generate
Expand Down Expand Up @@ -387,3 +389,16 @@ $(GOCOVER_COBERTURA):
@GO111MODULE=off GOPATH=$(TOOLS_HOST_DIR)/tmp-gocover-cobertura GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) get github.com/t-yuki/gocover-cobertura || rm -fr $(TOOLS_HOST_DIR)/tmp-covcover-cobertura || $(FAIL)
@rm -fr $(TOOLS_HOST_DIR)/tmp-gocover-cobertura
@$(OK) installing gocover-cobertura

$(CONTROLLERGEN):
@$(INFO) installing controller-gen @$(CONTROLLER_GEN_VERSION)
@mkdir -p $(TOOLS_HOST_DIR)/tmp-controllergen || $(FAIL)

@# `go get` only supports versioned go packages when GO111MODULE=on
@# since $(TOOLS_HOST_DIR) is under $(GO_PROJECT), make a temp folder which has a go.mod,
@# so that $(GO_PROJECT)/go.mod doesn't get modified because of running `go get`
@cd $(TOOLS_HOST_DIR)/tmp-controllergen; rm -f go.mod; GO111MODULE=on $(GOHOST) mod init tmp-controllergen
@cd $(TOOLS_HOST_DIR)/tmp-controllergen; GOPATH=$(abspath $(GO_PKG_DIR)) GO111MODULE=on GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) || $(FAIL)
@rm -fr $(TOOLS_HOST_DIR)/tmp-controllergen

@$(OK) installing controller-gen @$(CONTROLLER_GEN_VERSION)
36 changes: 7 additions & 29 deletions makelib/kubebuilder.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

# the version of kubebuilder to use
KUBEBUILDER_VERSION ?= 1.0.8
CONTROLLER_GEN_VERSION ?= v0.2.1
KUBEBUILDER := $(TOOLS_HOST_DIR)/kubebuilder-$(KUBEBUILDER_VERSION)

# these are use by the kube builder test harness
Expand All @@ -32,15 +31,13 @@ export TEST_ASSET_KUBE_APISERVER TEST_ASSET_ETCD TEST_ASSET_KUBECTL
-include golang.mk

ifeq ($(CRD_DIR),)
$(error please set CRD_DIR prior to including kubebuilder.mk)
$(error please set CRD_DIR (directories where CRD manifests will be saved) prior to including kubebuilder.mk)
endif

ifeq ($(CONTROLLERGEN_PATHS),)
$(error please set CONTROLLERGEN_PATHS prior to including kubebuilder.mk)
ifeq ($(API_DIR),)
$(error please set API_DIR ()(directories where KUBEBUILDER API types are defined) prior to including kubebuilder.mk)
endif

CONTROLLERGEN := $(TOOLS_HOST_DIR)/controller-gen

# ====================================================================================
# Kubebuilder Targets

Expand All @@ -49,16 +46,9 @@ kubebuilder.manifests: $(CONTROLLERGEN)
@$(INFO) Generating CRD manifests
@# first delete the CRD_DIR, to remove the CRDs of types that no longer exist
@rm -rf $(CRD_DIR)
@$(CONTROLLERGEN) crd:trivialVersions=true paths=$(CONTROLLERGEN_PATHS) output:dir=$(CRD_DIR)
@$(CONTROLLERGEN) crd:trivialVersions=true paths=$(API_DIR) output:dir=$(CRD_DIR)
@$(OK) Generating CRD manifests

# Generate controller
kubebuilder.generate: $(GOIMPORTS) $(CONTROLLERGEN)
@$(INFO) go generate $(PLATFORM)
@CGO_ENABLED=0 CONTROLLERGEN=$(CONTROLLERGEN) $(GOHOST) generate $(GO_COMMON_FLAGS) $(GO_PACKAGES) $(GO_INTEGRATION_TEST_PACKAGES) || $(FAIL)
@find $(GO_SUBDIRS) $(GO_INTEGRATION_TESTS_SUBDIRS) -type f -name 'zz_generated*' -exec $(GOIMPORTS) -l -w -local $(GO_PROJECT) {} \;
@$(OK) go generate $(PLATFORM)

# ====================================================================================
# Common Targets

Expand All @@ -69,8 +59,7 @@ test.init: $(KUBEBUILDER)

define KUBEBULDER_HELPTEXT
Kubebuilder Targets:
bin run kubebuilder binary, pass args by setting ARGS=""
contgen Runs go code generation, to execute controller-gen tool
bin Run kubebuilder binary, pass args by setting ARGS=""
manifests Generates Kubernetes custom resources manifests (e.g. CRDs RBACs, ...)

endef
Expand All @@ -80,14 +69,15 @@ kubebuilder.help:
@echo "$$KUBEBULDER_HELPTEXT"

help-special: kubebuilder.help
manifests: kubebuilder.manifests

contgen: kubebuilder.generate
manifests: kubebuilder.manifests

kubebuilder.bin: $(KUBEBUILDER)
@$(KUBEBUILDER)/kubebuilder $(ARGS)

.PHONY: kubebuilder.help kubebuilder.bin kubebuilder.generate kubebuilder.manifests
.PHONY: kubebuilder.help kubebuilder.bin kubebuilder.manifests

# ====================================================================================
# tools
Expand All @@ -101,16 +91,4 @@ $(KUBEBUILDER):
@rm -fr $(TOOLS_HOST_DIR)/tmp
@$(OK) installing kubebuilder $(KUBEBUILDER_VERSION)

$(CONTROLLERGEN):
@$(INFO) installing controller-gen @$(CONTROLLER_GEN_VERSION)
@mkdir -p $(TOOLS_HOST_DIR)/tmp-controllergen || $(FAIL)

@# `go get` only supports versioned go packages when GO111MODULE=on
@# since $(TOOLS_HOST_DIR) is under $(GO_PROJECT), make a temp folder which has a go.mod,
@# so that $(GO_PROJECT)/go.mod doesn't get modified because of running `go get`
@cd $(TOOLS_HOST_DIR)/tmp-controllergen; rm -f go.mod; GO111MODULE=on $(GOHOST) mod init tmp-controllergen
@cd $(TOOLS_HOST_DIR)/tmp-controllergen; GOPATH=$(abspath $(GO_PKG_DIR)) GO111MODULE=on GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) || $(FAIL)
@rm -fr $(TOOLS_HOST_DIR)/tmp-controllergen

@$(OK) installing controller-gen @$(CONTROLLER_GEN_VERSION)

0 comments on commit b169d16

Please sign in to comment.