From befe8799dbfa062d78948baf4aded19e701aea4e Mon Sep 17 00:00:00 2001 From: Tom Denham Date: Wed, 29 Mar 2017 15:12:22 -0700 Subject: [PATCH] Fix various little problems found by gometalinter --- backend/alloc/alloc.go | 2 +- backend/awsvpc/awsvpc.go | 3 +++ backend/gce/gce.go | 2 +- backend/hostgw/hostgw.go | 2 +- backend/manager.go | 6 +++--- backend/udp/network.go | 6 +----- backend/vxlan/device.go | 2 +- subnet/config.go | 6 ++---- subnet/etcdv2/registry.go | 2 +- subnet/etcdv2/registry_test.go | 8 +++----- subnet/etcdv2/subnet_test.go | 6 +++--- subnet/kube/kube.go | 1 - subnet/subnet.go | 6 +++--- subnet/watch.go | 6 +++--- 14 files changed, 26 insertions(+), 32 deletions(-) diff --git a/backend/alloc/alloc.go b/backend/alloc/alloc.go index a9278994f7..ab814a1fbc 100644 --- a/backend/alloc/alloc.go +++ b/backend/alloc/alloc.go @@ -17,10 +17,10 @@ package alloc import ( "fmt" - "golang.org/x/net/context" "github.com/coreos/flannel/backend" "github.com/coreos/flannel/pkg/ip" "github.com/coreos/flannel/subnet" + "golang.org/x/net/context" ) func init() { diff --git a/backend/awsvpc/awsvpc.go b/backend/awsvpc/awsvpc.go index 8043b55130..cafcc816ee 100644 --- a/backend/awsvpc/awsvpc.go +++ b/backend/awsvpc/awsvpc.go @@ -116,6 +116,9 @@ func (be *AwsVpcBackend) RegisterNetwork(ctx context.Context, network string, co } networkConfig, err := be.sm.GetNetworkConfig(ctx, network) + if err != nil { + log.Errorf("Error fetching network config: %v", err) + } err = be.cleanupBlackholeRoutes(cfg.RouteTableID, networkConfig.Network, ec2c) if err != nil { diff --git a/backend/gce/gce.go b/backend/gce/gce.go index bd1d740a6f..4e4fbf3d90 100644 --- a/backend/gce/gce.go +++ b/backend/gce/gce.go @@ -119,7 +119,7 @@ func (g *GCEBackend) RegisterNetwork(ctx context.Context, network string, config err = g.api.pollOperationStatus(operation.Name) if err != nil { - return nil, fmt.Errorf("insert operaiton failed: ", err) + return nil, fmt.Errorf("insert operaiton failed: %v", err) } } diff --git a/backend/hostgw/hostgw.go b/backend/hostgw/hostgw.go index 8e5d5d20f8..13bd6495f5 100644 --- a/backend/hostgw/hostgw.go +++ b/backend/hostgw/hostgw.go @@ -17,10 +17,10 @@ package hostgw import ( "fmt" - "golang.org/x/net/context" "github.com/coreos/flannel/backend" "github.com/coreos/flannel/pkg/ip" "github.com/coreos/flannel/subnet" + "golang.org/x/net/context" ) func init() { diff --git a/backend/manager.go b/backend/manager.go index 23206aa174..0a4d76aa73 100644 --- a/backend/manager.go +++ b/backend/manager.go @@ -24,7 +24,7 @@ import ( "github.com/coreos/flannel/subnet" ) -var backendCtors map[string]BackendCtor = make(map[string]BackendCtor) +var constructors = make(map[string]BackendCtor) type Manager interface { GetBackend(backendType string) (Backend, error) @@ -60,7 +60,7 @@ func (bm *manager) GetBackend(backendType string) (Backend, error) { } // first request, need to create and run it - befunc, ok := backendCtors[betype] + befunc, ok := constructors[betype] if !ok { return nil, fmt.Errorf("unknown backend type: %v", betype) } @@ -95,5 +95,5 @@ func (bm *manager) Wait() { } func Register(name string, ctor BackendCtor) { - backendCtors[name] = ctor + constructors[name] = ctor } diff --git a/backend/udp/network.go b/backend/udp/network.go index bf43dc9d59..98f9341102 100644 --- a/backend/udp/network.go +++ b/backend/udp/network.go @@ -142,11 +142,7 @@ func (n *network) initTun() error { } err = configureIface(tunName, n.tunNet, n.MTU()) - if err != nil { - return err - } - - return nil + return err } func configureIface(ifname string, ipn ip.IP4Net, mtu int) error { diff --git a/backend/vxlan/device.go b/backend/vxlan/device.go index c8725afd58..5bd4fd875b 100644 --- a/backend/vxlan/device.go +++ b/backend/vxlan/device.go @@ -243,7 +243,7 @@ func (dev *vxlanDevice) processNeighMsg(msg syscall.NetlinkMessage, misses chan return } - if int(neigh.LinkIndex) != dev.link.Index { + if neigh.LinkIndex != dev.link.Index { return } diff --git a/subnet/config.go b/subnet/config.go index 547f944b53..3dce7a04ff 100644 --- a/subnet/config.go +++ b/subnet/config.go @@ -38,10 +38,8 @@ func parseBackendType(be json.RawMessage) (string, error) { if len(be) == 0 { return "udp", nil - } else { - if err := json.Unmarshal(be, &bt); err != nil { - return "", fmt.Errorf("error decoding Backend property of config: %v", err) - } + } else if err := json.Unmarshal(be, &bt); err != nil { + return "", fmt.Errorf("error decoding Backend property of config: %v", err) } return bt.Type, nil diff --git a/subnet/etcdv2/registry.go b/subnet/etcdv2/registry.go index a7066b19ba..18fa40b4f5 100644 --- a/subnet/etcdv2/registry.go +++ b/subnet/etcdv2/registry.go @@ -353,7 +353,7 @@ func (esr *etcdSubnetRegistry) parseNetworkWatchResponse(resp *etcd.Response) (E return Event{}, index, errTryAgain } - evt := Event{} + var evt Event switch resp.Action { case "delete": diff --git a/subnet/etcdv2/registry_test.go b/subnet/etcdv2/registry_test.go index 3689b042f8..47932a69d4 100644 --- a/subnet/etcdv2/registry_test.go +++ b/subnet/etcdv2/registry_test.go @@ -88,8 +88,6 @@ func watchSubnets(t *testing.T, r Registry, ctx context.Context, sn ip.IP4Net, n return } } - - result <- fmt.Errorf("Should never get here") } func TestEtcdRegistry(t *testing.T) { @@ -152,19 +150,19 @@ func TestEtcdRegistry(t *testing.T) { t.Fatal("Failed to create subnet lease") } if !exp.After(time.Now()) { - t.Fatal("Subnet lease duration %v not in the future", exp) + t.Fatalf("Subnet lease duration %v not in the future", exp) } // Make sure the lease got created resp, err := m.Get(ctx, "/coreos.com/network/foobar/subnets/10.1.5.0-24", nil) if err != nil { - t.Fatal("Failed to verify subnet lease directly in etcd: %v", err) + t.Fatalf("Failed to verify subnet lease directly in etcd: %v", err) } if resp == nil || resp.Node == nil { t.Fatal("Failed to retrive node in subnet lease") } if resp.Node.Value != "{\"PublicIP\":\"1.2.3.4\"}" { - t.Fatal("Unexpected subnet lease node %s value %s", resp.Node.Key, resp.Node.Value) + t.Fatalf("Unexpected subnet lease node %s value %s", resp.Node.Key, resp.Node.Value) } leases, _, err := r.getSubnets(ctx, "foobar") diff --git a/subnet/etcdv2/subnet_test.go b/subnet/etcdv2/subnet_test.go index 9fb485203b..8a23ae036b 100644 --- a/subnet/etcdv2/subnet_test.go +++ b/subnet/etcdv2/subnet_test.go @@ -280,7 +280,7 @@ func TestRenewLease(t *testing.T) { // check that it's still good n, err := msr.getNetwork(ctx, "_") if err != nil { - t.Error("Failed to renew lease: could not get networks: %v", err) + t.Errorf("Failed to renew lease: could not get networks: %v", err) } for _, sn := range n.subnets { @@ -296,7 +296,7 @@ func TestRenewLease(t *testing.T) { } } - t.Fatalf("Failed to find acquired lease") + t.Fatal("Failed to find acquired lease") } func TestLeaseRevoked(t *testing.T) { @@ -336,7 +336,7 @@ func TestWatchGetNetworks(t *testing.T) { resp, err := sm.WatchNetworks(ctx, nil) if err != nil { - t.Errorf("WatchNetworks(nil) failed:", err) + t.Errorf("WatchNetworks(nil) failed: %v", err) } if len(resp.Snapshot) != 1 { diff --git a/subnet/kube/kube.go b/subnet/kube/kube.go index 5a80b4031b..9d38502797 100644 --- a/subnet/kube/kube.go +++ b/subnet/kube/kube.go @@ -41,7 +41,6 @@ import ( var ( ErrUnimplemented = errors.New("unimplemented") - kubeSubnetCfg *subnet.Config ) const ( diff --git a/subnet/subnet.go b/subnet/subnet.go index 259c90c21b..4326cbdbf5 100644 --- a/subnet/subnet.go +++ b/subnet/subnet.go @@ -28,9 +28,9 @@ import ( ) var ( - ErrLeaseTaken = errors.New("subnet: lease already taken") - ErrNoMoreTries = errors.New("subnet: no more tries") - subnetRegex *regexp.Regexp = regexp.MustCompile(`(\d+\.\d+.\d+.\d+)-(\d+)`) + ErrLeaseTaken = errors.New("subnet: lease already taken") + ErrNoMoreTries = errors.New("subnet: no more tries") + subnetRegex = regexp.MustCompile(`(\d+\.\d+.\d+.\d+)-(\d+)`) ) type LeaseAttrs struct { diff --git a/subnet/watch.go b/subnet/watch.go index ccd02554c7..5a6a21f585 100644 --- a/subnet/watch.go +++ b/subnet/watch.go @@ -47,7 +47,7 @@ func WatchLeases(ctx context.Context, sm Manager, network string, ownLease *Leas cursor = res.Cursor - batch := []Event{} + var batch []Event if len(res.Events) > 0 { batch = lw.update(res.Events) @@ -175,7 +175,7 @@ func WatchNetworks(ctx context.Context, sm Manager, receiver chan []Event) { } cursor = res.Cursor - batch := []Event{} + var batch []Event if len(res.Events) > 0 { batch = nw.update(res.Events) @@ -212,7 +212,7 @@ func (nw *netWatcher) reset(networks []string) []Event { } // everything left in sm.networks has been deleted - for netname, _ := range nw.networks { + for netname := range nw.networks { batch = append(batch, Event{EventRemoved, Lease{}, netname}) }