From 4382b80a354fa452699234b7f308d90da3e7491a Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 10 Sep 2026 19:34:44 -0700 Subject: [PATCH] core: upgrade Go requirement to 1.26.0 (#8466) * core: upgrade Go requirement to 1.26.0 As golang 1.27 has been released, this PR - Bump Go version requirement to 1.26.0 - Update Go build version to 1.27.0 This is also for solving the issue encountered in 8092 of k8s update Signed-off-by: Yong Tang * Bump golang ci Signed-off-by: Yong Tang * Fix Signed-off-by: Yong Tang * Fix Signed-off-by: Yong Tang * Fix Signed-off-by: Yong Tang * Migrate faillint to forbidigo, as failint has not bee updated for more than a year Signed-off-by: Yong Tang --------- Signed-off-by: Yong Tang --- .github/workflows/go.test.yml | 1 - .github/workflows/golangci-lint.yml | 2 +- .go-version | 2 +- .golangci.yml | 8 +++ README.md | 2 +- core/dnsserver/server.go | 5 +- core/dnsserver/server_https3_test.go | 6 +-- go.mod | 2 +- plugin/dns64/dns64_test.go | 2 +- plugin/file/secondary_test.go | 2 +- plugin/grpc_server/setup_test.go | 16 +++--- plugin/https/setup_test.go | 16 +++--- plugin/https3/setup_test.go | 8 ++- plugin/kubernetes/controller.go | 66 +++++++++++------------ plugin/kubernetes/object/deepcopy_test.go | 6 +-- plugin/pkg/proxy/doq_test.go | 15 +++--- plugin/pkg/tls/tls.go | 4 +- plugin/quic/setup_test.go | 16 +++--- plugin/rewrite/reverter.go | 15 +++--- plugin/siit/siit_test.go | 2 +- plugin/test/helpers.go | 2 +- test/metrics_test.go | 2 +- test/presubmit_test.go | 19 ------- 23 files changed, 99 insertions(+), 120 deletions(-) diff --git a/.github/workflows/go.test.yml b/.github/workflows/go.test.yml index e3591621b..5b2158032 100644 --- a/.github/workflows/go.test.yml +++ b/.github/workflows/go.test.yml @@ -102,7 +102,6 @@ jobs: - name: Test run: | - go install github.com/fatih/faillint@c56e3ec6dbfc933bbeb884fd31f2bcd41f712657 # v1.15.0 ( cd test; go test -race ./... ) test-makefile-release: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index fa6d35364..8af7a818d 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,4 +20,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: - version: v2.11.4 + version: v2.13.2 diff --git a/.go-version b/.go-version index ad7c780d0..5db08bf2d 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.26.7 +1.27.0 diff --git a/.golangci.yml b/.golangci.yml index 29eec3fe0..8fe90278f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ linters: - canonicalheader - copyloopvar - durationcheck + - forbidigo - godoclint - gosec - govet @@ -43,6 +44,13 @@ linters: - perfsprint - gosec settings: + forbidigo: + analyze-types: true + forbid: + - pattern: "^prometheus\\.(NewCounter|NewCounterVec|NewGauge|NewGaugeVec|NewGaugeFunc|NewHistogram|NewHistogramVec|NewSummary|NewSummaryVec)$" + pkg: "^github\\.com/prometheus/client_golang/prometheus$" + msg: use github.com/prometheus/client_golang/prometheus/promauto + govet: enable: - nilness diff --git a/README.md b/README.md index 00f3819be..f0b6dc045 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ out-of-tree plugins. To compile CoreDNS, we assume you have a working Go setup. See various tutorials if you don’t have that already configured. -First, make sure your golang version is 1.25.0 or higher as `go mod` support and other api is needed. +First, make sure your golang version is 1.26.0 or higher as `go mod` support and other api is needed. See [here](https://github.com/golang/go/wiki/Modules) for `go mod` details. Then, check out the project and run `make` to compile the binary: diff --git a/core/dnsserver/server.go b/core/dnsserver/server.go index ad6af9e06..32c405621 100644 --- a/core/dnsserver/server.go +++ b/core/dnsserver/server.go @@ -18,6 +18,7 @@ import ( "maps" "net" "runtime/debug" + "slices" "strings" "sync" "time" @@ -128,8 +129,8 @@ func NewServer(addr string, group []*Config) (*Server, error) { // compile custom plugin for everything var stack plugin.Handler - for i := len(site.Plugin) - 1; i >= 0; i-- { - stack = site.Plugin[i](stack) + for _, v := range slices.Backward(site.Plugin) { + stack = v(stack) // register the *handler* also site.registerHandler(stack) diff --git a/core/dnsserver/server_https3_test.go b/core/dnsserver/server_https3_test.go index bb7e27f1e..38e563dac 100644 --- a/core/dnsserver/server_https3_test.go +++ b/core/dnsserver/server_https3_test.go @@ -414,8 +414,7 @@ func TestServeHTTP3DoesNotLeakBodyReadError(t *testing.T) { func requireHTTPS3ConnectionRejected(t *testing.T, err error) { t.Helper() - var appErr *quic.ApplicationError - if errors.As(err, &appErr) { + if appErr, ok := errors.AsType[*quic.ApplicationError](err); ok { if !appErr.Remote { t.Fatalf("connection closed with local application error: %v", err) } @@ -428,8 +427,7 @@ func requireHTTPS3ConnectionRejected(t *testing.T, err error) { // An application close sent before 1-RTT keys are available is encoded as // the generic transport-level APPLICATION_ERROR. In that case, the peer // cannot observe the HTTP/3 application code or reason phrase. - var transportErr *quic.TransportError - if errors.As(err, &transportErr) { + if transportErr, ok := errors.AsType[*quic.TransportError](err); ok { if !transportErr.Remote { t.Fatalf("connection closed with local transport error: %v", err) } diff --git a/go.mod b/go.mod index 5c54ab259..1d596008f 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/coredns/coredns // Note this minimum version requirement. CoreDNS supports the last two // Go versions. This follows the upstream Go project support. -go 1.25.0 +go 1.26.0 require ( github.com/Azure/azure-sdk-for-go v68.0.0+incompatible diff --git a/plugin/dns64/dns64_test.go b/plugin/dns64/dns64_test.go index c501fb2a2..d7ada8ee8 100644 --- a/plugin/dns64/dns64_test.go +++ b/plugin/dns64/dns64_test.go @@ -507,7 +507,7 @@ func TestDNS64(t *testing.T) { } actual := rec.Msg if actual.Rcode != rc { - t.Fatalf("ServeDNS should return real result code %q != %q", actual.Rcode, rc) + t.Fatalf("ServeDNS should return real result code %d != %d", actual.Rcode, rc) } if !reflect.DeepEqual(actual, tc.resp) { diff --git a/plugin/file/secondary_test.go b/plugin/file/secondary_test.go index 189cc0fa5..dc94695f7 100644 --- a/plugin/file/secondary_test.go +++ b/plugin/file/secondary_test.go @@ -92,7 +92,7 @@ func TestShouldTransfer(t *testing.T) { t.Fatalf("Unable to run shouldTransfer: %v", err) } if !should { - t.Fatalf("ShouldTransfer should return true for serial: %q", soa.serial-1) + t.Fatalf("ShouldTransfer should return true for serial: %d", soa.serial-1) } // Serial equal z.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial)) diff --git a/plugin/grpc_server/setup_test.go b/plugin/grpc_server/setup_test.go index 75fb74980..3a865bed3 100644 --- a/plugin/grpc_server/setup_test.go +++ b/plugin/grpc_server/setup_test.go @@ -32,14 +32,14 @@ func TestSetup(t *testing.T) { max_streams 100 }`, shouldErr: false, - expectedMaxStreams: intPtr(100), + expectedMaxStreams: new(100), }, { input: `grpc_server { max_connections 200 }`, shouldErr: false, - expectedMaxConnections: intPtr(200), + expectedMaxConnections: new(200), }, { input: `grpc_server { @@ -47,8 +47,8 @@ func TestSetup(t *testing.T) { max_connections 100 }`, shouldErr: false, - expectedMaxStreams: intPtr(50), - expectedMaxConnections: intPtr(100), + expectedMaxStreams: new(50), + expectedMaxConnections: new(100), }, // Zero values (unbounded) { @@ -56,14 +56,14 @@ func TestSetup(t *testing.T) { max_streams 0 }`, shouldErr: false, - expectedMaxStreams: intPtr(0), + expectedMaxStreams: new(0), }, { input: `grpc_server { max_connections 0 }`, shouldErr: false, - expectedMaxConnections: intPtr(0), + expectedMaxConnections: new(0), }, // Error cases { @@ -139,9 +139,7 @@ func TestSetup(t *testing.T) { } } -func intPtr(v int) *int { - return &v -} +//go:fix inline func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) { t.Helper() diff --git a/plugin/https/setup_test.go b/plugin/https/setup_test.go index 890c2cfd8..e6c383dc1 100644 --- a/plugin/https/setup_test.go +++ b/plugin/https/setup_test.go @@ -48,14 +48,14 @@ func TestSetup(t *testing.T) { max_connections 200 }`, shouldErr: false, - expectedMaxConnections: intPtr(200), + expectedMaxConnections: new(200), }, { input: `https { max_streams 100 }`, shouldErr: false, - expectedMaxStreams: intPtr(100), + expectedMaxStreams: new(100), }, { input: `https { @@ -63,8 +63,8 @@ func TestSetup(t *testing.T) { max_streams 100 }`, shouldErr: false, - expectedMaxConnections: intPtr(200), - expectedMaxStreams: intPtr(100), + expectedMaxConnections: new(200), + expectedMaxStreams: new(100), }, // Zero values (unbounded) { @@ -72,7 +72,7 @@ func TestSetup(t *testing.T) { max_connections 0 }`, shouldErr: false, - expectedMaxConnections: intPtr(0), + expectedMaxConnections: new(0), }, // Error cases { @@ -123,7 +123,7 @@ func TestSetup(t *testing.T) { max_streams 0 }`, shouldErr: false, - expectedMaxStreams: intPtr(0), + expectedMaxStreams: new(0), }, { input: `https { @@ -199,9 +199,7 @@ func TestSetup(t *testing.T) { } } -func intPtr(v int) *int { - return &v -} +//go:fix inline func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) { t.Helper() diff --git a/plugin/https3/setup_test.go b/plugin/https3/setup_test.go index 5e4c7abc3..7973854b7 100644 --- a/plugin/https3/setup_test.go +++ b/plugin/https3/setup_test.go @@ -31,7 +31,7 @@ func TestSetup(t *testing.T) { max_streams 100 }`, shouldErr: false, - expectedMaxStreams: intPtr(100), + expectedMaxStreams: new(100), }, // Zero values (unbounded) { @@ -39,7 +39,7 @@ func TestSetup(t *testing.T) { max_streams 0 }`, shouldErr: false, - expectedMaxStreams: intPtr(0), + expectedMaxStreams: new(0), }, // Error cases { @@ -114,9 +114,7 @@ func TestSetup(t *testing.T) { } } -func intPtr(v int) *int { - return &v -} +//go:fix inline func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) { t.Helper() diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go index 31b6c937f..f8d3d523b 100644 --- a/plugin/kubernetes/controller.go +++ b/plugin/kubernetes/controller.go @@ -132,7 +132,7 @@ type dnsControlOpts struct { } // newdnsController creates a controller for CoreDNS. -func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsClient mcsClientset.MulticlusterV1alpha1Interface, opts dnsControlOpts) *dnsControl { +func newdnsController(_ context.Context, kubeClient kubernetes.Interface, mcsClient mcsClientset.MulticlusterV1alpha1Interface, opts dnsControlOpts) *dnsControl { dns := dnsControl{ client: kubeClient, mcsClient: mcsClient, @@ -147,8 +147,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC dns.svcLister, dns.svcController = object.NewIndexerInformer( cache.ToListWatcherWithWatchListSemantics( &cache.ListWatch{ - ListFunc: serviceListFunc(ctx, dns.client, api.NamespaceAll, dns.selector), - WatchFunc: serviceWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector), + ListWithContextFunc: serviceListFunc(dns.client, api.NamespaceAll, dns.selector), + WatchFuncWithContext: serviceWatchFunc(dns.client, api.NamespaceAll, dns.selector), }, kubeClient, ), @@ -161,8 +161,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC podLister, podController := object.NewIndexerInformer( cache.ToListWatcherWithWatchListSemantics( &cache.ListWatch{ - ListFunc: podListFunc(ctx, dns.client, api.NamespaceAll, dns.selector), - WatchFunc: podWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector), + ListWithContextFunc: podListFunc(dns.client, api.NamespaceAll, dns.selector), + WatchFuncWithContext: podWatchFunc(dns.client, api.NamespaceAll, dns.selector), }, kubeClient, ), @@ -183,8 +183,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC epLister, epController := object.NewIndexerInformer( cache.ToListWatcherWithWatchListSemantics( &cache.ListWatch{ - ListFunc: endpointSliceListFunc(ctx, dns.client, api.NamespaceAll, dns.selector), - WatchFunc: endpointSliceWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector), + ListWithContextFunc: endpointSliceListFunc(dns.client, api.NamespaceAll, dns.selector), + WatchFuncWithContext: endpointSliceWatchFunc(dns.client, api.NamespaceAll, dns.selector), }, kubeClient, ), @@ -201,8 +201,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC dns.nsLister, dns.nsController = object.NewIndexerInformer( cache.ToListWatcherWithWatchListSemantics( &cache.ListWatch{ - ListFunc: namespaceListFunc(ctx, dns.client, dns.namespaceSelector), - WatchFunc: namespaceWatchFunc(ctx, dns.client, dns.namespaceSelector), + ListWithContextFunc: namespaceListFunc(dns.client, dns.namespaceSelector), + WatchFuncWithContext: namespaceWatchFunc(dns.client, dns.namespaceSelector), }, kubeClient, ), @@ -222,8 +222,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC dns.mcEpLister, dns.mcEpController = object.NewIndexerInformer( cache.ToListWatcherWithWatchListSemantics( &cache.ListWatch{ - ListFunc: endpointSliceListFunc(ctx, dns.client, api.NamespaceAll, mcsEpSelector), - WatchFunc: endpointSliceWatchFunc(ctx, dns.client, api.NamespaceAll, mcsEpSelector), + ListWithContextFunc: endpointSliceListFunc(dns.client, api.NamespaceAll, mcsEpSelector), + WatchFuncWithContext: endpointSliceWatchFunc(dns.client, api.NamespaceAll, mcsEpSelector), }, kubeClient, ), @@ -235,8 +235,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC dns.svcImportLister, dns.svcImportController = object.NewIndexerInformer( cache.ToListWatcherWithWatchListSemantics( &cache.ListWatch{ - ListFunc: serviceImportListFunc(ctx, dns.mcsClient, api.NamespaceAll, dns.namespaceSelector), - WatchFunc: serviceImportWatchFunc(ctx, dns.mcsClient, api.NamespaceAll, dns.namespaceSelector), + ListWithContextFunc: serviceImportListFunc(dns.mcsClient, api.NamespaceAll, dns.namespaceSelector), + WatchFuncWithContext: serviceImportWatchFunc(dns.mcsClient, api.NamespaceAll, dns.namespaceSelector), }, kubeClient, ), @@ -334,8 +334,8 @@ func mcEpNameNamespaceIndexFunc(obj any) ([]string, error) { return []string{mcEp.Index}, nil } -func serviceListFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { - return func(opts meta.ListOptions) (runtime.Object, error) { +func serviceListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) { + return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) { if s != nil { opts.LabelSelector = s.String() } @@ -343,8 +343,8 @@ func serviceListFunc(ctx context.Context, c kubernetes.Interface, ns string, s l } } -func podListFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { - return func(opts meta.ListOptions) (runtime.Object, error) { +func podListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) { + return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) { if s != nil { opts.LabelSelector = s.String() } @@ -356,8 +356,8 @@ func podListFunc(ctx context.Context, c kubernetes.Interface, ns string, s label } } -func endpointSliceListFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { - return func(opts meta.ListOptions) (runtime.Object, error) { +func endpointSliceListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) { + return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) { if s != nil { opts.LabelSelector = s.String() } @@ -365,8 +365,8 @@ func endpointSliceListFunc(ctx context.Context, c kubernetes.Interface, ns strin } } -func namespaceListFunc(ctx context.Context, c kubernetes.Interface, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { - return func(opts meta.ListOptions) (runtime.Object, error) { +func namespaceListFunc(c kubernetes.Interface, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) { + return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) { if s != nil { opts.LabelSelector = s.String() } @@ -374,8 +374,8 @@ func namespaceListFunc(ctx context.Context, c kubernetes.Interface, s labels.Sel } } -func serviceImportListFunc(ctx context.Context, c mcsClientset.MulticlusterV1alpha1Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { - return func(opts meta.ListOptions) (runtime.Object, error) { +func serviceImportListFunc(c mcsClientset.MulticlusterV1alpha1Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) { + return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) { if s != nil { opts.LabelSelector = s.String() } @@ -383,8 +383,8 @@ func serviceImportListFunc(ctx context.Context, c mcsClientset.MulticlusterV1alp } } -func serviceWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { - return func(options meta.ListOptions) (watch.Interface, error) { +func serviceWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) { + return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) { if s != nil { options.LabelSelector = s.String() } @@ -392,8 +392,8 @@ func serviceWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s } } -func podWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { - return func(options meta.ListOptions) (watch.Interface, error) { +func podWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) { + return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) { if s != nil { options.LabelSelector = s.String() } @@ -405,8 +405,8 @@ func podWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labe } } -func endpointSliceWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { - return func(options meta.ListOptions) (watch.Interface, error) { +func endpointSliceWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) { + return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) { if s != nil { options.LabelSelector = s.String() } @@ -414,8 +414,8 @@ func endpointSliceWatchFunc(ctx context.Context, c kubernetes.Interface, ns stri } } -func namespaceWatchFunc(ctx context.Context, c kubernetes.Interface, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { - return func(options meta.ListOptions) (watch.Interface, error) { +func namespaceWatchFunc(c kubernetes.Interface, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) { + return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) { if s != nil { options.LabelSelector = s.String() } @@ -423,8 +423,8 @@ func namespaceWatchFunc(ctx context.Context, c kubernetes.Interface, s labels.Se } } -func serviceImportWatchFunc(ctx context.Context, c mcsClientset.MulticlusterV1alpha1Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { - return func(options meta.ListOptions) (watch.Interface, error) { +func serviceImportWatchFunc(c mcsClientset.MulticlusterV1alpha1Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) { + return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) { if s != nil { options.LabelSelector = s.String() } diff --git a/plugin/kubernetes/object/deepcopy_test.go b/plugin/kubernetes/object/deepcopy_test.go index 76c7dec22..716bc95a8 100644 --- a/plugin/kubernetes/object/deepcopy_test.go +++ b/plugin/kubernetes/object/deepcopy_test.go @@ -11,7 +11,7 @@ import ( mcs "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" ) -func ptrTo[T any](v T) *T { return &v } +//go:fix inline // dump renders an object for a failure message. %+v prints an aliased pointer field as // an address, which hides the value that actually differs, so render as JSON instead. @@ -76,7 +76,7 @@ func deepCopyCases() []struct { Ports: []api.ServicePort{{ Name: "http", Protocol: api.ProtocolTCP, Port: 80, // A pointer field, so a slice copy alone leaves it shared. - AppProtocol: ptrTo("kubernetes.io/h2c"), + AppProtocol: new("kubernetes.io/h2c"), }}, ExternalIPs: []string{"1.2.3.4"}, }}, @@ -89,7 +89,7 @@ func deepCopyCases() []struct { Type: mcs.ClusterSetIP, Ports: []mcs.ServicePort{{ Name: "http", Protocol: api.ProtocolTCP, Port: 80, - AppProtocol: ptrTo("kubernetes.io/h2c"), + AppProtocol: new("kubernetes.io/h2c"), }}, }}, {"Namespace", &Namespace{Version: "1", Name: "testns"}}, diff --git a/plugin/pkg/proxy/doq_test.go b/plugin/pkg/proxy/doq_test.go index ce7a9bd33..641791e97 100644 --- a/plugin/pkg/proxy/doq_test.go +++ b/plugin/pkg/proxy/doq_test.go @@ -176,12 +176,12 @@ func makeDoQTestTLSConfigs(t *testing.T) (*tls.Config, *tls.Config) { } roots.AddCert(parsed) return &tls.Config{ - Certificates: []tls.Certificate{cert}, - NextProtos: []string{doqALPN}, - }, &tls.Config{ - RootCAs: roots, - ServerName: "doq.test", - } + Certificates: []tls.Certificate{cert}, + NextProtos: []string{doqALPN}, + }, &tls.Config{ + RootCAs: roots, + ServerName: "doq.test", + } } func writeDoQTestResponse(stream *quic.Stream, response *dns.Msg) error { @@ -291,8 +291,7 @@ func TestProxyDoQVerifiesServerName(t *testing.T) { if err == nil { t.Fatal("Connect() succeeded with the wrong TLS server name") } - var hostnameError x509.HostnameError - if !errors.As(err, &hostnameError) { + if _, ok := errors.AsType[x509.HostnameError](err); !ok { t.Fatalf("Connect() error = %T %v, want x509.HostnameError", err, err) } } diff --git a/plugin/pkg/tls/tls.go b/plugin/pkg/tls/tls.go index b36eae0fe..d9c17f5b0 100644 --- a/plugin/pkg/tls/tls.go +++ b/plugin/pkg/tls/tls.go @@ -141,10 +141,10 @@ func loadRoots(caPath string) (*x509.CertPool, error) { func NewHTTPSTransport(cc *tls.Config) *http.Transport { tr := &http.Transport{ Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ + DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, - }).Dial, + }).DialContext, TLSHandshakeTimeout: 10 * time.Second, TLSClientConfig: cc, MaxIdleConnsPerHost: 25, diff --git a/plugin/quic/setup_test.go b/plugin/quic/setup_test.go index 11d6dd4ba..eeffb3899 100644 --- a/plugin/quic/setup_test.go +++ b/plugin/quic/setup_test.go @@ -36,7 +36,7 @@ func TestQuicSetup(t *testing.T) { max_streams 100 }`, shouldErr: false, - expectedMaxStreams: pint(100), + expectedMaxStreams: new(100), expectedWorkerPoolSize: nil, }, { @@ -45,7 +45,7 @@ func TestQuicSetup(t *testing.T) { }`, shouldErr: false, expectedMaxStreams: nil, - expectedWorkerPoolSize: pint(1000), + expectedWorkerPoolSize: new(1000), }, { input: `quic { @@ -53,8 +53,8 @@ func TestQuicSetup(t *testing.T) { worker_pool_size 1000 }`, shouldErr: false, - expectedMaxStreams: pint(100), - expectedWorkerPoolSize: pint(1000), + expectedMaxStreams: new(100), + expectedWorkerPoolSize: new(1000), }, { input: `quic { @@ -133,7 +133,7 @@ func TestQuicSetup(t *testing.T) { }`, shouldErr: true, expectedErrContent: "already defined", - expectedMaxStreams: pint(100), + expectedMaxStreams: new(100), }, { input: `quic { @@ -142,7 +142,7 @@ func TestQuicSetup(t *testing.T) { }`, shouldErr: true, expectedErrContent: "already defined", - expectedWorkerPoolSize: pint(1000), + expectedWorkerPoolSize: new(1000), }, { input: `quic { @@ -239,6 +239,4 @@ func formatNilableInt(v *int) string { return fmt.Sprintf("%d", *v) } -func pint(i int) *int { - return &i -} +//go:fix inline diff --git a/plugin/rewrite/reverter.go b/plugin/rewrite/reverter.go index 8350b32c4..d12d4e942 100644 --- a/plugin/rewrite/reverter.go +++ b/plugin/rewrite/reverter.go @@ -2,6 +2,7 @@ package rewrite import ( "fmt" + "slices" "github.com/miekg/dns" ) @@ -161,8 +162,8 @@ func copyRRs(rrs []dns.RR) []dns.RR { func (r *ResponseReverter) rewriteResourceRecord(res *dns.Msg, rr dns.RR) { // The reverting rules need to be done in reversed order. - for i := len(r.ResponseRules) - 1; i >= 0; i-- { - r.ResponseRules[i].RewriteResponse(res, rr) + for _, v := range slices.Backward(r.ResponseRules) { + v.RewriteResponse(res, rr) } } @@ -171,18 +172,18 @@ func (r *ResponseReverter) rewriteResourceRecord(res *dns.Msg, rr dns.RR) { // loops in WriteMsg would otherwise never apply them. func (r *ResponseReverter) rewriteMsg(res *dns.Msg) { // The reverting rules need to be done in reversed order. - for i := len(r.ResponseRules) - 1; i >= 0; i-- { - if _, ok := r.ResponseRules[i].(msgResponseRule); !ok { + for _, v := range slices.Backward(r.ResponseRules) { + if _, ok := v.(msgResponseRule); !ok { continue } - r.ResponseRules[i].RewriteResponse(res, nil) + v.RewriteResponse(res, nil) } } func (r *ResponseReverter) rewriteRequestExtra(req *dns.Msg, rr dns.RR) { // The reverting rules need to be done in reversed order. - for i := len(r.ResponseRules) - 1; i >= 0; i-- { - rule, ok := r.ResponseRules[i].(requestExtraRevertRule) + for _, v := range slices.Backward(r.ResponseRules) { + rule, ok := v.(requestExtraRevertRule) if !ok { continue } diff --git a/plugin/siit/siit_test.go b/plugin/siit/siit_test.go index 1f5131a43..b6f8ca924 100644 --- a/plugin/siit/siit_test.go +++ b/plugin/siit/siit_test.go @@ -541,7 +541,7 @@ func TestSIIT(t *testing.T) { } actual := rec.Msg if actual.Rcode != rc { - t.Fatalf("ServeDNS should return real result code %q != %q", actual.Rcode, rc) + t.Fatalf("ServeDNS should return real result code %d != %d", actual.Rcode, rc) } if !reflect.DeepEqual(actual, tc.resp) { diff --git a/plugin/test/helpers.go b/plugin/test/helpers.go index aa9916c38..67fd02135 100644 --- a/plugin/test/helpers.go +++ b/plugin/test/helpers.go @@ -247,7 +247,7 @@ func Section(tc Case, sec sect, rr []dns.RR) error { return fmt.Errorf("MX Mx should be %q, but is %q", tt.Mx, x.Mx) } if x.Preference != tt.Preference { - return fmt.Errorf("MX Preference should be %q, but is %q", tt.Preference, x.Preference) + return fmt.Errorf("MX Preference should be %d, but is %d", tt.Preference, x.Preference) } case *dns.NS: tt := section[i].(*dns.NS) diff --git a/test/metrics_test.go b/test/metrics_test.go index 0168b8100..a9b98ec92 100644 --- a/test/metrics_test.go +++ b/test/metrics_test.go @@ -97,7 +97,7 @@ func getBucketCount(mf *test.MetricFamily, bucketLabel string) (int, error) { return 0, fmt.Errorf("metric point for %s has no 'Buckets' field", mf.Name) } - bucketsMap, ok := bucketsField.Interface().(map[string]string) + bucketsMap, ok := reflect.TypeAssert[map[string]string](bucketsField) if !ok { return 0, fmt.Errorf("'Buckets' field for %s is not a map[string]string", mf.Name) } diff --git a/test/presubmit_test.go b/test/presubmit_test.go index 02a5ac497..12d0044a0 100644 --- a/test/presubmit_test.go +++ b/test/presubmit_test.go @@ -8,7 +8,6 @@ import ( "go/parser" "go/token" "os" - "os/exec" "path/filepath" "strings" "testing" @@ -313,21 +312,3 @@ func importtype(s string) string { } return "std" } - -// TestPrometheusImports tests the imports path used for metrics. It depends on faillint to be installed: go install github.com/fatih/faillint -func TestPrometheusImports(t *testing.T) { - if _, err := exec.LookPath("faillint"); err != nil { - fmt.Fprintf(os.Stderr, "Not executing TestPrometheusImports: faillint not found\n") - return - } - - // make this multiline? - p := `github.com/prometheus/client_golang/prometheus.{NewCounter,NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}=github.com/prometheus/client_golang/prometheus/promauto.{NewCounter,NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}` - - cmd := exec.Command("faillint", "-paths", p, "./...") - cmd.Dir = ".." - out, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Failed: %s\n%s", err, out) - } -}