Skip to content

Commit

Permalink
Don't enforce Go version using //go:build in main.go files
Browse files Browse the repository at this point in the history
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 <tobias@cilium.io>
  • Loading branch information
tklauser authored and aanm committed Apr 18, 2023
1 parent ca4f4f8 commit 66377a3
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 54 deletions.
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions bugtool/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 0 additions & 4 deletions cilium-health/main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 0 additions & 4 deletions cilium-health/responder/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
8 changes: 1 addition & 7 deletions cilium/main.go
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 0 additions & 4 deletions clustermesh-apiserver/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
8 changes: 1 addition & 7 deletions daemon/main.go
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 0 additions & 4 deletions hubble-relay/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 0 additions & 4 deletions operator/main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 0 additions & 4 deletions plugins/cilium-cni/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 0 additions & 4 deletions plugins/cilium-docker/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down

0 comments on commit 66377a3

Please sign in to comment.