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:
Miek Gieben
2017-06-14 09:37:10 -07:00
committed by GitHub
parent 5c10eba31c
commit e49ca86ce4
21 changed files with 64 additions and 62 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
)
// Freq tracks the frequence of things.
type Freq struct {
// Last time we saw a query for this element.
last time.Time
@@ -21,7 +22,7 @@ func New(t time.Time) *Freq {
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
// we reset hits to 1. It returns the number of hits.
func (f *Freq) Update(d time.Duration, now time.Time) int {

View File

@@ -43,7 +43,7 @@ func TestDebug(t *testing.T) {
}
}
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)
}
}
}

View File

@@ -71,7 +71,7 @@ func notifyAddr(c *dns.Client, m *dns.Msg, s string) (err error) {
}
}
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))
}

View File

@@ -60,7 +60,7 @@ func (z *Zone) Reload() error {
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.
func (z *Zone) SOASerialIfDefined() int64 {
z.reloadMu.Lock()

View File

@@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/middleware/etcd/msg"
)
// Federation holds TODO(...).
type Federation struct {
name string
zone string
@@ -26,8 +27,8 @@ const (
//
// But importing above breaks coredns with flag collision of 'log_dir'
LabelAvailabilityZone = "failure-domain.beta.kubernetes.io/zone"
LabelRegion = "failure-domain.beta.kubernetes.io/region"
labelAvailabilityZone = "failure-domain.beta.kubernetes.io/zone"
labelRegion = "failure-domain.beta.kubernetes.io/region"
)
// 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 == "" {
return msg.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{
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}, "."),
}
}

View File

@@ -66,8 +66,8 @@ func (apiConnFedTest) GetNodeByName(name string) (api.Node, error) {
ObjectMeta: api.ObjectMeta{
Name: "test.node.foo.bar",
Labels: map[string]string{
LabelRegion: "fd-r",
LabelAvailabilityZone: "fd-az",
labelRegion: "fd-r",
labelAvailabilityZone: "fd-az",
},
},
}, nil

View File

@@ -230,7 +230,7 @@ func (k *Kubernetes) InitKubeCache() (err error) {
kubeClient, err := kubernetes.NewForConfig(config)
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 {
@@ -238,7 +238,7 @@ func (k *Kubernetes) InitKubeCache() (err error) {
selector, err = unversionedapi.LabelSelectorAsSelector(k.LabelSelector)
k.Selector = &selector
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)
}
}

View File

@@ -431,8 +431,8 @@ func (APIConnServiceTest) GetNodeByName(name string) (api.Node, error) {
ObjectMeta: api.ObjectMeta{
Name: "test.node.foo.bar",
Labels: map[string]string{
LabelRegion: "fd-r",
LabelAvailabilityZone: "fd-az",
labelRegion: "fd-r",
labelAvailabilityZone: "fd-az",
},
},
}, nil

View File

