mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
chore(lint): modernize Go (#7536)
Use modern Go constructs through the modernize analyzer from the golang.org/x/tools package. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
@@ -68,9 +68,8 @@ func BenchmarkAutoPath(b *testing.B) {
|
||||
state := request.Request{W: &test.ResponseWriter{}, Req: req}
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
result := k.AutoPath(state)
|
||||
_ = result
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ func (dns *dnsControl) EndpointSliceLatencyRecorder() *object.EndpointLatencyRec
|
||||
}
|
||||
}
|
||||
|
||||
func podIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
func podIPIndexFunc(obj any) ([]string, error) {
|
||||
p, ok := obj.(*object.Pod)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -247,7 +247,7 @@ func podIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
return []string{p.PodIP}, nil
|
||||
}
|
||||
|
||||
func svcIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
func svcIPIndexFunc(obj any) ([]string, error) {
|
||||
svc, ok := obj.(*object.Service)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -257,7 +257,7 @@ func svcIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
return idx, nil
|
||||
}
|
||||
|
||||
func svcExtIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
func svcExtIPIndexFunc(obj any) ([]string, error) {
|
||||
svc, ok := obj.(*object.Service)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -267,7 +267,7 @@ func svcExtIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
return idx, nil
|
||||
}
|
||||
|
||||
func svcNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
||||
func svcNameNamespaceIndexFunc(obj any) ([]string, error) {
|
||||
s, ok := obj.(*object.Service)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -275,7 +275,7 @@ func svcNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
||||
return []string{s.Index}, nil
|
||||
}
|
||||
|
||||
func epNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
||||
func epNameNamespaceIndexFunc(obj any) ([]string, error) {
|
||||
s, ok := obj.(*object.Endpoints)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -283,7 +283,7 @@ func epNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
||||
return []string{s.Index}, nil
|
||||
}
|
||||
|
||||
func epIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
func epIPIndexFunc(obj any) ([]string, error) {
|
||||
ep, ok := obj.(*object.Endpoints)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -291,7 +291,7 @@ func epIPIndexFunc(obj interface{}) ([]string, error) {
|
||||
return ep.IndexIP, nil
|
||||
}
|
||||
|
||||
func svcImportNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
||||
func svcImportNameNamespaceIndexFunc(obj any) ([]string, error) {
|
||||
s, ok := obj.(*object.ServiceImport)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -299,7 +299,7 @@ func svcImportNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
||||
return []string{s.Index}, nil
|
||||
}
|
||||
|
||||
func mcEpNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
||||
func mcEpNameNamespaceIndexFunc(obj any) ([]string, error) {
|
||||
mcEp, ok := obj.(*object.MultiClusterEndpoints)
|
||||
if !ok {
|
||||
return nil, errObj
|
||||
@@ -647,12 +647,12 @@ func (dns *dnsControl) GetNamespaceByName(name string) (*object.Namespace, error
|
||||
return ns, nil
|
||||
}
|
||||
|
||||
func (dns *dnsControl) Add(obj interface{}) { dns.updateModified() }
|
||||
func (dns *dnsControl) Delete(obj interface{}) { dns.updateModified() }
|
||||
func (dns *dnsControl) Update(oldObj, newObj interface{}) { dns.detectChanges(oldObj, newObj) }
|
||||
func (dns *dnsControl) Add(obj any) { dns.updateModified() }
|
||||
func (dns *dnsControl) Delete(obj any) { dns.updateModified() }
|
||||
func (dns *dnsControl) Update(oldObj, newObj any) { dns.detectChanges(oldObj, newObj) }
|
||||
|
||||
// detectChanges detects changes in objects, and updates the modified timestamp
|
||||
func (dns *dnsControl) detectChanges(oldObj, newObj interface{}) {
|
||||
func (dns *dnsControl) detectChanges(oldObj, newObj any) {
|
||||
// If both objects have the same resource version, they are identical.
|
||||
if newObj != nil && oldObj != nil && (oldObj.(meta.Object).GetResourceVersion() == newObj.(meta.Object).GetResourceVersion()) {
|
||||
return
|
||||
@@ -771,7 +771,7 @@ func multiclusterEndpointsEquivalent(a, b *object.MultiClusterEndpoints) bool {
|
||||
// serviceModified checks the services passed for changes that result in changes
|
||||
// to internal and or external records. It returns two booleans, one for internal
|
||||
// record changes, and a second for external record changes
|
||||
func serviceModified(oldObj, newObj interface{}) (intSvc, extSvc bool) {
|
||||
func serviceModified(oldObj, newObj any) (intSvc, extSvc bool) {
|
||||
if oldObj != nil && newObj == nil {
|
||||
// deleted service only modifies external zone records if it had external ips
|
||||
return true, len(oldObj.(*object.Service).ExternalIPs) > 0
|
||||
@@ -825,7 +825,7 @@ func serviceModified(oldObj, newObj interface{}) (intSvc, extSvc bool) {
|
||||
|
||||
// serviceImportEquivalent checks if the update to a ServiceImport is something
|
||||
// that matters to us or if they are effectively equivalent.
|
||||
func serviceImportEquivalent(oldObj, newObj interface{}) bool {
|
||||
func serviceImportEquivalent(oldObj, newObj any) bool {
|
||||
if oldObj != nil && newObj == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ func BenchmarkController(b *testing.B) {
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("svc1.testns.svc.cluster.local.", dns.TypeA)
|
||||
|
||||
b.ResetTimer()
|
||||
for range b.N {
|
||||
for b.Loop() {
|
||||
k.ServeDNS(ctx, rw, m)
|
||||
}
|
||||
}
|
||||
@@ -294,8 +293,8 @@ func createMultiClusterHeadlessSvc(suffix int, mcsClient mcsClientset.Multiclust
|
||||
|
||||
func TestServiceModified(t *testing.T) {
|
||||
tests := []struct {
|
||||
oldSvc interface{}
|
||||
newSvc interface{}
|
||||
oldSvc any
|
||||
newSvc any
|
||||
ichanged bool
|
||||
echanged bool
|
||||
}{
|
||||
|
||||
@@ -21,15 +21,15 @@ func (l *loggerAdapter) Enabled(_ int) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *loggerAdapter) Info(_ int, msg string, _ ...interface{}) {
|
||||
func (l *loggerAdapter) Info(_ int, msg string, _ ...any) {
|
||||
l.P.Info(msg)
|
||||
}
|
||||
|
||||
func (l *loggerAdapter) Error(_ error, msg string, _ ...interface{}) {
|
||||
func (l *loggerAdapter) Error(_ error, msg string, _ ...any) {
|
||||
l.P.Error(msg)
|
||||
}
|
||||
|
||||
func (l *loggerAdapter) WithValues(_ ...interface{}) logr.LogSink {
|
||||
func (l *loggerAdapter) WithValues(_ ...any) logr.LogSink {
|
||||
return l
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ type RecordLatencyFunc func(meta.Object)
|
||||
// DefaultProcessor is based on the Process function from cache.NewIndexerInformer except it does a conversion.
|
||||
func DefaultProcessor(convert ToFunc, recordLatency *EndpointLatencyRecorder) ProcessorBuilder {
|
||||
return func(clientState cache.Indexer, h cache.ResourceEventHandler) cache.ProcessFunc {
|
||||
return func(obj interface{}, isInitialList bool) error {
|
||||
return func(obj any, isInitialList bool) error {
|
||||
for _, d := range obj.(cache.Deltas) {
|
||||
if recordLatency != nil {
|
||||
if o, ok := d.Object.(meta.Object); ok {
|
||||
@@ -59,7 +59,7 @@ func DefaultProcessor(convert ToFunc, recordLatency *EndpointLatencyRecorder) Pr
|
||||
recordLatency.record()
|
||||
}
|
||||
case cache.Deleted:
|
||||
var obj interface{}
|
||||
var obj any
|
||||
obj, ok := d.Object.(cache.DeletedFinalStateUnknown)
|
||||
if !ok {
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user