From c5f4780e348e4c38d1130016e57f6832c0a595fa Mon Sep 17 00:00:00 2001 From: timfeirg Date: Fri, 24 Mar 2017 15:30:46 +0800 Subject: [PATCH] fixup old go vet errors --- cluster/calcium/remove_container.go | 12 ++++++------ lock/etcdlock/lock.go | 13 ++++++------- scheduler/complex/potassium_test.go | 6 +++--- store/etcd/node.go | 8 ++++---- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cluster/calcium/remove_container.go b/cluster/calcium/remove_container.go index a406c6f18..324049ce1 100644 --- a/cluster/calcium/remove_container.go +++ b/cluster/calcium/remove_container.go @@ -16,11 +16,11 @@ type imageBucket struct { data map[string]map[string]struct{} } -func newImageBucket() imageBucket { - return imageBucket{data: make(map[string]map[string]struct{})} +func newImageBucket() *imageBucket { + return &imageBucket{data: make(map[string]map[string]struct{})} } -func (ib imageBucket) Add(podname, image string) { +func (ib *imageBucket) Add(podname, image string) { ib.Lock() defer ib.Unlock() @@ -30,11 +30,11 @@ func (ib imageBucket) Add(podname, image string) { ib.data[podname][image] = struct{}{} } -func (ib imageBucket) Dump() map[string][]string { +func (ib *imageBucket) Dump() map[string][]string { r := make(map[string][]string) for podname, imageMap := range ib.data { images := []string{} - for image, _ := range imageMap { + for image := range imageMap { images = append(images, image) } r[podname] = images @@ -96,7 +96,7 @@ func (c *calcium) RemoveContainer(ids []string) (chan *types.RemoveContainerMess wg.Wait() // 把收集的image清理掉 - go func(ib imageBucket) { + go func(ib *imageBucket) { for podname, images := range ib.Dump() { for _, image := range images { c.cleanImage(podname, image) diff --git a/lock/etcdlock/lock.go b/lock/etcdlock/lock.go index bcb8b47fd..d871cf604 100644 --- a/lock/etcdlock/lock.go +++ b/lock/etcdlock/lock.go @@ -18,7 +18,7 @@ const ( ) // A Mutex is a mutual exclusion lock which is distributed across a cluster. -type mutex struct { +type Mutex struct { key string id string // The identity of the caller kapi client.KeysAPI @@ -29,7 +29,7 @@ type mutex struct { // New creates a Mutex with the given key which must be the same // across the cluster nodes. // machines are the ectd cluster addresses -func New(c client.KeysAPI, key string, ttl int) *mutex { +func New(c client.KeysAPI, key string, ttl int) *Mutex { if key == "" { return nil // return fmt.Errorf("A key must be given to create etcd lock, you give %q", key) @@ -48,7 +48,7 @@ func New(c client.KeysAPI, key string, ttl int) *mutex { ttl = defaultTTL } - return &mutex{ + return &Mutex{ key: key, id: fmt.Sprintf("%v-%v-%v", hostname, os.Getpid(), time.Now().Format("20060102-15:04:05.999999999")), kapi: c, @@ -60,7 +60,7 @@ func New(c client.KeysAPI, key string, ttl int) *mutex { // Lock locks m. // If the lock is already in use, the calling goroutine // blocks until the mutex is available. -func (m *mutex) Lock() (err error) { +func (m *Mutex) Lock() (err error) { m.mutex.Lock() for try := 1; try <= defaultTry; try++ { err = m.lock() @@ -71,7 +71,7 @@ func (m *mutex) Lock() (err error) { return err } -func (m *mutex) lock() (err error) { +func (m *Mutex) lock() (err error) { setOptions := &client.SetOptions{ PrevExist: client.PrevNoExist, TTL: m.ttl, @@ -114,7 +114,6 @@ func (m *mutex) lock() (err error) { } } } - return err } // Unlock unlocks m. @@ -123,7 +122,7 @@ func (m *mutex) lock() (err error) { // A locked Mutex is not associated with a particular goroutine. // It is allowed for one goroutine to lock a Mutex and then // arrange for another goroutine to unlock it. -func (m *mutex) Unlock() (err error) { +func (m *Mutex) Unlock() (err error) { defer m.mutex.Unlock() for i := 1; i <= defaultTry; i++ { _, err := m.kapi.Delete(context.TODO(), m.key, nil) diff --git a/scheduler/complex/potassium_test.go b/scheduler/complex/potassium_test.go index 315cd9e26..7ad2472b9 100644 --- a/scheduler/complex/potassium_test.go +++ b/scheduler/complex/potassium_test.go @@ -30,7 +30,7 @@ func TestSelectNodes(t *testing.T) { k, merr := New(coreCfg) if merr != nil { - t.Fatalf("cannot create Potassim instance.", merr) + t.Fatalf("Create Potassim error: %v", merr) } _, _, err := k.SelectNodes(map[string]types.CPUMap{}, 1, 1) @@ -140,7 +140,7 @@ func TestComplexNodes(t *testing.T) { k, merr := New(coreCfg) if merr != nil { - t.Fatalf("cannot create Potassim instance.", merr) + t.Fatalf("Create Potassim error: %v", merr) } // nodes can offer 28 containers. @@ -307,7 +307,7 @@ func TestEvenPlan(t *testing.T) { k, merr := New(coreCfg) if merr != nil { - t.Fatalf("cannot create Potassim instance.", merr) + t.Fatalf("Create Potassim error: %v", merr) } // nodes -- n1: 2, n2: 2 diff --git a/store/etcd/node.go b/store/etcd/node.go index 37a1f6c65..cd80c9889 100644 --- a/store/etcd/node.go +++ b/store/etcd/node.go @@ -31,26 +31,26 @@ type cache struct { clients map[string]*engineapi.Client } -func (c cache) set(host string, client *engineapi.Client) { +func (c *cache) set(host string, client *engineapi.Client) { c.Lock() defer c.Unlock() c.clients[host] = client } -func (c cache) get(host string) *engineapi.Client { +func (c *cache) get(host string) *engineapi.Client { c.Lock() defer c.Unlock() return c.clients[host] } -func (c cache) delete(host string) { +func (c *cache) delete(host string) { c.Lock() defer c.Unlock() delete(c.clients, host) } -var _cache = cache{clients: make(map[string]*engineapi.Client)} +var _cache = &cache{clients: make(map[string]*engineapi.Client)} // get a node from etcd // and construct it's docker client