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
|
@ -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}, "."),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue