cleanup: go vet and golint run (#736)
* cleanup: go vet and golint run Various cleanups trickered by go vet and golint. * Fix tests and lowercase all errors Lowercase all errors, some tests in kubernetes use errors from kubernetes which do start with a capital letter.
This commit is contained in:
parent
5c10eba31c
commit
e49ca86ce4
21 changed files with 64 additions and 62 deletions
|
@ -16,8 +16,8 @@ import (
|
||||||
"github.com/coredns/coredns/pb"
|
"github.com/coredns/coredns/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// servergRPC represents an instance of a DNS-over-gRPC server.
|
// ServergRPC represents an instance of a DNS-over-gRPC server.
|
||||||
type servergRPC struct {
|
type ServergRPC struct {
|
||||||
*Server
|
*Server
|
||||||
grpcServer *grpc.Server
|
grpcServer *grpc.Server
|
||||||
|
|
||||||
|
@ -25,18 +25,18 @@ type servergRPC struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServergRPC returns a new CoreDNS GRPC server and compiles all middleware in to it.
|
// NewServergRPC returns a new CoreDNS GRPC server and compiles all middleware in to it.
|
||||||
func NewServergRPC(addr string, group []*Config) (*servergRPC, error) {
|
func NewServergRPC(addr string, group []*Config) (*ServergRPC, error) {
|
||||||
|
|
||||||
s, err := NewServer(addr, group)
|
s, err := NewServer(addr, group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
gs := &servergRPC{Server: s}
|
gs := &ServergRPC{Server: s}
|
||||||
return gs, nil
|
return gs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve implements caddy.TCPServer interface.
|
// Serve implements caddy.TCPServer interface.
|
||||||
func (s *servergRPC) Serve(l net.Listener) error {
|
func (s *ServergRPC) Serve(l net.Listener) error {
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
s.listenAddr = l.Addr()
|
s.listenAddr = l.Addr()
|
||||||
s.m.Unlock()
|
s.m.Unlock()
|
||||||
|
@ -57,10 +57,10 @@ func (s *servergRPC) Serve(l net.Listener) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServePacket implements caddy.UDPServer interface.
|
// ServePacket implements caddy.UDPServer interface.
|
||||||
func (s *servergRPC) ServePacket(p net.PacketConn) error { return nil }
|
func (s *ServergRPC) ServePacket(p net.PacketConn) error { return nil }
|
||||||
|
|
||||||
// Listen implements caddy.TCPServer interface.
|
// Listen implements caddy.TCPServer interface.
|
||||||
func (s *servergRPC) Listen() (net.Listener, error) {
|
func (s *ServergRPC) Listen() (net.Listener, error) {
|
||||||
|
|
||||||
// The *tls* middleware must make sure that multiple conflicting
|
// The *tls* middleware must make sure that multiple conflicting
|
||||||
// TLS configuration return an error: it can only be specified once.
|
// TLS configuration return an error: it can only be specified once.
|
||||||
|
@ -88,11 +88,11 @@ func (s *servergRPC) Listen() (net.Listener, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenPacket implements caddy.UDPServer interface.
|
// ListenPacket implements caddy.UDPServer interface.
|
||||||
func (s *servergRPC) ListenPacket() (net.PacketConn, error) { return nil, nil }
|
func (s *ServergRPC) ListenPacket() (net.PacketConn, error) { return nil, nil }
|
||||||
|
|
||||||
// OnStartupComplete lists the sites served by this server
|
// OnStartupComplete lists the sites served by this server
|
||||||
// and any relevant information, assuming Quiet is false.
|
// and any relevant information, assuming Quiet is false.
|
||||||
func (s *servergRPC) OnStartupComplete() {
|
func (s *ServergRPC) OnStartupComplete() {
|
||||||
if Quiet {
|
if Quiet {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func (s *servergRPC) OnStartupComplete() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *servergRPC) Stop() (err error) {
|
func (s *ServergRPC) Stop() (err error) {
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
defer s.m.Unlock()
|
defer s.m.Unlock()
|
||||||
if s.grpcServer != nil {
|
if s.grpcServer != nil {
|
||||||
|
@ -114,7 +114,7 @@ func (s *servergRPC) Stop() (err error) {
|
||||||
// Query is the main entry-point into the gRPC server. From here we call ServeDNS like
|
// Query is the main entry-point into the gRPC server. From here we call ServeDNS like
|
||||||
// any normal server. We use a custom responseWriter to pick up the bytes we need to write
|
// any normal server. We use a custom responseWriter to pick up the bytes we need to write
|
||||||
// back to the client as a protobuf.
|
// back to the client as a protobuf.
|
||||||
func (s *servergRPC) Query(ctx context.Context, in *pb.DnsPacket) (*pb.DnsPacket, error) {
|
func (s *ServergRPC) Query(ctx context.Context, in *pb.DnsPacket) (*pb.DnsPacket, error) {
|
||||||
msg := new(dns.Msg)
|
msg := new(dns.Msg)
|
||||||
err := msg.Unpack(in.Msg)
|
err := msg.Unpack(in.Msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,7 +144,7 @@ func (s *servergRPC) Query(ctx context.Context, in *pb.DnsPacket) (*pb.DnsPacket
|
||||||
return &pb.DnsPacket{Msg: packed}, nil
|
return &pb.DnsPacket{Msg: packed}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *servergRPC) Shutdown() error {
|
func (s *ServergRPC) Shutdown() error {
|
||||||
if s.grpcServer != nil {
|
if s.grpcServer != nil {
|
||||||
s.grpcServer.Stop()
|
s.grpcServer.Stop()
|
||||||
}
|
}
|
||||||
|
|
3
middleware/cache/freq/freq.go
vendored
3
middleware/cache/freq/freq.go
vendored
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Freq tracks the frequence of things.
|
||||||
type Freq struct {
|
type Freq struct {
|
||||||
// Last time we saw a query for this element.
|
// Last time we saw a query for this element.
|
||||||
last time.Time
|
last time.Time
|
||||||
|
@ -21,7 +22,7 @@ func New(t time.Time) *Freq {
|
||||||
return &Freq{last: t, hits: 0}
|
return &Freq{last: t, hits: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates updates the number of hits. Last time seen will be set to now.
|
// Update updates the number of hits. Last time seen will be set to now.
|
||||||
// If the last time we've seen this entity is within now - d, we increment hits, otherwise
|
// If the last time we've seen this entity is within now - d, we increment hits, otherwise
|
||||||
// we reset hits to 1. It returns the number of hits.
|
// we reset hits to 1. It returns the number of hits.
|
||||||
func (f *Freq) Update(d time.Duration, now time.Time) int {
|
func (f *Freq) Update(d time.Duration, now time.Time) int {
|
||||||
|
|
|
@ -43,7 +43,7 @@ func TestDebug(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cfg.Debug != test.expectedDebug {
|
if cfg.Debug != test.expectedDebug {
|
||||||
t.Fatalf("Test %d: Expected debug to be: %t, but got: %t, input: %s", i, test.expectedDebug, test.input)
|
t.Fatalf("Test %d: Expected debug to be: %t, but got: %t, input: %s", i, test.expectedDebug, cfg.Debug, test.input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ func notifyAddr(c *dns.Client, m *dns.Msg, s string) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Notify for zone %q was not accepted by %q: %q", m.Question[0].Name, s, err)
|
return fmt.Errorf("notify for zone %q was not accepted by %q: %q", m.Question[0].Name, s, err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Notify for zone %q was not accepted by %q: rcode was %q", m.Question[0].Name, s, rcode.ToString(code))
|
return fmt.Errorf("notify for zone %q was not accepted by %q: rcode was %q", m.Question[0].Name, s, rcode.ToString(code))
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (z *Zone) Reload() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SOASerialIfDefind returns the SOA's serial if the zone has a SOA record in the Apex, or
|
// SOASerialIfDefined returns the SOA's serial if the zone has a SOA record in the Apex, or
|
||||||
// -1 otherwise.
|
// -1 otherwise.
|
||||||
func (z *Zone) SOASerialIfDefined() int64 {
|
func (z *Zone) SOASerialIfDefined() int64 {
|
||||||
z.reloadMu.Lock()
|
z.reloadMu.Lock()
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/coredns/coredns/middleware/etcd/msg"
|
"github.com/coredns/coredns/middleware/etcd/msg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Federation holds TODO(...).
|
||||||
type Federation struct {
|
type Federation struct {
|
||||||
name string
|
name string
|
||||||
zone string
|
zone string
|
||||||
|
@ -26,8 +27,8 @@ const (
|
||||||
//
|
//
|
||||||
// But importing above breaks coredns with flag collision of 'log_dir'
|
// But importing above breaks coredns with flag collision of 'log_dir'
|
||||||
|
|
||||||
LabelAvailabilityZone = "failure-domain.beta.kubernetes.io/zone"
|
labelAvailabilityZone = "failure-domain.beta.kubernetes.io/zone"
|
||||||
LabelRegion = "failure-domain.beta.kubernetes.io/region"
|
labelRegion = "failure-domain.beta.kubernetes.io/region"
|
||||||
)
|
)
|
||||||
|
|
||||||
// stripFederation removes the federation segment from the segment list, if it
|
// stripFederation removes the federation segment from the segment list, if it
|
||||||
|
@ -66,12 +67,12 @@ func (k *Kubernetes) federationCNAMERecord(r recordRequest) msg.Service {
|
||||||
if r.endpoint == "" {
|
if r.endpoint == "" {
|
||||||
return msg.Service{
|
return msg.Service{
|
||||||
Key: strings.Join([]string{msg.Path(r.zone, "coredns"), r.typeName, r.federation, r.namespace, r.service}, "/"),
|
Key: strings.Join([]string{msg.Path(r.zone, "coredns"), r.typeName, r.federation, r.namespace, r.service}, "/"),
|
||||||
Host: strings.Join([]string{r.service, r.namespace, r.federation, r.typeName, node.Labels[LabelAvailabilityZone], node.Labels[LabelRegion], f.zone}, "."),
|
Host: strings.Join([]string{r.service, r.namespace, r.federation, r.typeName, node.Labels[labelAvailabilityZone], node.Labels[labelRegion], f.zone}, "."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return msg.Service{
|
return msg.Service{
|
||||||
Key: strings.Join([]string{msg.Path(r.zone, "coredns"), r.typeName, r.federation, r.namespace, r.service, r.endpoint}, "/"),
|
Key: strings.Join([]string{msg.Path(r.zone, "coredns"), r.typeName, r.federation, r.namespace, r.service, r.endpoint}, "/"),
|
||||||
Host: strings.Join([]string{r.endpoint, r.service, r.namespace, r.federation, r.typeName, node.Labels[LabelAvailabilityZone], node.Labels[LabelRegion], f.zone}, "."),
|
Host: strings.Join([]string{r.endpoint, r.service, r.namespace, r.federation, r.typeName, node.Labels[labelAvailabilityZone], node.Labels[labelRegion], f.zone}, "."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,8 @@ func (apiConnFedTest) GetNodeByName(name string) (api.Node, error) {
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "test.node.foo.bar",
|
Name: "test.node.foo.bar",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
LabelRegion: "fd-r",
|
labelRegion: "fd-r",
|
||||||
LabelAvailabilityZone: "fd-az",
|
labelAvailabilityZone: "fd-az",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -230,7 +230,7 @@ func (k *Kubernetes) InitKubeCache() (err error) {
|
||||||
|
|
||||||
kubeClient, err := kubernetes.NewForConfig(config)
|
kubeClient, err := kubernetes.NewForConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create kubernetes notification controller: %v", err)
|
return fmt.Errorf("failed to create kubernetes notification controller: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if k.LabelSelector != nil {
|
if k.LabelSelector != nil {
|
||||||
|
@ -238,7 +238,7 @@ func (k *Kubernetes) InitKubeCache() (err error) {
|
||||||
selector, err = unversionedapi.LabelSelectorAsSelector(k.LabelSelector)
|
selector, err = unversionedapi.LabelSelectorAsSelector(k.LabelSelector)
|
||||||
k.Selector = &selector
|
k.Selector = &selector
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to create Selector for LabelSelector '%s'.Error was: %s", k.LabelSelector, err)
|
return fmt.Errorf("unable to create Selector for LabelSelector '%s'.Error was: %s", k.LabelSelector, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -431,8 +431,8 @@ func (APIConnServiceTest) GetNodeByName(name string) (api.Node, error) {
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "test.node.foo.bar",
|
Name: "test.node.foo.bar",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
LabelRegion: "fd-r",
|
labelRegion: "fd-r",
|
||||||
LabelAvailabilityZone: "fd-az",
|
labelAvailabilityZone: "fd-az",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -96,7 +96,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
|
||||||
for _, cidrStr := range args {
|
for _, cidrStr := range args {
|
||||||
_, cidr, err := net.ParseCIDR(cidrStr)
|
_, cidr, err := net.ParseCIDR(cidrStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Invalid cidr: " + cidrStr)
|
return nil, fmt.Errorf("invalid cidr: %s", cidrStr)
|
||||||
}
|
}
|
||||||
k8s.ReverseCidrs = append(k8s.ReverseCidrs, *cidr)
|
k8s.ReverseCidrs = append(k8s.ReverseCidrs, *cidr)
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
|
||||||
case PodModeDisabled, PodModeInsecure, PodModeVerified:
|
case PodModeDisabled, PodModeInsecure, PodModeVerified:
|
||||||
k8s.PodMode = args[0]
|
k8s.PodMode = args[0]
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Value for pods must be one of: disabled, verified, insecure")
|
return nil, fmt.Errorf("wrong value for pods: %s, must be one of: disabled, verified, insecure", args[0])
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
rp, err := time.ParseDuration(args[0])
|
rp, err := time.ParseDuration(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to parse resync duration value. Value provided was '%v'. Example valid values: '15s', '5m', '1h'. Error was: %v", args[0], err)
|
return nil, fmt.Errorf("unable to parse resync duration value: '%v': %v", args[0], err)
|
||||||
}
|
}
|
||||||
k8s.ResyncPeriod = rp
|
k8s.ResyncPeriod = rp
|
||||||
continue
|
continue
|
||||||
|
@ -154,7 +154,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
|
||||||
labelSelectorString := strings.Join(args, " ")
|
labelSelectorString := strings.Join(args, " ")
|
||||||
ls, err := unversionedapi.ParseToLabelSelector(labelSelectorString)
|
ls, err := unversionedapi.ParseToLabelSelector(labelSelectorString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to parse label selector. Value provided was '%v'. Error was: %v", labelSelectorString, err)
|
return nil, fmt.Errorf("unable to parse label selector value: '%v': %v", labelSelectorString, err)
|
||||||
}
|
}
|
||||||
k8s.LabelSelector = ls
|
k8s.LabelSelector = ls
|
||||||
continue
|
continue
|
||||||
|
@ -185,17 +185,15 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
|
||||||
zone: args[1],
|
zone: args[1],
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("Incorrect number of arguments for federation. Got %v, expect 2.", len(args))
|
|
||||||
}
|
}
|
||||||
return nil, c.ArgErr()
|
return nil, fmt.Errorf("incorrect number of arguments for federation, got %v, expected 2", len(args))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return k8s, nil
|
return k8s, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, errors.New("Kubernetes setup called without keyword 'kubernetes' in Corefile")
|
return nil, errors.New("kubernetes setup called without keyword 'kubernetes' in Corefile")
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -223,7 +223,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
"no kubernetes keyword",
|
"no kubernetes keyword",
|
||||||
"",
|
"",
|
||||||
true,
|
true,
|
||||||
"Kubernetes setup called without keyword 'kubernetes' in Corefile",
|
"kubernetes setup called without keyword 'kubernetes' in Corefile",
|
||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
defaultResyncPeriod,
|
defaultResyncPeriod,
|
||||||
|
@ -255,7 +255,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
endpoint
|
endpoint
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Wrong argument count or unexpected line ending after 'endpoint'",
|
"rong argument count or unexpected line ending",
|
||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
defaultResyncPeriod,
|
defaultResyncPeriod,
|
||||||
|
@ -272,7 +272,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
namespaces
|
namespaces
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Parse error: Wrong argument count or unexpected line ending after 'namespaces'",
|
"rong argument count or unexpected line ending",
|
||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
defaultResyncPeriod,
|
defaultResyncPeriod,
|
||||||
|
@ -289,7 +289,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
resyncperiod
|
resyncperiod
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Wrong argument count or unexpected line ending after 'resyncperiod'",
|
"rong argument count or unexpected line ending",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
0 * time.Minute,
|
0 * time.Minute,
|
||||||
|
@ -306,7 +306,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
resyncperiod 15
|
resyncperiod 15
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Unable to parse resync duration value. Value provided was ",
|
"unable to parse resync duration value",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
0 * time.Second,
|
0 * time.Second,
|
||||||
|
@ -323,7 +323,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
resyncperiod abc
|
resyncperiod abc
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Unable to parse resync duration value. Value provided was ",
|
"unable to parse resync duration value",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
0 * time.Second,
|
0 * time.Second,
|
||||||
|
@ -340,7 +340,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
labels
|
labels
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Wrong argument count or unexpected line ending after 'labels'",
|
"rong argument count or unexpected line ending",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
0 * time.Second,
|
0 * time.Second,
|
||||||
|
@ -357,7 +357,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
labels environment in (production, qa
|
labels environment in (production, qa
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Unable to parse label selector. Value provided was",
|
"unable to parse label selector",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
0 * time.Second,
|
0 * time.Second,
|
||||||
|
@ -429,7 +429,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
pods giant_seed
|
pods giant_seed
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Value for pods must be one of: disabled, verified, insecure",
|
"rong value for pods",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
defaultResyncPeriod,
|
defaultResyncPeriod,
|
||||||
|
@ -460,12 +460,12 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
},
|
},
|
||||||
// cidrs ok
|
// cidrs ok
|
||||||
{
|
{
|
||||||
"Invalid cidr: hard",
|
"invalid cidr: hard",
|
||||||
`kubernetes coredns.local {
|
`kubernetes coredns.local {
|
||||||
cidrs hard dry
|
cidrs hard dry
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Invalid cidr: hard",
|
"invalid cidr: hard",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
defaultResyncPeriod,
|
defaultResyncPeriod,
|
||||||
|
@ -483,7 +483,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
fallthrough junk
|
fallthrough junk
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
"Wrong argument count",
|
"rong argument count",
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
defaultResyncPeriod,
|
defaultResyncPeriod,
|
||||||
|
@ -559,7 +559,7 @@ func TestKubernetesParse(t *testing.T) {
|
||||||
federation starship
|
federation starship
|
||||||
}`,
|
}`,
|
||||||
true,
|
true,
|
||||||
`Incorrect number of arguments for federation. Got 1, expect 2.`,
|
`incorrect number of arguments for federation`,
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
defaultResyncPeriod,
|
defaultResyncPeriod,
|
||||||
|
|
|
@ -108,7 +108,7 @@ func Typify(m *dns.Msg, t time.Time) (Type, *dns.OPT) {
|
||||||
return NameError, opt
|
return NameError, opt
|
||||||
}
|
}
|
||||||
|
|
||||||
if ns > 0 && ns > 0 && m.Rcode == dns.RcodeSuccess {
|
if ns > 0 && m.Rcode == dns.RcodeSuccess {
|
||||||
return Delegation, opt
|
return Delegation, opt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ func NewTLSConfigFromArgs(args ...string) (*tls.Config, error) {
|
||||||
// Client cert, use specified CA
|
// Client cert, use specified CA
|
||||||
c, err = NewTLSConfig(args[0], args[1], args[2])
|
c, err = NewTLSConfig(args[0], args[1], args[2])
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("Maximum of three arguments allowed for TLS config, found %d", len(args))
|
err = fmt.Errorf("maximum of three arguments allowed for TLS config, found %d", len(args))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -64,7 +64,7 @@ func NewTLSConfigFromArgs(args ...string) (*tls.Config, error) {
|
||||||
func NewTLSConfig(certPath, keyPath, caPath string) (*tls.Config, error) {
|
func NewTLSConfig(certPath, keyPath, caPath string) (*tls.Config, error) {
|
||||||
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
|
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Could not load TLS cert: %s", err)
|
return nil, fmt.Errorf("could not load TLS cert: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
roots, err := loadRoots(caPath)
|
roots, err := loadRoots(caPath)
|
||||||
|
@ -94,11 +94,11 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
|
||||||
roots := x509.NewCertPool()
|
roots := x509.NewCertPool()
|
||||||
pem, err := ioutil.ReadFile(caPath)
|
pem, err := ioutil.ReadFile(caPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error reading %s: %s", caPath, err)
|
return nil, fmt.Errorf("error reading %s: %s", caPath, err)
|
||||||
}
|
}
|
||||||
ok := roots.AppendCertsFromPEM(pem)
|
ok := roots.AppendCertsFromPEM(pem)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("Could not read root certs: %s", err)
|
return nil, fmt.Errorf("could not read root certs: %s", err)
|
||||||
}
|
}
|
||||||
return roots, nil
|
return roots, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ type dnsEx struct {
|
||||||
Options
|
Options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Options define the options understood by dns.Exchange.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
ForceTCP bool // If true use TCP for upstream no matter what
|
ForceTCP bool // If true use TCP for upstream no matter what
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewLookup(hosts []string) Proxy {
|
||||||
return NewLookupWithOption(hosts, Options{})
|
return NewLookupWithOption(hosts, Options{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLookupWithForcedProto process creates a simple round robin forward with potentially forced proto for upstream.
|
// NewLookupWithOption process creates a simple round robin forward with potentially forced proto for upstream.
|
||||||
func NewLookupWithOption(hosts []string, opts Options) Proxy {
|
func NewLookupWithOption(hosts []string, opts Options) Proxy {
|
||||||
p := Proxy{Next: nil}
|
p := Proxy{Next: nil}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func operatorError(operator string) error {
|
func operatorError(operator string) error {
|
||||||
return fmt.Errorf("Invalid operator %v", operator)
|
return fmt.Errorf("invalid operator %v", operator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReplacer(r *dns.Msg) replacer.Replacer {
|
func newReplacer(r *dns.Msg) replacer.Replacer {
|
||||||
|
|
|
@ -94,7 +94,7 @@ func (rule *edns0LocalRule) Rewrite(r *dns.Msg) Result {
|
||||||
// newEdns0Rule creates an EDNS0 rule of the appropriate type based on the args
|
// newEdns0Rule creates an EDNS0 rule of the appropriate type based on the args
|
||||||
func newEdns0Rule(args ...string) (Rule, error) {
|
func newEdns0Rule(args ...string) (Rule, error) {
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
return nil, fmt.Errorf("Too few arguments for an EDNS0 rule")
|
return nil, fmt.Errorf("too few arguments for an EDNS0 rule")
|
||||||
}
|
}
|
||||||
|
|
||||||
ruleType := strings.ToLower(args[0])
|
ruleType := strings.ToLower(args[0])
|
||||||
|
|
|
@ -64,7 +64,7 @@ type Rule interface {
|
||||||
|
|
||||||
func newRule(args ...string) (Rule, error) {
|
func newRule(args ...string) (Rule, error) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return nil, fmt.Errorf("No rule type specified for rewrite")
|
return nil, fmt.Errorf("no rule type specified for rewrite")
|
||||||
}
|
}
|
||||||
|
|
||||||
ruleType := strings.ToLower(args[0])
|
ruleType := strings.ToLower(args[0])
|
||||||
|
|
|
@ -7,11 +7,12 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/coredns/coredns/middleware"
|
"github.com/coredns/coredns/middleware"
|
||||||
|
// Plugin the trace package.
|
||||||
_ "github.com/coredns/coredns/middleware/pkg/trace"
|
_ "github.com/coredns/coredns/middleware/pkg/trace"
|
||||||
|
|
||||||
"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"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ func (t *trace) OnStartup() error {
|
||||||
case "zipkin":
|
case "zipkin":
|
||||||
err = t.setupZipkin()
|
err = t.setupZipkin()
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("Unknown endpoint type: %s", t.EndpointType)
|
err = fmt.Errorf("unknown endpoint type: %s", t.EndpointType)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -52,10 +52,10 @@ func TestGrpc(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Rcode != dns.RcodeSuccess {
|
if d.Rcode != dns.RcodeSuccess {
|
||||||
t.Errorf("Expected success but got %s", d.Rcode)
|
t.Errorf("Expected success but got %d", d.Rcode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(d.Extra) != 2 {
|
if len(d.Extra) != 2 {
|
||||||
t.Errorf("Expected 2 RRs in additional section, but got %s", len(d.Extra))
|
t.Errorf("Expected 2 RRs in additional section, but got %d", len(d.Extra))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,6 @@ func send(t *testing.T, server string) {
|
||||||
t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode])
|
t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode])
|
||||||
}
|
}
|
||||||
if len(r.Extra) != 2 {
|
if len(r.Extra) != 2 {
|
||||||
t.Fatalf("Expected 2 RRs in additional, got %s", len(r.Extra))
|
t.Fatalf("Expected 2 RRs in additional, got %d", len(r.Extra))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue