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 <yong.tang.github@outlook.com>

* Bump golang ci

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Fix

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Fix

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Fix

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Migrate faillint to forbidigo, as failint has not bee updated for more than a year

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

---------

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2026-09-10 19:34:44 -07:00
committed by GitHub
parent fb7e1d19fd
commit 4382b80a35
23 changed files with 99 additions and 120 deletions

View File

@@ -102,7 +102,6 @@ jobs:
- name: Test - name: Test
run: | run: |
go install github.com/fatih/faillint@c56e3ec6dbfc933bbeb884fd31f2bcd41f712657 # v1.15.0
( cd test; go test -race ./... ) ( cd test; go test -race ./... )
test-makefile-release: test-makefile-release:

View File

@@ -20,4 +20,4 @@ jobs:
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with: with:
version: v2.11.4 version: v2.13.2

View File

@@ -1 +1 @@
1.26.7 1.27.0

View File

@@ -10,6 +10,7 @@ linters:
- canonicalheader - canonicalheader
- copyloopvar - copyloopvar
- durationcheck - durationcheck
- forbidigo
- godoclint - godoclint
- gosec - gosec
- govet - govet
@@ -43,6 +44,13 @@ linters:
- perfsprint - perfsprint
- gosec - gosec
settings: 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: govet:
enable: enable:
- nilness - nilness

View File

@@ -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 To compile CoreDNS, we assume you have a working Go setup. See various tutorials if you don’t have
that already configured. 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. 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: Then, check out the project and run `make` to compile the binary:

View File

