From 3d33c4e4f8801393934f481bba4a9ee62122bfaf Mon Sep 17 00:00:00 2001 From: Sean Eagan Date: Tue, 2 Feb 2021 10:04:03 -0600 Subject: [PATCH] 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 Change-Id: I82f44c2efb75556d9f1ecbe78018b8bd65b34f9f --- Makefile | 24 ++++++++++--------- .../bases/airship.airshipit.org_vinoes.yaml | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index d4310bb..fa5461a 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/config/crd/bases/airship.airshipit.org_vinoes.yaml b/config/crd/bases/airship.airshipit.org_vinoes.yaml index 0e28104..98f4b9c 100644 --- a/config/crd/bases/airship.airshipit.org_vinoes.yaml +++ b/config/crd/bases/airship.airshipit.org_vinoes.yaml @@ -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: