Skip to content

Commit

Permalink
third_party: update go-dockerclient
Browse files Browse the repository at this point in the history
math.MaxInt64 represents 8 exabytes, which is a good limit for memory.
Also, this is the type used by Docker, so it's not possible to get any
value bigger than math.MaxInt64 as memory limit (both ram and swap) on a
Docker container.

Relevant discussion at kubernetes#589 (more precisely,
kubernetes#589 (comment)).
  • Loading branch information
fsouza committed Jul 30, 2014
1 parent dc6fdc4 commit 2a345ff
Show file tree
Hide file tree
Showing 16 changed files with 658 additions and 103 deletions.
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes v
ExposedPorts: exposedPorts,
Hostname: container.Name,
Image: container.Image,
Memory: uint64(container.Memory),
Memory: int64(container.Memory),
CpuShares: int64(milliCPUToShares(container.CPU)),
Volumes: volumes,
WorkingDir: container.WorkingDir,
Expand Down
4 changes: 4 additions & 0 deletions third_party/src/github.com/fsouza/go-dockerclient/AUTHORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is the official list of go-dockerclient authors for copyright purposes.

Andreas Jaekle <andreas@jaekle.net>
Andrews Medina <andrewsmedina@gmail.com>
Andy Goldstein <andy.goldstein@redhat.com>
Ben McCann <benmccann.com>
Expand All @@ -8,13 +9,16 @@ Cheah Chu Yeow <chuyeow@gmail.com>
cheneydeng <cheneydeng@qq.com>
Ed <edrocksit@gmail.com>
Eric Anderson <anderson@copperegg.com>
Fabio Rehm <fgrehm@gmail.com>
Flavia Missi <flaviamissi@gmail.com>
Francisco Souza <f@souza.cc>
Jari Kolehmainen <jari.kolehmainen@digia.com>
Jason Wilder <jwilder@litl.com>
Jean-Baptiste Dalido <jeanbaptiste@appgratis.com>
Jeff Mitchell <jeffrey.mitchell@gmail.com>
Jeffrey Hulten <jhulten@gmail.com>
Johan Euphrosine <proppy@google.com>
Karan Misra <kidoman@gmail.com>
Lucas Clemente <lucas@clemente.io>
Omeid Matten <public@omeid.me>
Paul Morie <pmorie@gmail.com>
Expand Down
44 changes: 23 additions & 21 deletions third_party/src/github.com/fsouza/go-dockerclient/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@ For more details, check the [remote API documentation](http://docs.docker.io/en/

## Example

package main

import (
"fmt"
"github.com/fsouza/go-dockerclient"
)

func main() {
endpoint := "unix:///var/run/docker.sock"
client, _ := docker.NewClient(endpoint)
imgs, _ := client.ListImages(true)
for _, img := range imgs {
fmt.Println("ID: ", img.ID)
fmt.Println("RepoTags: ", img.RepoTags)
fmt.Println("Created: ", img.Created)
fmt.Println("Size: ", img.Size)
fmt.Println("VirtualSize: ", img.VirtualSize)
fmt.Println("ParentId: ", img.ParentId)
fmt.Println("Repository: ", img.Repository)
}
}
```go
package main

import (
"fmt"
"github.com/fsouza/go-dockerclient"
)

func main() {
endpoint := "unix:///var/run/docker.sock"
client, _ := docker.NewClient(endpoint)
imgs, _ := client.ListImages(true)
for _, img := range imgs {
fmt.Println("ID: ", img.ID)
fmt.Println("RepoTags: ", img.RepoTags)
fmt.Println("Created: ", img.Created)
fmt.Println("Size: ", img.Size)
fmt.Println("VirtualSize: ", img.VirtualSize)
fmt.Println("ParentId: ", img.ParentId)
fmt.Println("Repository: ", img.Repository)
}
}
```

## Developing

Expand Down
52 changes: 8 additions & 44 deletions third_party/src/github.com/fsouza/go-dockerclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"reflect"
"strconv"
"strings"
"sync"

"github.com/fsouza/go-dockerclient/utils"
)
Expand Down Expand Up @@ -113,11 +112,11 @@ func (version ApiVersion) compare(other ApiVersion) int {
// interaction with the API.
type Client struct {
SkipServerVersionCheck bool
HTTPClient *http.Client

endpoint string
endpointURL *url.URL
eventMonitor *eventMonitoringState
client *http.Client
requestedApiVersion ApiVersion
serverApiVersion ApiVersion
expectedApiVersion ApiVersion
Expand All @@ -142,19 +141,17 @@ func NewVersionedClient(endpoint string, apiVersionString string) (*Client, erro
if err != nil {
return nil, err
}

var requestedApiVersion ApiVersion
if strings.Contains(apiVersionString, ".") {
requestedApiVersion, err = NewApiVersion(apiVersionString)
if err != nil {
return nil, err
}
}

return &Client{
HTTPClient: http.DefaultClient,
endpoint: endpoint,
endpointURL: u,
client: http.DefaultClient,
eventMonitor: new(eventMonitoringState),
requestedApiVersion: requestedApiVersion,
}, nil
Expand All @@ -177,29 +174,6 @@ func (c *Client) checkApiVersion() error {
return nil
}

func parseApiVersionString(input string) (version uint16, err error) {
version = 0

if !strings.Contains(input, ".") {
return 0, fmt.Errorf("Unable to parse version '%s'", input)
}

arr := strings.Split(input, ".")

major, err := strconv.Atoi(arr[0])
if err != nil {
return version, err
}

minor, err := strconv.Atoi(arr[1])
if err != nil {
return version, err
}

version = uint16(major)<<8 | uint16(minor)
return version, nil
}

// Ping pings the docker server
//
// See http://goo.gl/stJENm for more details.
Expand All @@ -223,13 +197,11 @@ func (c *Client) getServerApiVersionString() (version string, err error) {
if status != http.StatusOK {
return "", fmt.Errorf("Received unexpected status %d while trying to retrieve the server version", status)
}

var versionResponse map[string]string
err = json.Unmarshal(body, &versionResponse)
if err != nil {
return "", err
}

version = versionResponse["ApiVersion"]
return version, nil
}
Expand All @@ -243,14 +215,12 @@ func (c *Client) do(method, path string, data interface{}) ([]byte, int, error)
}
params = bytes.NewBuffer(buf)
}

if path != "/version" && !c.SkipServerVersionCheck && c.expectedApiVersion == nil {
err := c.checkApiVersion()
if err != nil {
return nil, -1, err
}
}

req, err := http.NewRequest(method, c.getURL(path), params)
if err != nil {
return nil, -1, err
Expand All @@ -277,7 +247,7 @@ func (c *Client) do(method, path string, data interface{}) ([]byte, int, error)
}
defer clientconn.Close()
} else {
resp, err = c.client.Do(req)
resp, err = c.HTTPClient.Do(req)
}
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
Expand Down Expand Up @@ -335,7 +305,7 @@ func (c *Client) stream(method, path string, setRawTerminal bool, headers map[st
resp, err = clientconn.Do(req)
defer clientconn.Close()
} else {
resp, err = c.client.Do(req)
resp, err = c.HTTPClient.Do(req)
}
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
Expand Down Expand Up @@ -418,18 +388,17 @@ func (c *Client) hijack(method, path string, success chan struct{}, setRawTermin
<-success
}
rwc, br := clientconn.Hijack()
var wg sync.WaitGroup
wg.Add(2)
errs := make(chan error, 2)
exit := make(chan bool)
go func() {
defer close(exit)
var err error
if setRawTerminal {
_, err = io.Copy(stdout, br)
} else {
_, err = utils.StdCopy(stdout, stderr, br)
}
errs <- err
wg.Done()
}()
go func() {
var err error
Expand All @@ -440,14 +409,9 @@ func (c *Client) hijack(method, path string, success chan struct{}, setRawTermin
CloseWrite() error
}).CloseWrite()
errs <- err
wg.Done()
}()
wg.Wait()
close(errs)
if err := <-errs; err != nil {
return err
}
return nil
<-exit
return <-errs
}