@@ -18,6 +18,7 @@ import (
"maps" "maps"
"net" "net"
"runtime/debug" "runtime/debug"
"slices"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -128,8 +129,8 @@ func NewServer(addr string, group []*Config) (*Server, error) {
// compile custom plugin for everything // compile custom plugin for everything
var stack plugin.Handler var stack plugin.Handler
for i := len(site.Plugin) - 1; i >= 0; i-- { for _, v := range slices.Backward(site.Plugin) {
stack = site.Plugin[i](stack) stack = v(stack)
// register the *handler* also // register the *handler* also
site.registerHandler(stack) site.registerHandler(stack)

View File

@@ -414,8 +414,7 @@ func TestServeHTTP3DoesNotLeakBodyReadError(t *testing.T) {
func requireHTTPS3ConnectionRejected(t *testing.T, err error) { func requireHTTPS3ConnectionRejected(t *testing.T, err error) {
t.Helper() t.Helper()
var appErr *quic.ApplicationError if appErr, ok := errors.AsType[*quic.ApplicationError](err); ok {
if errors.As(err, &appErr) {
if !appErr.Remote { if !appErr.Remote {
t.Fatalf("connection closed with local application error: %v", err) 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 // An application close sent before 1-RTT keys are available is encoded as
// the generic transport-level APPLICATION_ERROR. In that case, the peer // the generic transport-level APPLICATION_ERROR. In that case, the peer
// cannot observe the HTTP/3 application code or reason phrase. // cannot observe the HTTP/3 application code or reason phrase.
var transportErr *quic.TransportError if transportErr, ok := errors.AsType[*quic.TransportError](err); ok {
if errors.As(err, &transportErr) {
if !transportErr.Remote { if !transportErr.Remote {
t.Fatalf("connection closed with local transport error: %v", err) t.Fatalf("connection closed with local transport error: %v", err)
} }

2
go.mod
View File

@@ -2,7 +2,7 @@ module github.com/coredns/coredns
// Note this minimum version requirement. CoreDNS supports the last two // Note this minimum version requirement. CoreDNS supports the last two
// Go versions. This follows the upstream Go project support. // Go versions. This follows the upstream Go project support.
go 1.25.0 go 1.26.0
require ( require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible github.com/Azure/azure-sdk-for-go v68.0.0+incompatible

View File

@@ -507,7 +507,7 @@ func TestDNS64(t *testing.T) {
} }
actual := rec.Msg actual := rec.Msg
if actual.Rcode != rc { 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) { if !reflect.DeepEqual(actual, tc.resp) {

View File

@@ -92,7 +92,7 @@ func TestShouldTransfer(t *testing.T) {
t.Fatalf("Unable to run shouldTransfer: %v", err) t.Fatalf("Unable to run shouldTransfer: %v", err)
} }
if !should { 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 // Serial equal
z.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial)) z.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial))

View File

@@ -32,14 +32,14 @@ func TestSetup(t *testing.T) {
max_streams 100 max_streams 100
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: intPtr(100), expectedMaxStreams: new(100),
}, },
{ {
input: `grpc_server { input: `grpc_server {
max_connections 200 max_connections 200
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxConnections: intPtr(200), expectedMaxConnections: new(200),
}, },
{ {
input: `grpc_server { input: `grpc_server {
@@ -47,8 +47,8 @@ func TestSetup(t *testing.T) {
max_connections 100 max_connections 100
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: intPtr(50), expectedMaxStreams: new(50),
expectedMaxConnections: intPtr(100), expectedMaxConnections: new(100),
}, },
// Zero values (unbounded) // Zero values (unbounded)
{ {
@@ -56,14 +56,14 @@ func TestSetup(t *testing.T) {
max_streams 0 max_streams 0
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: intPtr(0), expectedMaxStreams: new(0),
}, },
{ {
input: `grpc_server { input: `grpc_server {
max_connections 0 max_connections 0
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxConnections: intPtr(0), expectedMaxConnections: new(0),
}, },
// Error cases // Error cases
{ {
@@ -139,9 +139,7 @@ func TestSetup(t *testing.T) {
} }
} }
func intPtr(v int) *int { //go:fix inline
return &v
}
func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) { func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) {
t.Helper() t.Helper()

View File

@@ -48,14 +48,14 @@ func TestSetup(t *testing.T) {
max_connections 200 max_connections 200
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxConnections: intPtr(200), expectedMaxConnections: new(200),
}, },
{ {
input: `https { input: `https {
max_streams 100 max_streams 100
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: intPtr(100), expectedMaxStreams: new(100),
}, },
{ {
input: `https { input: `https {
@@ -63,8 +63,8 @@ func TestSetup(t *testing.T) {
max_streams 100 max_streams 100
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxConnections: intPtr(200), expectedMaxConnections: new(200),
expectedMaxStreams: intPtr(100), expectedMaxStreams: new(100),
}, },
// Zero values (unbounded) // Zero values (unbounded)
{ {
@@ -72,7 +72,7 @@ func TestSetup(t *testing.T) {
max_connections 0 max_connections 0
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxConnections: intPtr(0), expectedMaxConnections: new(0),
}, },
// Error cases // Error cases
{ {
@@ -123,7 +123,7 @@ func TestSetup(t *testing.T) {
max_streams 0 max_streams 0
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: intPtr(0), expectedMaxStreams: new(0),
}, },
{ {
input: `https { input: `https {
@@ -199,9 +199,7 @@ func TestSetup(t *testing.T) {
} }
} }
func intPtr(v int) *int { //go:fix inline
return &v
}
func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) { func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) {
t.Helper() t.Helper()

View File

@@ -31,7 +31,7 @@ func TestSetup(t *testing.T) {
max_streams 100 max_streams 100
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: intPtr(100), expectedMaxStreams: new(100),
}, },
// Zero values (unbounded) // Zero values (unbounded)
{ {
@@ -39,7 +39,7 @@ func TestSetup(t *testing.T) {
max_streams 0 max_streams 0
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: intPtr(0), expectedMaxStreams: new(0),
}, },
// Error cases // Error cases
{ {
@@ -114,9 +114,7 @@ func TestSetup(t *testing.T) {
} }
} }
func intPtr(v int) *int { //go:fix inline
return &v
}
func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) { func assertIntPtrValue(t *testing.T, testIndex int, testInput, fieldName string, actual, expected *int) {
t.Helper() t.Helper()

View File

@@ -132,7 +132,7 @@ type dnsControlOpts struct {
} }
// newdnsController creates a controller for CoreDNS. // 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{ dns := dnsControl{
client: kubeClient, client: kubeClient,
mcsClient: mcsClient, mcsClient: mcsClient,
@@ -147,8 +147,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC
dns.svcLister, dns.svcController = object.NewIndexerInformer( dns.svcLister, dns.svcController = object.NewIndexerInformer(
cache.ToListWatcherWithWatchListSemantics( cache.ToListWatcherWithWatchListSemantics(
&cache.ListWatch{ &cache.ListWatch{
ListFunc: serviceListFunc(ctx, dns.client, api.NamespaceAll, dns.selector), ListWithContextFunc: serviceListFunc(dns.client, api.NamespaceAll, dns.selector),
WatchFunc: serviceWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector), WatchFuncWithContext: serviceWatchFunc(dns.client, api.NamespaceAll, dns.selector),
}, },
kubeClient, kubeClient,
), ),
@@ -161,8 +161,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC
podLister, podController := object.NewIndexerInformer( podLister, podController := object.NewIndexerInformer(
cache.ToListWatcherWithWatchListSemantics( cache.ToListWatcherWithWatchListSemantics(
&cache.ListWatch{ &cache.ListWatch{
ListFunc: podListFunc(ctx, dns.client, api.NamespaceAll, dns.selector), ListWithContextFunc: podListFunc(dns.client, api.NamespaceAll, dns.selector),
WatchFunc: podWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector), WatchFuncWithContext: podWatchFunc(dns.client, api.NamespaceAll, dns.selector),
}, },
kubeClient, kubeClient,
), ),
@@ -183,8 +183,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC
epLister, epController := object.NewIndexerInformer( epLister, epController := object.NewIndexerInformer(
cache.ToListWatcherWithWatchListSemantics( cache.ToListWatcherWithWatchListSemantics(
&cache.ListWatch{ &cache.ListWatch{
ListFunc: endpointSliceListFunc(ctx, dns.client, api.NamespaceAll, dns.selector), ListWithContextFunc: endpointSliceListFunc(dns.client, api.NamespaceAll, dns.selector),
WatchFunc: endpointSliceWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector), WatchFuncWithContext: endpointSliceWatchFunc(dns.client, api.NamespaceAll, dns.selector),
}, },
kubeClient, kubeClient,
), ),
@@ -201,8 +201,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC
dns.nsLister, dns.nsController = object.NewIndexerInformer( dns.nsLister, dns.nsController = object.NewIndexerInformer(
cache.ToListWatcherWithWatchListSemantics( cache.ToListWatcherWithWatchListSemantics(
&cache.ListWatch{ &cache.ListWatch{
ListFunc: namespaceListFunc(ctx, dns.client, dns.namespaceSelector), ListWithContextFunc: namespaceListFunc(dns.client, dns.namespaceSelector),
WatchFunc: namespaceWatchFunc(ctx, dns.client, dns.namespaceSelector), WatchFuncWithContext: namespaceWatchFunc(dns.client, dns.namespaceSelector),
}, },
kubeClient, kubeClient,
), ),
@@ -222,8 +222,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC
dns.mcEpLister, dns.mcEpController = object.NewIndexerInformer( dns.mcEpLister, dns.mcEpController = object.NewIndexerInformer(
cache.ToListWatcherWithWatchListSemantics( cache.ToListWatcherWithWatchListSemantics(
&cache.ListWatch{ &cache.ListWatch{
ListFunc: endpointSliceListFunc(ctx, dns.client, api.NamespaceAll, mcsEpSelector), ListWithContextFunc: endpointSliceListFunc(dns.client, api.NamespaceAll, mcsEpSelector),
WatchFunc: endpointSliceWatchFunc(ctx, dns.client, api.NamespaceAll, mcsEpSelector), WatchFuncWithContext: endpointSliceWatchFunc(dns.client, api.NamespaceAll, mcsEpSelector),
}, },
kubeClient, kubeClient,
), ),
@@ -235,8 +235,8 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, mcsC
dns.svcImportLister, dns.svcImportController = object.NewIndexerInformer( dns.svcImportLister, dns.svcImportController = object.NewIndexerInformer(
cache.ToListWatcherWithWatchListSemantics( cache.ToListWatcherWithWatchListSemantics(
&cache.ListWatch{ &cache.ListWatch{
ListFunc: serviceImportListFunc(ctx, dns.mcsClient, api.NamespaceAll, dns.namespaceSelector), ListWithContextFunc: serviceImportListFunc(dns.mcsClient, api.NamespaceAll, dns.namespaceSelector),
WatchFunc: serviceImportWatchFunc(ctx, dns.mcsClient, api.NamespaceAll, dns.namespaceSelector), WatchFuncWithContext: serviceImportWatchFunc(dns.mcsClient, api.NamespaceAll, dns.namespaceSelector),
}, },
kubeClient, kubeClient,
), ),
@@ -334,8 +334,8 @@ func mcEpNameNamespaceIndexFunc(obj any) ([]string, error) {
return []string{mcEp.Index}, nil return []string{mcEp.Index}, nil
} }
func serviceListFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(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(opts meta.ListOptions) (runtime.Object, error) { return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) {
if s != nil { if s != nil {
opts.LabelSelector = s.String() 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) { func podListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) {
return func(opts meta.ListOptions) (runtime.Object, error) { return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) {
if s != nil { if s != nil {
opts.LabelSelector = s.String() 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) { func endpointSliceListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) {
return func(opts meta.ListOptions) (runtime.Object, error) { return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) {
if s != nil { if s != nil {
opts.LabelSelector = s.String() 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) { func namespaceListFunc(c kubernetes.Interface, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) {
return func(opts meta.ListOptions) (runtime.Object, error) { return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) {
if s != nil { if s != nil {
opts.LabelSelector = s.String() 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) { func serviceImportListFunc(c mcsClientset.MulticlusterV1alpha1Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (runtime.Object, error) {
return func(opts meta.ListOptions) (runtime.Object, error) { return func(ctx context.Context, opts meta.ListOptions) (runtime.Object, error) {
if s != nil { if s != nil {
opts.LabelSelector = s.String() 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) { func serviceWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) {
return func(options meta.ListOptions) (watch.Interface, error) { return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) {
if s != nil { if s != nil {
options.LabelSelector = s.String() 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) { func podWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) {
return func(options meta.ListOptions) (watch.Interface, error) { return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) {
if s != nil { if s != nil {
options.LabelSelector = s.String() 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) { func endpointSliceWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) {
return func(options meta.ListOptions) (watch.Interface, error) { return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) {
if s != nil { if s != nil {
options.LabelSelector = s.String() 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) { func namespaceWatchFunc(c kubernetes.Interface, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) {
return func(options meta.ListOptions) (watch.Interface, error) { return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) {
if s != nil { if s != nil {
options.LabelSelector = s.String() 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) { func serviceImportWatchFunc(c mcsClientset.MulticlusterV1alpha1Interface, ns string, s labels.Selector) func(context.Context, meta.ListOptions) (watch.Interface, error) {
return func(options meta.ListOptions) (watch.Interface, error) { return func(ctx context.Context, options meta.ListOptions) (watch.Interface, error) {
if s != nil { if s != nil {
options.LabelSelector = s.String() options.LabelSelector = s.String()
} }

View File

@@ -11,7 +11,7 @@ import (
mcs "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" 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 // 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. // an address, which hides the value that actually differs, so render as JSON instead.
@@ -76,7 +76,7 @@ func deepCopyCases() []struct {
Ports: []api.ServicePort{{ Ports: []api.ServicePort{{
Name: "http", Protocol: api.ProtocolTCP, Port: 80, Name: "http", Protocol: api.ProtocolTCP, Port: 80,
// A pointer field, so a slice copy alone leaves it shared. // 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"}, ExternalIPs: []string{"1.2.3.4"},
}}, }},
@@ -89,7 +89,7 @@ func deepCopyCases() []struct {
Type: mcs.ClusterSetIP, Type: mcs.ClusterSetIP,
Ports: []mcs.ServicePort{{ Ports: []mcs.ServicePort{{
Name: "http", Protocol: api.ProtocolTCP, Port: 80, Name: "http", Protocol: api.ProtocolTCP, Port: 80,
AppProtocol: ptrTo("kubernetes.io/h2c"), AppProtocol: new("kubernetes.io/h2c"),
}}, }},
}}, }},
{"Namespace", &Namespace{Version: "1", Name: "testns"}}, {"Namespace", &Namespace{Version: "1", Name: "testns"}},

View File

@@ -176,12 +176,12 @@ func makeDoQTestTLSConfigs(t *testing.T) (*tls.Config, *tls.Config) {
} }
roots.AddCert(parsed) roots.AddCert(parsed)
return &tls.Config{ return &tls.Config{
Certificates: []tls.Certificate{cert}, Certificates: []tls.Certificate{cert},
NextProtos: []string{doqALPN}, NextProtos: []string{doqALPN},
}, &tls.Config{ }, &tls.Config{
RootCAs: roots, RootCAs: roots,
ServerName: "doq.test", ServerName: "doq.test",
} }
} }
func writeDoQTestResponse(stream *quic.Stream, response *dns.Msg) error { func writeDoQTestResponse(stream *quic.Stream, response *dns.Msg) error {
@@ -291,8 +291,7 @@ func TestProxyDoQVerifiesServerName(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("Connect() succeeded with the wrong TLS server name") t.Fatal("Connect() succeeded with the wrong TLS server name")
} }
var hostnameError x509.HostnameError if _, ok := errors.AsType[x509.HostnameError](err); !ok {
if !errors.As(err, &hostnameError) {
t.Fatalf("Connect() error = %T %v, want x509.HostnameError", err, err) t.Fatalf("Connect() error = %T %v, want x509.HostnameError", err, err)
} }
} }

View File

@@ -141,10 +141,10 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
func NewHTTPSTransport(cc *tls.Config) *http.Transport { func NewHTTPSTransport(cc *tls.Config) *http.Transport {
tr := &http.Transport{ tr := &http.Transport{
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{ DialContext: (&net.Dialer{
Timeout: 30 * time.Second, Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second, KeepAlive: 30 * time.Second,
}).Dial, }).DialContext,
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: cc, TLSClientConfig: cc,
MaxIdleConnsPerHost: 25, MaxIdleConnsPerHost: 25,

View File

@@ -36,7 +36,7 @@ func TestQuicSetup(t *testing.T) {
max_streams 100 max_streams 100
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: pint(100), expectedMaxStreams: new(100),
expectedWorkerPoolSize: nil, expectedWorkerPoolSize: nil,
}, },
{ {
@@ -45,7 +45,7 @@ func TestQuicSetup(t *testing.T) {
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: nil, expectedMaxStreams: nil,
expectedWorkerPoolSize: pint(1000), expectedWorkerPoolSize: new(1000),
}, },
{ {
input: `quic { input: `quic {
@@ -53,8 +53,8 @@ func TestQuicSetup(t *testing.T) {
worker_pool_size 1000 worker_pool_size 1000
}`, }`,
shouldErr: false, shouldErr: false,
expectedMaxStreams: pint(100), expectedMaxStreams: new(100),
expectedWorkerPoolSize: pint(1000), expectedWorkerPoolSize: new(1000),
}, },
{ {
input: `quic { input: `quic {
@@ -133,7 +133,7 @@ func TestQuicSetup(t *testing.T) {
}`, }`,
shouldErr: true, shouldErr: true,
expectedErrContent: "already defined", expectedErrContent: "already defined",
expectedMaxStreams: pint(100), expectedMaxStreams: new(100),
}, },
{ {
input: `quic { input: `quic {
@@ -142,7 +142,7 @@ func TestQuicSetup(t *testing.T) {
}`, }`,
shouldErr: true, shouldErr: true,
expectedErrContent: "already defined", expectedErrContent: "already defined",
expectedWorkerPoolSize: pint(1000), expectedWorkerPoolSize: new(1000),
}, },
{ {
input: `quic { input: `quic {
@@ -239,6 +239,4 @@ func formatNilableInt(v *int) string {
return fmt.Sprintf("%d", *v) return fmt.Sprintf("%d", *v)
} }
func pint(i int) *int { //go:fix inline
return &i
}

View File

@@ -2,6 +2,7 @@ package rewrite
import ( import (
"fmt" "fmt"
"slices"
"github.com/miekg/dns" "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) { func (r *ResponseReverter) rewriteResourceRecord(res *dns.Msg, rr dns.RR) {
// The reverting rules need to be done in reversed order. // The reverting rules need to be done in reversed order.
for i := len(r.ResponseRules) - 1; i >= 0; i-- { for _, v := range slices.Backward(r.ResponseRules) {
r.ResponseRules[i].RewriteResponse(res, rr) 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. // loops in WriteMsg would otherwise never apply them.
func (r *ResponseReverter) rewriteMsg(res *dns.Msg) { func (r *ResponseReverter) rewriteMsg(res *dns.Msg) {
// The reverting rules need to be done in reversed order. // The reverting rules need to be done in reversed order.
for i := len(r.ResponseRules) - 1; i >= 0; i-- { for _, v := range slices.Backward(r.ResponseRules) {
if _, ok := r.ResponseRules[i].(msgResponseRule); !ok { if _, ok := v.(msgResponseRule); !ok {
continue continue
} }
r.ResponseRules[i].RewriteResponse(res, nil) v.RewriteResponse(res, nil)
} }
} }
func (r *ResponseReverter) rewriteRequestExtra(req *dns.Msg, rr dns.RR) { func (r *ResponseReverter) rewriteRequestExtra(req *dns.Msg, rr dns.RR) {
// The reverting rules need to be done in reversed order. // The reverting rules need to be done in reversed order.
for i := len(r.ResponseRules) - 1; i >= 0; i-- { for _, v := range slices.Backward(r.ResponseRules) {
rule, ok := r.ResponseRules[i].(requestExtraRevertRule) rule, ok := v.(requestExtraRevertRule)
if !ok { if !ok {
continue continue
} }

View File

@@ -541,7 +541,7 @@ func TestSIIT(t *testing.T) {
} }
actual := rec.Msg actual := rec.Msg
if actual.Rcode != rc { 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) { if !reflect.DeepEqual(actual, tc.resp) {

View File

@@ -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) return fmt.Errorf("MX Mx should be %q, but is %q", tt.Mx, x.Mx)
} }
if x.Preference != tt.Preference { 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: case *dns.NS:
tt := section[i].(*dns.NS) tt := section[i].(*dns.NS)

View File

@@ -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) 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 { if !ok {
return 0, fmt.Errorf("'Buckets' field for %s is not a map[string]string", mf.Name) return 0, fmt.Errorf("'Buckets' field for %s is not a map[string]string", mf.Name)
} }

View File

@@ -8,7 +8,6 @@ import (
"go/parser" "go/parser"
"go/token" "go/token"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
@@ -313,21 +312,3 @@ func importtype(s string) string {
} }
return "std" 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)
}
}