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

Commit

Permalink
add targets for controller-gen in makelib/kubebuilder.mk
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 dbc597d commit 106ac5d
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions makelib/kubebuilder.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# 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 @@ -25,6 +26,39 @@ TEST_ASSET_ETCD := $(KUBEBUILDER)/etcd
TEST_ASSET_KUBECTL := $(KUBEBUILDER)/kubectl
export TEST_ASSET_KUBE_APISERVER TEST_ASSET_ETCD TEST_ASSET_KUBECTL

# ====================================================================================
# Setup environment

-include golang.mk

ifeq ($(CRD_DIR),)
$(error please set CRD_DIR prior to including kubebuilder.mk)
endif

ifeq ($(CONTROLLERGEN_PATHS),)
$(error please set CONTROLLERGEN_PATHS prior to including kubebuilder.mk)
endif

CONTROLLERGEN := $(TOOLS_HOST_DIR)/controller-gen

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

# Generate manifests e.g. CRD, RBAC etc.
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)
@$(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 @@ -35,8 +69,9 @@ test.init: $(KUBEBUILDER)

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

endef
export KUBEBULDER_HELPTEXT
Expand All @@ -46,10 +81,13 @@ kubebuilder.help:

help-special: kubebuilder.help

contgen: kubebuilder.generate
manifests: kubebuilder.manifests

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

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

# ====================================================================================
# tools
Expand All @@ -63,4 +101,16 @@ $(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 106ac5d

Please sign in to comment.