func (c *Client) getURL(path string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ func TestNewAPIClient(t *testing.T) {
if client.endpoint != endpoint {
t.Errorf("Expected endpoint %s. Got %s.", endpoint, client.endpoint)
}
if client.client != http.DefaultClient {
t.Errorf("Expected http.Client %#v. Got %#v.", http.DefaultClient, client.client)
if client.HTTPClient != http.DefaultClient {
t.Errorf("Expected http.Client %#v. Got %#v.", http.DefaultClient, client.HTTPClient)
}

// test unix socket endpoints
endpoint = "unix:///var/run/docker.sock"
client, err = NewClient(endpoint)
Expand All @@ -54,8 +53,8 @@ func TestNewVersionedClient(t *testing.T) {
if client.endpoint != endpoint {
t.Errorf("Expected endpoint %s. Got %s.", endpoint, client.endpoint)
}
if client.client != http.DefaultClient {
t.Errorf("Expected http.Client %#v. Got %#v.", http.DefaultClient, client.client)
if client.HTTPClient != http.DefaultClient {
t.Errorf("Expected http.Client %#v. Got %#v.", http.DefaultClient, client.HTTPClient)
}
if reqVersion := client.requestedApiVersion.String(); reqVersion != "1.12" {
t.Errorf("Wrong requestApiVersion. Want %q. Got %q.", "1.12", reqVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ type Config struct {
Hostname string
Domainname string
User string
Memory uint64
MemorySwap uint64
Memory int64
MemorySwap int64
CpuShares int64
AttachStdin bool
AttachStdout bool
Expand Down Expand Up @@ -297,7 +297,7 @@ type HostConfig struct {
NetworkMode string
}

// StartContainer starts a container, returning an errror in case of failure.
// StartContainer starts a container, returning an error in case of failure.
//
// See http://goo.gl/y5GZlE for more details.
func (c *Client) StartContainer(id string, hostConfig *HostConfig) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,88 @@ func TestInspectContainer(t *testing.T) {
}
}

func TestInspectContainerNegativeSwap(t *testing.T) {
jsonContainer := `{
"Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
"Created": "2013-05-07T14:51:42.087658+02:00",
"Path": "date",
"Args": [],
"Config": {
"Hostname": "4fa6e0f0c678",
"User": "",
"Memory": 17179869184,
"MemorySwap": -1,
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"PortSpecs": null,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": [
"date"
],
"Image": "base",
"Volumes": {},
"VolumesFrom": ""
},
"State": {
"Running": false,
"Pid": 0,
"ExitCode": 0,
"StartedAt": "2013-05-07T14:51:42.087658+02:00",
"Ghost": false
},
"Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
"NetworkSettings": {
"IpAddress": "",
"IpPrefixLen": 0,
"Gateway": "",
"Bridge": "",
"PortMapping": null
},
"SysInitPath": "/home/kitty/go/src/github.com/dotcloud/docker/bin/docker",
"ResolvConfPath": "/etc/resolv.conf",
"Volumes": {},
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LxcConf": [],
"Privileged": false,
"PortBindings": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "49153"
}
]
},
"Links": null,
"PublishAllPorts": false
}
}`
var expected Container
err := json.Unmarshal([]byte(jsonContainer), &expected)
if err != nil {
t.Fatal(err)
}
fakeRT := &FakeRoundTripper{message: jsonContainer, status: http.StatusOK}
client := newTestClient(fakeRT)
id := "4fa6e0f0c678"
container, err := client.InspectContainer(id)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(*container, expected) {
t.Errorf("InspectContainer(%q): Expected %#v. Got %#v.", id, expected, container)
}
expectedURL, _ := url.Parse(client.getURL("/containers/4fa6e0f0c678/json"))
if gotPath := fakeRT.requests[0].URL.Path; gotPath != expectedURL.Path {
t.Errorf("InspectContainer(%q): Wrong path in request. Want %q. Got %q.", id, expectedURL.Path, gotPath)
}
}

func TestInspectContainerFailure(t *testing.T) {
client := newTestClient(&FakeRoundTripper{message: "server error", status: 500})
expected := Error{Status: 500, Message: "server error"}
Expand Down Expand Up @@ -1184,9 +1266,9 @@ func TestExportContainerViaUnixSocket(t *testing.T) {
endpoint := "unix://" + tempSocket
u, _ := parseEndpoint(endpoint)
client := Client{
HTTPClient: http.DefaultClient,
endpoint: endpoint,
endpointURL: u,
client: http.DefaultClient,
SkipServerVersionCheck: true,
}
listening := make(chan string)
Expand Down
Loading

0 comments on commit 2a345ff

Please sign in to comment.