Skip to content

Commit

Permalink
Merge branch 'bug/govet' into 'master'
Browse files Browse the repository at this point in the history
fixup old go vet errors

See merge request !72
  • Loading branch information
timfeirg committed Mar 24, 2017
2 parents 736d9dd + c5f4780 commit 58ae883
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
12 changes: 6 additions & 6 deletions cluster/calcium/remove_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions lock/etcdlock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -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,
Expand Down Expand Up @@ -114,7 +114,6 @@ func (m *mutex) lock() (err error) {
}
}
}
return err
}

// Unlock unlocks m.
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions scheduler/complex/potassium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions store/etcd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58ae883

Please sign in to comment.