From 7fd983b02c734695cddbaaeddbc3f9b94e7fde9a Mon Sep 17 00:00:00 2001 From: Ville Vesilehto Date: Mon, 30 Mar 2026 03:01:03 +0300 Subject: [PATCH] lint(revive): fix context-as-argument violations (#7976) --- .golangci.yml | 3 ++- plugin/nomad/nomad.go | 10 +++++----- plugin/plugin.go | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index fb5edd646..bf6de9ae5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -53,7 +53,8 @@ linters: - name: blank-imports - name: context-as-argument - disabled: true + arguments: + - allowTypesBefore: "*testing.T" - name: context-keys-type diff --git a/plugin/nomad/nomad.go b/plugin/nomad/nomad.go index 5a0042c4f..3a4dfa089 100644 --- a/plugin/nomad/nomad.go +++ b/plugin/nomad/nomad.go @@ -53,15 +53,15 @@ func (n Nomad) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( svcRegistrations, _, err := fetchServiceRegistrations(n, serviceName, namespace) if err != nil { log.Warning(err) - return handleServiceLookupError(w, m, ctx, namespace) + return handleServiceLookupError(ctx, w, m, namespace) } if len(svcRegistrations) == 0 { - return handleResponseError(n, w, m, originalQName, n.ttl, ctx, namespace, err) + return handleResponseError(ctx, n, w, m, originalQName, n.ttl, namespace, err) } if err := addServiceResponses(m, svcRegistrations, header, state.QType(), originalQName, n.ttl); err != nil { - return handleResponseError(n, w, m, originalQName, n.ttl, ctx, namespace, err) + return handleResponseError(ctx, n, w, m, originalQName, n.ttl, namespace, err) } err = w.WriteMsg(m) @@ -107,7 +107,7 @@ func fetchServiceRegistrations(n Nomad, serviceName, namespace string) ([]*api.S return nc.Services().Get(serviceName, (&api.QueryOptions{Namespace: namespace, Filter: n.filter})) } -func handleServiceLookupError(w dns.ResponseWriter, m *dns.Msg, ctx context.Context, namespace string) (int, error) { +func handleServiceLookupError(ctx context.Context, w dns.ResponseWriter, m *dns.Msg, namespace string) (int, error) { m.Rcode = dns.RcodeSuccess err := w.WriteMsg(m) requestFailedCount.WithLabelValues(metrics.WithServer(ctx), namespace).Inc() @@ -145,7 +145,7 @@ func addServiceResponses(m *dns.Msg, svcRegistrations []*api.ServiceRegistration return nil } -func handleResponseError(n Nomad, w dns.ResponseWriter, m *dns.Msg, originalQName string, ttl uint32, ctx context.Context, namespace string, err error) (int, error) { +func handleResponseError(ctx context.Context, n Nomad, w dns.ResponseWriter, m *dns.Msg, originalQName string, ttl uint32, namespace string, err error) (int, error) { m.Rcode = dns.RcodeNameError m.Answer = append(m.Answer, createSOARecord(originalQName, ttl, n.Zone)) diff --git a/plugin/plugin.go b/plugin/plugin.go index 2cb55e64d..20e9c2628 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -71,6 +71,8 @@ func (f HandlerFunc) Name() string { return "handlerfunc" } func Error(name string, err error) error { return fmt.Errorf("%s/%s: %w", "plugin", name, err) } // NextOrFailure calls next.ServeDNS when next is not nil, otherwise it will return, a ServerFailure and a `no next plugin found` error. +// +//nolint:revive // ctx is not the first parameter to preserve the existing public API. func NextOrFailure(name string, next Handler, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { if next != nil { if span := ot.SpanFromContext(ctx); span != nil {