From 66377a3b2fc191ea048f5ed81ff3513bf4793040 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 18 Apr 2023 10:33:52 +0200 Subject: [PATCH] Don't enforce Go version using //go:build in main.go files These build tags lead to a rather unhelpful error message when compiling an outdated Go versions, e.g. package github.com/cilium/cilium/daemon: build constraints exclude all Go files in ... Nothing in the error messages indicates that this is due to an outdated Go toolchain version and this has been a source of confusion several times for several developers. It's also brittle in a way that if a developer adds a new tool with a main func and forgets adding the //go:build line it will not be enforced by tooling. The update-go-version make target will only cover existing //go:build go1.X lines. We have other checks in place to guarantee that Cilium is built using the correct Go version (namely the go directive in go.mod, the check-go-version make target, the dev-doctor tool and various CI checks), so drop these build tags. Signed-off-by: Tobias Klauser --- Makefile | 8 -------- bugtool/main.go | 4 ---- cilium-health/main.go | 4 ---- cilium-health/responder/main.go | 4 ---- cilium/main.go | 8 +------- clustermesh-apiserver/main.go | 4 ---- daemon/main.go | 8 +------- hubble-relay/main.go | 4 ---- operator/main.go | 4 ---- plugins/cilium-cni/main.go | 4 ---- plugins/cilium-docker/main.go | 4 ---- 11 files changed, 2 insertions(+), 54 deletions(-) diff --git a/Makefile b/Makefile index 3c5beab6e699a..43d9480cb4780 100644 --- a/Makefile +++ b/Makefile @@ -656,14 +656,6 @@ else @$(ECHO_CHECK) "Installed Go version $(GO_INSTALLED_MAJOR_AND_MINOR_VERSION) matches required version $(GO_MAJOR_AND_MINOR_VERSION)" endif -update-go-version: ## Update Go version for all the components (images, CI, dev-doctor etc.). - # Update Go version in main.go. - $(QUIET) for fl in $(shell find . -name main.go -not -path "./vendor/*" -print); do \ - sed -i \ - -e 's|^//go:build go.*|//go:build go$(GO_MAJOR_AND_MINOR_VERSION)|g' \ - $$fl ; \ - done - dev-doctor: ## Run Cilium dev-doctor to validate local development environment. $(QUIET)$(GO) version 2>/dev/null || ( echo "go not found, see https://golang.org/doc/install" ; false ) $(QUIET)$(GO) run ./tools/dev-doctor diff --git a/bugtool/main.go b/bugtool/main.go index 4e53f089bf75b..811e3952e5eba 100644 --- a/bugtool/main.go +++ b/bugtool/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import ( diff --git a/cilium-health/main.go b/cilium-health/main.go index dfa375f573c5d..85eac1238c71b 100644 --- a/cilium-health/main.go +++ b/cilium-health/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import "github.com/cilium/cilium/cilium-health/cmd" diff --git a/cilium-health/responder/main.go b/cilium-health/responder/main.go index d9460b2645d2d..57587cf59521b 100644 --- a/cilium-health/responder/main.go +++ b/cilium-health/responder/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import ( diff --git a/cilium/main.go b/cilium/main.go index 3f83b5ce4851f..30ec5caad17c3 100644 --- a/cilium/main.go +++ b/cilium/main.go @@ -1,15 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main -import ( - "github.com/cilium/cilium/cilium/cmd" -) +import "github.com/cilium/cilium/cilium/cmd" func main() { cmd.Execute() diff --git a/clustermesh-apiserver/main.go b/clustermesh-apiserver/main.go index 6ea654e3f7506..e350f40e3cf5b 100644 --- a/clustermesh-apiserver/main.go +++ b/clustermesh-apiserver/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import ( diff --git a/daemon/main.go b/daemon/main.go index 73cc8cfaa2891..430008daab118 100644 --- a/daemon/main.go +++ b/daemon/main.go @@ -1,15 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main -import ( - "github.com/cilium/cilium/daemon/cmd" -) +import "github.com/cilium/cilium/daemon/cmd" func main() { cmd.Execute() diff --git a/hubble-relay/main.go b/hubble-relay/main.go index 6463044576342..c7db13ad19fe1 100644 --- a/hubble-relay/main.go +++ b/hubble-relay/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import ( diff --git a/operator/main.go b/operator/main.go index 66481a82e23bf..e20883c66adf0 100644 --- a/operator/main.go +++ b/operator/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import "github.com/cilium/cilium/operator/cmd" diff --git a/plugins/cilium-cni/main.go b/plugins/cilium-cni/main.go index a3d0b7e982807..98807f02f693f 100644 --- a/plugins/cilium-cni/main.go +++ b/plugins/cilium-cni/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import ( diff --git a/plugins/cilium-docker/main.go b/plugins/cilium-docker/main.go index 83c3ebbeed2e9..b66b35d9108d2 100644 --- a/plugins/cilium-docker/main.go +++ b/plugins/cilium-docker/main.go @@ -1,10 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Cilium -// Ensure build fails on versions of Go that are not supported by Cilium. -// This build tag should be kept in sync with the version specified in go.mod. -//go:build go1.20 - package main import (