Skip to content

Commit

Permalink
fix build with go 1.18 (#374)
Browse files Browse the repository at this point in the history
* fix build with go 1.18

* support multiple version makefile

* fix ci

* remove echo

* more output

* fix CI
  • Loading branch information
freeznet authored May 23, 2022
1 parent ef521f9 commit eb67357
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
if [ "$(GO_MINOR_VERSION)" -ge "17" ]; then \
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
else \
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
fi ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
Expand All @@ -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/[email protected] ;\
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/[email protected] ;\
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/[email protected] ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
fi ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
Expand Down

0 comments on commit eb67357

Please sign in to comment.