Ensure correct version of controller-gen

If controller-gen is already installed, but with a different version
than the one specified, this will update it to the correct version.

This avoids extraneous diffs in patchsets that we have seen, such as
the controller-gen version number that gets inserted into manifests.

Signed-off-by: Sean Eagan <seaneagan1@gmail.com>
Change-Id: I82f44c2efb75556d9f1ecbe78018b8bd65b34f9f
This commit is contained in:
Sean Eagan 2021-02-02 10:04:03 -06:00
parent e82e410dbe
commit 3d33c4e4f8
2 changed files with 14 additions and 12 deletions

View File

@ -8,6 +8,8 @@ CRD_OPTIONS ?= "crd:trivialVersions=true"
TOOLBINDIR := tools/bin
CONTROLLER_GEN_VERSION = v0.3.0
# linting
LINTER := $(TOOLBINDIR)/golangci-lint
LINTER_CONFIG := .golangci.yaml
@ -83,22 +85,22 @@ docker-push-controller:
docker-push-nodelabeler:
docker push ${NODE_LABELER_IMG}
CONTROLLER_GEN:=$(GOBIN)/controller-gen
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
if ! which $(CONTROLLER_GEN) || [ 'Version $(CONTROLLER_GEN_VERSION)' != "$$($(CONTROLLER_GEN) --version)" ];\
then\
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
fi;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
.PHONY: lint
lint: $(LINTER)

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.5
controller-gen.kubebuilder.io/version: v0.3.0
creationTimestamp: null
name: vinoes.airship.airshipit.org
spec: