Skip to content

Commit

Permalink
Merge pull request #658 from tomdee/tidy
Browse files Browse the repository at this point in the history
Fix various little problems found by gometalinter
  • Loading branch information
tomdee authored Apr 3, 2017
2 parents 299c4ec + befe879 commit 558d2d0
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion backend/alloc/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions backend/awsvpc/awsvpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion backend/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/hostgw/hostgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions backend/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -95,5 +95,5 @@ func (bm *manager) Wait() {
}

func Register(name string, ctor BackendCtor) {
backendCtors[name] = ctor
constructors[name] = ctor
}
6 changes: 1 addition & 5 deletions backend/udp/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion backend/vxlan/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 2 additions & 4 deletions subnet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion subnet/etcdv2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
8 changes: 3 additions & 5 deletions subnet/etcdv2/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions subnet/etcdv2/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion subnet/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (

var (
ErrUnimplemented = errors.New("unimplemented")
kubeSubnetCfg *subnet.Config
)

const (
Expand Down
6 changes: 3 additions & 3 deletions subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions subnet/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
}

Expand Down

0 comments on commit 558d2d0

Please sign in to comment.