mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
Fix go fmt, go lint, and go vet issues (#494)
This fix fixes several `go fmt`, `go lint`, and `go vet` issues, to make goreportcard happy: https://goreportcard.com/report/github.com/miekg/coredns Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -44,10 +44,14 @@ type Kubernetes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PodModeDisabled = "disabled" // default. pod requests are ignored
|
// PodModeDisabled is the default value where pod requests are ignored
|
||||||
PodModeVerified = "verified" // Pod requests are answered only if they exist
|
PodModeDisabled = "disabled"
|
||||||
PodModeInsecure = "insecure" // ALL pod requests are answered without verfying they exist
|
// PodModeVerified is where Pod requests are answered only if they exist
|
||||||
DnsSchemaVersion = "1.0.0" // https://github.com/kubernetes/dns/blob/master/docs/specification.md
|
PodModeVerified = "verified"
|
||||||
|
// PodModeInsecure is where pod requests are answered without verfying they exist
|
||||||
|
PodModeInsecure = "insecure"
|
||||||
|
// DNSSchemaVersion is the schema version: https://github.com/kubernetes/dns/blob/master/docs/specification.md
|
||||||
|
DNSSchemaVersion = "1.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
type endpoint struct {
|
type endpoint struct {
|
||||||
@@ -100,7 +104,7 @@ func (k *Kubernetes) recordsForTXT(r recordRequest) ([]msg.Service, error) {
|
|||||||
switch r.typeName {
|
switch r.typeName {
|
||||||
case "dns-version":
|
case "dns-version":
|
||||||
s := msg.Service{
|
s := msg.Service{
|
||||||
Text: DnsSchemaVersion,
|
Text: DNSSchemaVersion,
|
||||||
TTL: 28800,
|
TTL: 28800,
|
||||||
Key: msg.Path(r.typeName+"."+r.zone, "coredns")}
|
Key: msg.Path(r.typeName+"."+r.zone, "coredns")}
|
||||||
return []msg.Service{s}, nil
|
return []msg.Service{s}, nil
|
||||||
@@ -289,7 +293,7 @@ func (k *Kubernetes) Records(r recordRequest) ([]msg.Service, error) {
|
|||||||
return nil, errNsNotExposed
|
return nil, errNsNotExposed
|
||||||
}
|
}
|
||||||
|
|
||||||
services, pods, err := k.Get(r)
|
services, pods, err := k.get(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -405,8 +409,8 @@ func (k *Kubernetes) findPods(namespace, podname string) (pods []pod, err error)
|
|||||||
return pods, nil
|
return pods, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get retrieves matching data from the cache.
|
// get retrieves matching data from the cache.
|
||||||
func (k *Kubernetes) Get(r recordRequest) (services []service, pods []pod, err error) {
|
func (k *Kubernetes) get(r recordRequest) (services []service, pods []pod, err error) {
|
||||||
switch {
|
switch {
|
||||||
case r.typeName == "pod":
|
case r.typeName == "pod":
|
||||||
pods, err = k.findPods(r.namespace, r.service)
|
pods, err = k.findPods(r.namespace, r.service)
|
||||||
@@ -497,7 +501,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
|
|||||||
}
|
}
|
||||||
if service.Spec.ClusterIP == ip {
|
if service.Spec.ClusterIP == ip {
|
||||||
domain := service.Name + "." + service.Namespace + ".svc." + k.PrimaryZone()
|
domain := service.Name + "." + service.Namespace + ".svc." + k.PrimaryZone()
|
||||||
return []msg.Service{msg.Service{Host: domain}}
|
return []msg.Service{{Host: domain}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If no cluster ips match, search endpoints
|
// If no cluster ips match, search endpoints
|
||||||
@@ -513,7 +517,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
|
|||||||
for _, addr := range eps.Addresses {
|
for _, addr := range eps.Addresses {
|
||||||
if addr.IP == ip {
|
if addr.IP == ip {
|
||||||
domain := endpointHostname(addr) + "." + ep.ObjectMeta.Name + "." + ep.ObjectMeta.Namespace + ".svc." + k.PrimaryZone()
|
domain := endpointHostname(addr) + "." + ep.ObjectMeta.Name + "." + ep.ObjectMeta.Namespace + ".svc." + k.PrimaryZone()
|
||||||
return []msg.Service{msg.Service{Host: domain}}
|
return []msg.Service{{Host: domain}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ func TestSymbolContainsWildcard(t *testing.T) {
|
|||||||
|
|
||||||
func expectString(t *testing.T, function, qtype, query string, r *recordRequest, field, expected string) {
|
func expectString(t *testing.T, function, qtype, query string, r *recordRequest, field, expected string) {
|
||||||
ref := reflect.ValueOf(r)
|
ref := reflect.ValueOf(r)
|
||||||
ref_f := reflect.Indirect(ref).FieldByName(field)
|
refField := reflect.Indirect(ref).FieldByName(field)
|
||||||
got := ref_f.String()
|
got := refField.String()
|
||||||
if got != expected {
|
if got != expected {
|
||||||
t.Errorf("Expected %v(%v, \"%v\") to get %v == \"%v\". Instead got \"%v\".", function, query, qtype, field, expected, got)
|
t.Errorf("Expected %v(%v, \"%v\") to get %v == \"%v\". Instead got \"%v\".", function, query, qtype, field, expected, got)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"path/filepath"
|
||||||
"path/filepath"
|
"testing"
|
||||||
|
|
||||||
"github.com/miekg/coredns/middleware/test"
|
"github.com/miekg/coredns/middleware/test"
|
||||||
)
|
)
|
||||||
@@ -57,7 +57,7 @@ func TestNewTLSConfigFromArgs(t *testing.T) {
|
|||||||
t.Error("RootCAs should not be nil when one arg passed")
|
t.Error("RootCAs should not be nil when one arg passed")
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err = NewTLSConfigFromArgs(cert,key)
|
c, err = NewTLSConfigFromArgs(cert, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to create TLSConfig: %s", err)
|
t.Errorf("Failed to create TLSConfig: %s", err)
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ func TestNewTLSConfigFromArgs(t *testing.T) {
|
|||||||
if len(c.Certificates) != 1 {
|
if len(c.Certificates) != 1 {
|
||||||
t.Error("Certificates should have a single entry when two args passed")
|
t.Error("Certificates should have a single entry when two args passed")
|
||||||
}
|
}
|
||||||
args := []string{cert,key,ca}
|
args := []string{cert, key, ca}
|
||||||
c, err = NewTLSConfigFromArgs(args...)
|
c, err = NewTLSConfigFromArgs(args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to create TLSConfig: %s", err)
|
t.Errorf("Failed to create TLSConfig: %s", err)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/miekg/coredns/request"
|
"github.com/miekg/coredns/request"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
ot "github.com/opentracing/opentracing-go"
|
ot "github.com/opentracing/opentracing-go"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func setup(c *caddy.Controller) error {
|
|||||||
|
|
||||||
func traceParse(c *caddy.Controller) (*Trace, error) {
|
func traceParse(c *caddy.Controller) (*Trace, error) {
|
||||||
var (
|
var (
|
||||||
tr = &Trace{Endpoint: defEP, EndpointType: defEpType}
|
tr = &Trace{Endpoint: defEP, EndpointType: defEpType}
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -82,6 +82,6 @@ func normalizeEndpoint(epType, ep string) (string, error) {
|
|||||||
var traceOnce sync.Once
|
var traceOnce sync.Once
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defEP = "localhost:9411"
|
defEP = "localhost:9411"
|
||||||
defEpType = "zipkin"
|
defEpType = "zipkin"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func TestTraceParse(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
endpoint string
|
endpoint string
|
||||||
}{
|
}{
|
||||||
// oks
|
// oks
|
||||||
{`trace`, false, "http://localhost:9411/api/v1/spans"},
|
{`trace`, false, "http://localhost:9411/api/v1/spans"},
|
||||||
|
|||||||
@@ -5,22 +5,22 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/miekg/coredns/middleware"
|
"github.com/miekg/coredns/middleware"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
ot "github.com/opentracing/opentracing-go"
|
ot "github.com/opentracing/opentracing-go"
|
||||||
zipkin "github.com/openzipkin/zipkin-go-opentracing"
|
zipkin "github.com/openzipkin/zipkin-go-opentracing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Trace holds the tracer and endpoint info
|
// Trace holds the tracer and endpoint info
|
||||||
type Trace struct {
|
type Trace struct {
|
||||||
Next middleware.Handler
|
Next middleware.Handler
|
||||||
ServiceEndpoint string
|
ServiceEndpoint string
|
||||||
Endpoint string
|
Endpoint string
|
||||||
EndpointType string
|
EndpointType string
|
||||||
Tracer ot.Tracer
|
Tracer ot.Tracer
|
||||||
Once sync.Once
|
Once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnStartup sets up the tracer
|
// OnStartup sets up the tracer
|
||||||
@@ -52,10 +52,12 @@ func (t *Trace) setupZipkin() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trace) Name() (string) {
|
// Name implements the Handler interface.
|
||||||
|
func (t *Trace) Name() string {
|
||||||
return "trace"
|
return "trace"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServeDNS implements the middleware.Handle interface.
|
||||||
func (t *Trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (t *Trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
span := t.Tracer.StartSpan("servedns")
|
span := t.Tracer.StartSpan("servedns")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func TestEtcdStubAndProxyLookup(t *testing.T) {
|
|||||||
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
|
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
|
||||||
resp, err := p.Lookup(state, "example.com.", dns.TypeA)
|
resp, err := p.Lookup(state, "example.com.", dns.TypeA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expected to receive reply, but didn't", err)
|
t.Fatalf("Expected to receive reply, but didn't: %v", err)
|
||||||
}
|
}
|
||||||
if len(resp.Answer) == 0 {
|
if len(resp.Answer) == 0 {
|
||||||
t.Fatalf("Expected to at least one RR in the answer section, got none")
|
t.Fatalf("Expected to at least one RR in the answer section, got none")
|
||||||
@@ -79,7 +79,7 @@ func TestEtcdStubAndProxyLookup(t *testing.T) {
|
|||||||
t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
|
t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
|
||||||
}
|
}
|
||||||
if resp.Answer[0].(*dns.A).A.String() != "93.184.216.34" {
|
if resp.Answer[0].(*dns.A).A.String() != "93.184.216.34" {
|
||||||
t.Errorf("Expected 93.184.216.34, got: %d", resp.Answer[0].(*dns.A).A.String())
|
t.Errorf("Expected 93.184.216.34, got: %s", resp.Answer[0].(*dns.A).A.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user