mirror of
https://github.com/coredns/coredns.git
synced 2026-04-05 11:45:33 -04:00
lint(revive): fix context-as-argument violations (#7976)
This commit is contained in:
@@ -53,7 +53,8 @@ linters:
|
|||||||
- name: blank-imports
|
- name: blank-imports
|
||||||
|
|
||||||
- name: context-as-argument
|
- name: context-as-argument
|
||||||
disabled: true
|
arguments:
|
||||||
|
- allowTypesBefore: "*testing.T"
|
||||||
|
|
||||||
- name: context-keys-type
|
- name: context-keys-type
|
||||||
|
|
||||||
|
|||||||
@@ -53,15 +53,15 @@ func (n Nomad) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
|||||||
svcRegistrations, _, err := fetchServiceRegistrations(n, serviceName, namespace)
|
svcRegistrations, _, err := fetchServiceRegistrations(n, serviceName, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warning(err)
|
log.Warning(err)
|
||||||
return handleServiceLookupError(w, m, ctx, namespace)
|
return handleServiceLookupError(ctx, w, m, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(svcRegistrations) == 0 {
|
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 {
|
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)
|
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}))
|
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
|
m.Rcode = dns.RcodeSuccess
|
||||||
err := w.WriteMsg(m)
|
err := w.WriteMsg(m)
|
||||||
requestFailedCount.WithLabelValues(metrics.WithServer(ctx), namespace).Inc()
|
requestFailedCount.WithLabelValues(metrics.WithServer(ctx), namespace).Inc()
|
||||||
@@ -145,7 +145,7 @@ func addServiceResponses(m *dns.Msg, svcRegistrations []*api.ServiceRegistration
|
|||||||
return nil
|
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.Rcode = dns.RcodeNameError
|
||||||
m.Answer = append(m.Answer, createSOARecord(originalQName, ttl, n.Zone))
|
m.Answer = append(m.Answer, createSOARecord(originalQName, ttl, n.Zone))
|
||||||
|
|
||||||
|
|||||||
@@ -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) }
|
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.
|
// 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) {
|
func NextOrFailure(name string, next Handler, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
if next != nil {
|
if next != nil {
|
||||||
if span := ot.SpanFromContext(ctx); span != nil {
|
if span := ot.SpanFromContext(ctx); span != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user