From cd9754e2f1b918472aceedcc08e8f82171d3ac2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Mon, 23 Aug 2021 18:22:31 +0200 Subject: [PATCH] core: do not format deepcopy-gen files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit deepcopy-gen appends a header starting with `// +build` which makes gofmt to complain in Go 1.17 so until this is fixed in https://github.com/kubernetes/gengo/pull/210 let's skip those files for formatting. Signed-off-by: Sébastien Han --- build/crds/crds.go | 1 + build/makelib/golang.mk | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build/crds/crds.go b/build/crds/crds.go index 1bcaee88b..01bee7092 100644 --- a/build/crds/crds.go +++ b/build/crds/crds.go @@ -1,3 +1,4 @@ +//go:build crds // +build crds /* diff --git a/build/makelib/golang.mk b/build/makelib/golang.mk index 697ea293d..fed6de033 100644 --- a/build/makelib/golang.mk +++ b/build/makelib/golang.mk @@ -156,7 +156,10 @@ go.vet: .PHONY: go.fmt go.fmt: $(GOFMT) - @gofmt_out=$$($(GOFMT) -s -d -e $(GO_SUBDIRS) $(GO_INTEGRATION_TESTS_SUBDIRS) 2>&1) && [ -z "$${gofmt_out}" ] || (echo "$${gofmt_out}" 1>&2; exit 1) + # ignore deepcopy generated files since the tool hardcoded the header with a "// +build" which in Golang 1.17 makes it fail gofmt since "////go:build" is preferred + # see: https://github.com/kubernetes/gengo/blob/master/examples/deepcopy-gen/generators/deepcopy.go#L136 + # https://github.com/kubernetes/gengo/pull/210 + @gofmt_out=$$(find . -name "*.go" -not -name "*.deepcopy.go" | xargs $(GOFMT) -s -d -e 2>&1) && [ -z "$${gofmt_out}" ] || (echo "$${gofmt_out}" 1>&2; exit 1) go.validate: go.vet go.fmt