mirror of https://github.com/docker/docs.git
do not leak dockerclient
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
af05bfd0ba
commit
e6b3b04150
|
@ -353,7 +353,7 @@ func deleteImages(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
out := []*dockerclient.ImageDelete{}
|
||||
errs := []string{}
|
||||
for _, image := range matchedImages {
|
||||
content, err := image.Node.DockerClient().RemoveImage(name)
|
||||
content, err := c.cluster.RemoveImage(image)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%s: %s", image.Node.Name(), err.Error()))
|
||||
continue
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/swarm/cluster"
|
||||
"github.com/samalba/dockerclient"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -20,7 +19,6 @@ func (fw *FakeWriter) Write(p []byte) (n int, err error) {
|
|||
|
||||
type FakeNode struct{}
|
||||
|
||||
func (fn *FakeNode) DockerClient() dockerclient.Client { return nil }
|
||||
func (fn *FakeNode) ID() string { return "node_id" }
|
||||
func (fn *FakeNode) Name() string { return "node_name" }
|
||||
func (fn *FakeNode) IP() string { return "node_ip" }
|
||||
|
|
|
@ -15,6 +15,9 @@ type Cluster interface {
|
|||
// Return one image matching `IdOrName`
|
||||
Image(IdOrName string) *Image
|
||||
|
||||
// Remove an image from the cluster
|
||||
RemoveImage(image *Image) ([]*dockerclient.ImageDelete, error)
|
||||
|
||||
// Return all containers
|
||||
Containers() []*Container
|
||||
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
type Node interface {
|
||||
DockerClient() dockerclient.Client
|
||||
|
||||
ID() string
|
||||
Name() string
|
||||
|
||||
|
|
|
@ -186,6 +186,16 @@ func (c *Cluster) Image(IdOrName string) *cluster.Image {
|
|||
return nil
|
||||
}
|
||||
|
||||
// RemoveImage removes an image from the cluster
|
||||
func (c *Cluster) RemoveImage(image *cluster.Image) ([]*dockerclient.ImageDelete, error) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
if n, ok := image.Node.(*node); ok {
|
||||
return n.removeImage(image)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *Cluster) Pull(name string, callback func(what, status string)) {
|
||||
size := len(c.nodes)
|
||||
done := make(chan bool, size)
|
||||
|
|
|
@ -54,10 +54,6 @@ type node struct {
|
|||
overcommitRatio int64
|
||||
}
|
||||
|
||||
func (n *node) DockerClient() dockerclient.Client {
|
||||
return n.client
|
||||
}
|
||||
|
||||
func (n *node) ID() string {
|
||||
return n.id
|
||||
}
|
||||
|
@ -167,6 +163,11 @@ func (n *node) updateSpecs() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Delete an image from the node.
|
||||
func (n *node) removeImage(image *cluster.Image) ([]*dockerclient.ImageDelete, error) {
|
||||
return n.client.RemoveImage(image.Id)
|
||||
}
|
||||
|
||||
// Refresh the list of images on the node.
|
||||
func (n *node) refreshImages() error {
|
||||
images, err := n.client.ListImages()
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package filter
|
||||
|
||||
import (
|
||||
"github.com/docker/swarm/cluster"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
import "github.com/docker/swarm/cluster"
|
||||
|
||||
type FakeNode struct {
|
||||
id string
|
||||
|
@ -14,12 +11,11 @@ type FakeNode struct {
|
|||
labels map[string]string
|
||||
}
|
||||
|
||||
func (fn *FakeNode) DockerClient() dockerclient.Client { return nil }
|
||||
func (fn *FakeNode) ID() string { return fn.id }
|
||||
func (fn *FakeNode) Name() string { return fn.name }
|
||||
func (fn *FakeNode) IP() string { return "" }
|
||||
func (fn *FakeNode) Addr() string { return fn.addr }
|
||||
func (fn *FakeNode) Images() []*cluster.Image { return fn.images }
|
||||
func (fn *FakeNode) ID() string { return fn.id }
|
||||
func (fn *FakeNode) Name() string { return fn.name }
|
||||
func (fn *FakeNode) IP() string { return "" }
|
||||
func (fn *FakeNode) Addr() string { return fn.addr }
|
||||
func (fn *FakeNode) Images() []*cluster.Image { return fn.images }
|
||||
func (fn *FakeNode) Image(id string) *cluster.Image {
|
||||
for _, image := range fn.images {
|
||||
if image.Id == id {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/docker/swarm/cluster"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
||||
type FakeNode struct {
|
||||
|
@ -18,7 +17,6 @@ type FakeNode struct {
|
|||
containers []*cluster.Container
|
||||
}
|
||||
|
||||
func (fn *FakeNode) DockerClient() dockerclient.Client { return nil }
|
||||
func (fn *FakeNode) ID() string { return fn.id }
|
||||
func (fn *FakeNode) Name() string { return fn.name }
|
||||
func (fn *FakeNode) IP() string { return "" }
|
||||
|
|
Loading…
Reference in New Issue