From eb6735735e15048a2a8a4ce64129ffc741eecefe Mon Sep 17 00:00:00 2001 From: Rui Fu Date: Mon, 23 May 2022 21:15:20 +0800 Subject: [PATCH] fix build with go 1.18 (#374) * fix build with go 1.18 * support multiple version makefile * fix ci * remove echo * more output * fix CI --- .github/workflows/project.yml | 4 ++++ Makefile | 33 +++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml index 8c401ac27..bc82358ce 100644 --- a/.github/workflows/project.yml +++ b/.github/workflows/project.yml @@ -36,6 +36,10 @@ jobs: wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.45.2 ./bin/golangci-lint --version + - name: validate controller-gen + run: | + make manager + - name: BuildProject run: | go mod download diff --git a/Makefile b/Makefile index 3fed986e8..a27e40fd9 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,8 @@ GOARCH := $(if $(GOARCH),$(GOARCH),amd64) GOENV := CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GO := $(GOENV) go GO_BUILD := $(GO) build -trimpath +GO_MAJOR_VERSION := $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION := $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) # Options for 'bundle-build' ifneq ($(origin CHANNELS), undefined) @@ -106,11 +108,15 @@ 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.6.2 ;\ - rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ + if [ "$(GO_MINOR_VERSION)" -ge "17" ]; then \ + go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2 ;\ + else \ + 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.6.2 ;\ + rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ + fi ;\ } CONTROLLER_GEN=$(GOBIN)/controller-gen else @@ -121,11 +127,18 @@ kustomize: ifeq (, $(shell which kustomize)) @{ \ set -e ;\ - KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ - cd $$KUSTOMIZE_GEN_TMP_DIR ;\ - go mod init tmp ;\ - go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\ - rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ + echo "Installing kustomize..." ;\ + if [ "$(GO_MINOR_VERSION)" -ge "17" ]; then \ + echo "Installing kustomize with go install..." ;\ + go install sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\ + else \ + echo "Installing kustomize with go get..." ;\ + KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ + cd $$KUSTOMIZE_GEN_TMP_DIR ;\ + go mod init tmp ;\ + go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\ + rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ + fi ;\ } KUSTOMIZE=$(GOBIN)/kustomize else