Repository: nginx/nginx-gateway-fabric
Pull request #3181 (2025-02-27 18:10:20)

Remove tools.go and require Go 1.24
go 1.24 removes the need for tools.go to include extra packages.

Updating the project to use the new tools method, and require Go 1.24 because of this. Also removed a deprecated linter.

### Checklist

Before creating a PR, run through this checklist and mark each as complete.

- [x] I have read the [CONTRIBUTING](https://github.com/nginx/nginx-gateway-fabric/blob/main/CONTRIBUTING.md) doc
- [ ] I have added tests that prove my fix is effective or that my feature works
- [x] I have checked that all unit tests pass after adding my changes
- [ ] I have updated necessary documentation
- [x] I have rebased my branch onto main
- [x] I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

### Release notes

If this PR introduces a change that affects users and needs to be mentioned in the [release notes](../blob/main/CHANGELOG.md),
please add a brief note that summarizes the change.

<!-- If this PR does not require a release note, you can just write NONE in the release-note block below. -->

```release-note

```


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/nginx/nginx-gateway-fabric/pull/3181?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 95.19%. Comparing base [(`c792439`)](https://app.codecov.io/gh/nginx/nginx-gateway-fabric/commit/c792439401d959faf930734ffdee3fd93f2cc223?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) to head [(`e3cd6f4`)](https://app.codecov.io/gh/nginx/nginx-gateway-fabric/commit/e3cd6f4521f93182035fdb4ad509f4c23fc17a96?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> Report is 4 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #3181      +/-   ##
==========================================
+ Coverage   86.14%   95.19%   +9.05%     
==========================================
  Files         113        1     -112     
  Lines       11648      229   -11419     
  Branches       62       62              
==========================================
- Hits        10034      218    -9816     
+ Misses       1553       11    -1542     
+ Partials       61        0      -61     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/nginx/nginx-gateway-fabric/pull/3181?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index a79fdb22..707f7e68 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -105,7 +105,6 @@ linters:
     - staticcheck
     - stylecheck
     - tagalign
-    - tenv
     - thelper
     - tparallel
     - typecheck
diff --git a/go.mod b/go.mod
index 34a8b528..fdfcdeb4 100644
--- a/go.mod
+++ b/go.mod
@@ -1,12 +1,11 @@
 module github.com/nginx/nginx-gateway-fabric
 
-go 1.23.0
+go 1.24.0
 
 require (
 	github.com/go-kit/log v0.2.1
 	github.com/go-logr/logr v1.4.2
 	github.com/google/go-cmp v0.7.0
-	github.com/maxbrunsfeld/counterfeiter/v6 v6.11.2
 	github.com/nginx/telemetry-exporter v0.1.3
 	github.com/nginxinc/nginx-plus-go-client v1.3.0
 	github.com/nginxinc/nginx-prometheus-exporter v1.3.0
@@ -57,6 +56,7 @@ require (
 	github.com/json-iterator/go v1.1.12 // indirect
 	github.com/klauspost/compress v1.17.9 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
+	github.com/maxbrunsfeld/counterfeiter/v6 v6.11.2 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -94,3 +94,5 @@ require (
 	sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
 	sigs.k8s.io/yaml v1.4.0 // indirect
 )
+
+tool github.com/maxbrunsfeld/counterfeiter/v6
diff --git a/internal/framework/controller/fakes.go b/internal/framework/controller/fakes.go
index 9babcf0e..b039e8e5 100644
--- a/internal/framework/controller/fakes.go
+++ b/internal/framework/controller/fakes.go
@@ -5,7 +5,7 @@ import (
 	_ "sigs.k8s.io/controller-runtime/pkg/manager" // used below to generate a fake
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 //counterfeiter:generate  sigs.k8s.io/controller-runtime/pkg/manager.Manager
 
diff --git a/internal/framework/events/handler.go b/internal/framework/events/handler.go
index f66fa064..673a6f37 100644
--- a/internal/framework/events/handler.go
+++ b/internal/framework/events/handler.go
@@ -6,7 +6,7 @@ import (
 	"github.com/go-logr/logr"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 //counterfeiter:generate . EventHandler
 
 // EventHandler handles events.
diff --git a/internal/framework/kubernetes/client.go b/internal/framework/kubernetes/client.go
index e10df946..0dac5588 100644
--- a/internal/framework/kubernetes/client.go
+++ b/internal/framework/kubernetes/client.go
@@ -2,7 +2,7 @@ package kubernetes
 
 import "sigs.k8s.io/controller-runtime/pkg/client"
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 //counterfeiter:generate . Reader
 
diff --git a/internal/framework/status/k8s_updater.go b/internal/framework/status/k8s_updater.go
index 3840b7d7..8b54e190 100644
--- a/internal/framework/status/k8s_updater.go
+++ b/internal/framework/status/k8s_updater.go
@@ -9,7 +9,7 @@ import (
 // K8sUpdater updates a resource from the k8s API.
 // It allows us to mock the client.Reader.Status.Update method.
 //
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 //counterfeiter:generate . K8sUpdater
 type K8sUpdater interface {
 	// Update is from client.StatusClient.SubResourceWriter.
diff --git a/internal/mode/static/licensing/collector.go b/internal/mode/static/licensing/collector.go
index 0e28a476..0babb3bd 100644
--- a/internal/mode/static/licensing/collector.go
+++ b/internal/mode/static/licensing/collector.go
@@ -11,7 +11,7 @@ import (
 	"github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 //counterfeiter:generate . Collector
 
diff --git a/internal/mode/static/nginx/config/generator.go b/internal/mode/static/nginx/config/generator.go
index 00b9500a..49be7696 100644
--- a/internal/mode/static/nginx/config/generator.go
+++ b/internal/mode/static/nginx/config/generator.go
@@ -17,7 +17,7 @@ import (
 	"github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 //counterfeiter:generate . Generator
 
 // Volumes here also need to be added to our crossplane ephemeral test container.
diff --git a/internal/mode/static/nginx/config/policies/policy.go b/internal/mode/static/nginx/config/policies/policy.go
index b818f5a2..d65a375d 100644
--- a/internal/mode/static/nginx/config/policies/policy.go
+++ b/internal/mode/static/nginx/config/policies/policy.go
@@ -9,7 +9,7 @@ import (
 	"sigs.k8s.io/gateway-api/apis/v1alpha2"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 // Policy is an extension of client.Object. It adds methods that are common among all NGF Policies.
 //
diff --git a/internal/mode/static/nginx/config/policies/validator.go b/internal/mode/static/nginx/config/policies/validator.go
index 7ab88667..0bb7b589 100644
--- a/internal/mode/static/nginx/config/policies/validator.go
+++ b/internal/mode/static/nginx/config/policies/validator.go
@@ -1,6 +1,6 @@
 package policies
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 import (
 	"fmt"
diff --git a/internal/mode/static/nginx/file/manager.go b/internal/mode/static/nginx/file/manager.go
index 6c535ddf..52c64216 100644
--- a/internal/mode/static/nginx/file/manager.go
+++ b/internal/mode/static/nginx/file/manager.go
@@ -10,7 +10,7 @@ import (
 	"github.com/go-logr/logr"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 const (
 	// regularFileMode defines the default file mode for regular files.
diff --git a/internal/mode/static/nginx/runtime/manager.go b/internal/mode/static/nginx/runtime/manager.go
index afa64164..8c378f1e 100644
--- a/internal/mode/static/nginx/runtime/manager.go
+++ b/internal/mode/static/nginx/runtime/manager.go
@@ -16,7 +16,7 @@ import (
 	"k8s.io/apimachinery/pkg/util/wait"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 const (
 	// PidFile specifies the location of the PID file for the Nginx process.
diff --git a/internal/mode/static/nginx/runtime/verify.go b/internal/mode/static/nginx/runtime/verify.go
index 9dc64d4e..e5d7e64b 100644
--- a/internal/mode/static/nginx/runtime/verify.go
+++ b/internal/mode/static/nginx/runtime/verify.go
@@ -19,7 +19,7 @@ const configVersionURI = "/var/run/nginx/nginx-config-version.sock"
 var noNewWorkersErrFmt = "reload unsuccessful: no new NGINX worker processes started for config version %d." +
 	" Please check the NGINX container logs for possible configuration issues: %w"
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . nginxConfigVerifier
+//go:generate go tool counterfeiter . nginxConfigVerifier
 
 type nginxConfigVerifier interface {
 	GetConfigVersion() (int, error)
diff --git a/internal/mode/static/state/change_processor.go b/internal/mode/static/state/change_processor.go
index 61d6475d..3f5122df 100644
--- a/internal/mode/static/state/change_processor.go
+++ b/internal/mode/static/state/change_processor.go
@@ -26,7 +26,7 @@ import (
 	"github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 // ChangeType is the type of change that occurred based on a k8s object event.
 type ChangeType int
diff --git a/internal/mode/static/state/resolver/resolver.go b/internal/mode/static/state/resolver/resolver.go
index 151c5917..5162ddd5 100644
--- a/internal/mode/static/state/resolver/resolver.go
+++ b/internal/mode/static/state/resolver/resolver.go
@@ -14,7 +14,7 @@ import (
 	"github.com/nginx/nginx-gateway-fabric/internal/framework/controller/index"
 )
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 //counterfeiter:generate . ServiceResolver
 
 // ServiceResolver resolves a Service's NamespacedName and ServicePort to a list of Endpoints.
diff --git a/internal/mode/static/state/validation/validator.go b/internal/mode/static/state/validation/validator.go
index eba86b0e..dd485739 100644
--- a/internal/mode/static/state/validation/validator.go
+++ b/internal/mode/static/state/validation/validator.go
@@ -1,6 +1,6 @@
 package validation
 
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 
 import (
 	"github.com/nginx/nginx-gateway-fabric/internal/framework/conditions"
diff --git a/internal/mode/static/telemetry/exporter.go b/internal/mode/static/telemetry/exporter.go
index 21c7c99c..1cd70f12 100644
--- a/internal/mode/static/telemetry/exporter.go
+++ b/internal/mode/static/telemetry/exporter.go
@@ -9,7 +9,7 @@ import (
 
 // Exporter exports telemetry data to some destination.
 //
-//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
+//go:generate go tool counterfeiter -generate
 //counterfeiter:generate . Exporter
 type Exporter interface {
 	Export(ctx context.Context, data tel.Exportable) error
diff --git a/tools.go b/tools.go
deleted file mode 100644
index 97875e72..00000000
--- a/tools.go
+++ /dev/null
@@ -1,11 +0,0 @@
-//go:build tools
-// +build tools
-
-// This file just exists to ensure we download the tools we need for building
-// See https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
-
-package tools
-
-import (
-	_ "github.com/maxbrunsfeld/counterfeiter/v6"
-)


Test patch:
diff --git a/tests/framework/crossplane/go.mod b/tests/framework/crossplane/go.mod
index 67ea352c..0a349992 100644
--- a/tests/framework/crossplane/go.mod
+++ b/tests/framework/crossplane/go.mod
@@ -1,6 +1,6 @@
 module github.com/nginx/nginx-gateway-fabric/tests/framework/crossplane
 
-go 1.23.1
+go 1.24.0
 
 require github.com/nginxinc/nginx-go-crossplane v0.4.73
 
diff --git a/tests/go.mod b/tests/go.mod
index bfd30caa..dacde365 100644
--- a/tests/go.mod
+++ b/tests/go.mod
@@ -1,6 +1,6 @@
 module github.com/nginx/nginx-gateway-fabric/tests
 
-go 1.23.0
+go 1.24.0
 
 replace github.com/nginx/nginx-gateway-fabric => ../