@@ -96,7 +96,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
for _, cidrStr := range args {
_, cidr, err := net.ParseCIDR(cidrStr)
if err != nil {
return nil, errors.New("Invalid cidr: " + cidrStr)
return nil, fmt.Errorf("invalid cidr: %s", cidrStr)
}
k8s.ReverseCidrs = append(k8s.ReverseCidrs, *cidr)
@@ -111,7 +111,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
case PodModeDisabled, PodModeInsecure, PodModeVerified:
k8s.PodMode = args[0]
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
}
@@ -142,7 +142,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
if len(args) > 0 {
rp, err := time.ParseDuration(args[0])
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
continue
@@ -154,7 +154,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
labelSelectorString := strings.Join(args, " ")
ls, err := unversionedapi.ParseToLabelSelector(labelSelectorString)
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
continue
@@ -185,17 +185,15 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
zone: args[1],
})
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 nil, errors.New("Kubernetes setup called without keyword 'kubernetes' in Corefile")
return nil, errors.New("kubernetes setup called without keyword 'kubernetes' in Corefile")
}
const (

View File

@@ -223,7 +223,7 @@ func TestKubernetesParse(t *testing.T) {
"no kubernetes keyword",
"",
true,
"Kubernetes setup called without keyword 'kubernetes' in Corefile",
"kubernetes setup called without keyword 'kubernetes' in Corefile",
-1,
-1,
defaultResyncPeriod,
@@ -255,7 +255,7 @@ func TestKubernetesParse(t *testing.T) {
endpoint
}`,
true,
"Wrong argument count or unexpected line ending after 'endpoint'",
"rong argument count or unexpected line ending",
-1,
-1,
defaultResyncPeriod,
@@ -272,7 +272,7 @@ func TestKubernetesParse(t *testing.T) {
namespaces
}`,
true,
"Parse error: Wrong argument count or unexpected line ending after 'namespaces'",
"rong argument count or unexpected line ending",
-1,
-1,
defaultResyncPeriod,
@@ -289,7 +289,7 @@ func TestKubernetesParse(t *testing.T) {
resyncperiod
}`,
true,
"Wrong argument count or unexpected line ending after 'resyncperiod'",
"rong argument count or unexpected line ending",
-1,
0,
0 * time.Minute,
@@ -306,7 +306,7 @@ func TestKubernetesParse(t *testing.T) {
resyncperiod 15
}`,
true,
"Unable to parse resync duration value. Value provided was ",
"unable to parse resync duration value",
-1,
0,
0 * time.Second,
@@ -323,7 +323,7 @@ func TestKubernetesParse(t *testing.T) {
resyncperiod abc
}`,
true,
"Unable to parse resync duration value. Value provided was ",
"unable to parse resync duration value",
-1,
0,
0 * time.Second,
@@ -340,7 +340,7 @@ func TestKubernetesParse(t *testing.T) {
labels
}`,
true,
"Wrong argument count or unexpected line ending after 'labels'",
"rong argument count or unexpected line ending",
-1,
0,
0 * time.Second,
@@ -357,7 +357,7 @@ func TestKubernetesParse(t *testing.T) {
labels environment in (production, qa
}`,
true,
"Unable to parse label selector. Value provided was",
"unable to parse label selector",
-1,
0,
0 * time.Second,
@@ -429,7 +429,7 @@ func TestKubernetesParse(t *testing.T) {
pods giant_seed
}`,
true,
"Value for pods must be one of: disabled, verified, insecure",
"rong value for pods",
-1,
0,
defaultResyncPeriod,
@@ -460,12 +460,12 @@ func TestKubernetesParse(t *testing.T) {
},
// cidrs ok
{
"Invalid cidr: hard",
"invalid cidr: hard",
`kubernetes coredns.local {
cidrs hard dry
}`,
true,
"Invalid cidr: hard",
"invalid cidr: hard",
-1,
0,
defaultResyncPeriod,
@@ -483,7 +483,7 @@ func TestKubernetesParse(t *testing.T) {
fallthrough junk
}`,
true,
"Wrong argument count",
"rong argument count",
-1,
0,
defaultResyncPeriod,
@@ -559,7 +559,7 @@ func TestKubernetesParse(t *testing.T) {
federation starship
}`,
true,
`Incorrect number of arguments for federation. Got 1, expect 2.`,
`incorrect number of arguments for federation`,
-1,
0,
defaultResyncPeriod,

View File

@@ -108,7 +108,7 @@ func Typify(m *dns.Msg, t time.Time) (Type, *dns.OPT) {
return NameError, opt
}
if ns > 0 && ns > 0 && m.Rcode == dns.RcodeSuccess {
if ns > 0 && m.Rcode == dns.RcodeSuccess {
return Delegation, opt
}

View File

@@ -50,7 +50,7 @@ func NewTLSConfigFromArgs(args ...string) (*tls.Config, error) {
// Client cert, use specified CA
c, err = NewTLSConfig(args[0], args[1], args[2])
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 {
return nil, err
@@ -64,7 +64,7 @@ func NewTLSConfigFromArgs(args ...string) (*tls.Config, error) {
func NewTLSConfig(certPath, keyPath, caPath string) (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
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)
@@ -94,11 +94,11 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
roots := x509.NewCertPool()
pem, err := ioutil.ReadFile(caPath)
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)
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
}

View File

@@ -15,6 +15,7 @@ type dnsEx struct {
Options
}
// Options define the options understood by dns.Exchange.
type Options struct {
ForceTCP bool // If true use TCP for upstream no matter what
}

View File

@@ -17,7 +17,7 @@ func NewLookup(hosts []string) Proxy {
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 {
p := Proxy{Next: nil}

View File

@@ -23,7 +23,7 @@ const (
)
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 {

View File

@@ -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
func newEdns0Rule(args ...string) (Rule, error) {
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])

View File

@@ -64,7 +64,7 @@ type Rule interface {
func newRule(args ...string) (Rule, error) {
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])

View File

@@ -7,11 +7,12 @@ import (
"sync/atomic"
"github.com/coredns/coredns/middleware"
// Plugin the trace package.
_ "github.com/coredns/coredns/middleware/pkg/trace"
"github.com/miekg/dns"
ot "github.com/opentracing/opentracing-go"
zipkin "github.com/openzipkin/zipkin-go-opentracing"
"golang.org/x/net/context"
)
@@ -40,7 +41,7 @@ func (t *trace) OnStartup() error {
case "zipkin":
err = t.setupZipkin()
default:
err = fmt.Errorf("Unknown endpoint type: %s", t.EndpointType)
err = fmt.Errorf("unknown endpoint type: %s", t.EndpointType)
}
})
return err