Skip to content

Commit 9c4caf5

Browse files
committed
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
1 parent d13ad67 commit 9c4caf5

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

.github/workflows/project.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ jobs:
3636
wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.45.2
3737
./bin/golangci-lint --version
3838
39+
- name: validate controller-gen
40+
run: |
41+
make manager
42+
3943
- name: BuildProject
4044
run: |
4145
go mod download

Makefile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ GOARCH := $(if $(GOARCH),$(GOARCH),amd64)
2121
GOENV := CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH)
2222
GO := $(GOENV) go
2323
GO_BUILD := $(GO) build -trimpath
24+
GO_MAJOR_VERSION := $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
25+
GO_MINOR_VERSION := $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
2426

2527
# Options for 'bundle-build'
2628
ifneq ($(origin CHANNELS), undefined)
@@ -106,11 +108,15 @@ controller-gen:
106108
ifeq (, $(shell which controller-gen))
107109
@{ \
108110
set -e ;\
109-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
110-
cd $$CONTROLLER_GEN_TMP_DIR ;\
111-
go mod init tmp ;\
112-
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2 ;\
113-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
111+
if [ "$(GO_MINOR_VERSION)" -ge "17" ]; then \
112+
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2 ;\
113+
else \
114+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
115+
cd $$CONTROLLER_GEN_TMP_DIR ;\
116+
go mod init tmp ;\
117+
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2 ;\
118+
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
119+
fi ;\
114120
}
115121
CONTROLLER_GEN=$(GOBIN)/controller-gen
116122
else
@@ -121,11 +127,18 @@ kustomize:
121127
ifeq (, $(shell which kustomize))
122128
@{ \
123129
set -e ;\
124-
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
125-
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
126-
go mod init tmp ;\
127-
go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
128-
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
130+
echo "Installing kustomize..." ;\
131+
if [ "$(GO_MINOR_VERSION)" -ge "17" ]; then \
132+
echo "Installing kustomize with go install..." ;\
133+
go install sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
134+
else \
135+
echo "Installing kustomize with go get..." ;\
136+
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
137+
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
138+
go mod init tmp ;\
139+
go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
140+
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
141+
fi ;\
129142
}
130143
KUSTOMIZE=$(GOBIN)/kustomize
131144
else

0 commit comments

Comments
 (0)