Skip to content

Commit

Permalink
update github.com/fsouza/go-dockerclient
Browse files Browse the repository at this point in the history
  • Loading branch information
monnand committed Jul 24, 2014
1 parent 7a8e268 commit ea4224c
Show file tree
Hide file tree
Showing 13 changed files with 1,002 additions and 145 deletions.
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes v
ExposedPorts: exposedPorts,
Hostname: container.Name,
Image: container.Image,
Memory: int64(container.Memory),
Memory: uint64(container.Memory),
CpuShares: int64(milliCPUToShares(container.CPU)),
Volumes: volumes,
WorkingDir: container.WorkingDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: go
go:
- 1.1.2
- 1.2
- 1.3
- tip
env:
- GOARCH=amd64
Expand Down
2 changes: 2 additions & 0 deletions third_party/src/github.com/fsouza/go-dockerclient/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Ed <edrocksit@gmail.com>
Eric Anderson <anderson@copperegg.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>
Expand All @@ -19,6 +20,7 @@ Omeid Matten <public@omeid.me>
Paul Morie <pmorie@gmail.com>
Peter Jihoon Kim <raingrove@gmail.com>
Philippe Lafoucrière <philippe.lafoucriere@tech-angels.com>
Rafe Colton <r.colton@modcloth.com>
Salvador Gironès <salvadorgirones@gmail.com>
Simon Eskildsen <sirup@sirupsen.com>
Simon Menke <simon.menke@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ This package presents a client for the Docker remote API.

For more details, check the [remote API documentation](http://docs.docker.io/en/latest/reference/api/docker_remote_api/).

##Versioning

* Version 0.1 is compatible with Docker v0.7.1
* The master is compatible with Docker's master


## Example

package main
Expand Down
52 changes: 38 additions & 14 deletions third_party/src/github.com/fsouza/go-dockerclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,17 @@ type ApiVersion []int
// <minor> and <patch> are integer numbers.
func NewApiVersion(input string) (ApiVersion, error) {
if !strings.Contains(input, ".") {
return nil, fmt.Errorf("Unable to parse version '%s'", input)
return nil, fmt.Errorf("Unable to parse version %q", input)
}

arr := strings.Split(input, ".")
ret := make(ApiVersion, len(arr))

var err error
for i, val := range arr {
ret[i], err = strconv.Atoi(val)
if err != nil {
return nil, err
return nil, fmt.Errorf("Unable to parse version %q: %q is not an integer", input, val)
}
}

return ret, nil
}

Expand Down Expand Up @@ -203,6 +200,21 @@ func parseApiVersionString(input string) (version uint16, err error) {
return version, nil
}

// Ping pings the docker server
//
// See http://goo.gl/stJENm for more details.
func (c *Client) Ping() error {
path := "/_ping"
body, status, err := c.do("GET", path, nil)
if err != nil {
return err
}
if status != http.StatusOK {
return newError(status, body)
}
return nil
}

func (c *Client) getServerApiVersionString() (version string, err error) {
body, status, err := c.do("GET", "/version", nil)
if err != nil {
Expand Down Expand Up @@ -257,6 +269,7 @@ func (c *Client) do(method, path string, data interface{}) ([]byte, int, error)
if err != nil {
return nil, -1, err
}
defer dial.Close()
clientconn := httputil.NewClientConn(dial, nil)
resp, err = clientconn.Do(req)
if err != nil {
Expand All @@ -283,11 +296,10 @@ func (c *Client) do(method, path string, data interface{}) ([]byte, int, error)
return body, resp.StatusCode, nil
}

func (c *Client) stream(method, path string, headers map[string]string, in io.Reader, out io.Writer) error {
func (c *Client) stream(method, path string, setRawTerminal bool, headers map[string]string, in io.Reader, stdout, stderr io.Writer) error {
if (method == "POST" || method == "PUT") && in == nil {
in = bytes.NewReader(nil)
}

if path != "/version" && !c.SkipServerVersionCheck && c.expectedApiVersion == nil {
err := c.checkApiVersion()
if err != nil {
Expand All @@ -308,8 +320,11 @@ func (c *Client) stream(method, path string, headers map[string]string, in io.Re
var resp *http.Response
protocol := c.endpointURL.Scheme
address := c.endpointURL.Path
if out == nil {
out = ioutil.Discard
if stdout == nil {
stdout = ioutil.Discard
}
if stderr == nil {
stderr = ioutil.Discard
}
if protocol == "unix" {
dial, err := net.Dial(protocol, address)
Expand Down Expand Up @@ -346,20 +361,23 @@ func (c *Client) stream(method, path string, headers map[string]string, in io.Re
return err
}
if m.Stream != "" {
fmt.Fprint(out, m.Stream)
fmt.Fprint(stdout, m.Stream)
} else if m.Progress != "" {
fmt.Fprintf(out, "%s %s\r", m.Status, m.Progress)
fmt.Fprintf(stdout, "%s %s\r", m.Status, m.Progress)
} else if m.Error != "" {
return errors.New(m.Error)
}
if m.Status != "" {
fmt.Fprintln(out, m.Status)
fmt.Fprintln(stdout, m.Status)
}
}
} else {
if _, err := io.Copy(out, resp.Body); err != nil {
return err
if setRawTerminal {
_, err = io.Copy(stdout, resp.Body)
} else {
_, err = utils.StdCopy(stdout, stderr, resp.Body)
}
return err
}
return nil
}
Expand All @@ -371,6 +389,12 @@ func (c *Client) hijack(method, path string, success chan struct{}, setRawTermin
return err
}
}
if stdout == nil {
stdout = ioutil.Discard
}
if stderr == nil {
stderr = ioutil.Discard
}
req, err := http.NewRequest(method, c.getURL(path), nil)
if err != nil {
return err
Expand Down
54 changes: 54 additions & 0 deletions third_party/src/github.com/fsouza/go-dockerclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ func TestQueryString(t *testing.T) {
}
}

func TestNewApiVersionFailures(t *testing.T) {
var tests = []struct {
input string
expectedError string
}{
{"1-0", `Unable to parse version "1-0"`},
{"1.0-beta", `Unable to parse version "1.0-beta": "0-beta" is not an integer`},
}
for _, tt := range tests {
v, err := NewApiVersion(tt.input)
if v != nil {
t.Errorf("Expected <nil> version, got %v.", v)
}
if err.Error() != tt.expectedError {
t.Errorf("NewApiVersion(%q): wrong error. Want %q. Got %q", tt.input, tt.expectedError, err.Error())
}
}
}

func TestApiVersions(t *testing.T) {
var tests = []struct {
a string
Expand Down Expand Up @@ -192,6 +211,41 @@ func TestApiVersions(t *testing.T) {
}
}

func TestPing(t *testing.T) {
fakeRT := &FakeRoundTripper{message: "", status: http.StatusOK}
client := newTestClient(fakeRT)
err := client.Ping()
if err != nil {
t.Fatal(err)
}
}

func TestPingFailing(t *testing.T) {
fakeRT := &FakeRoundTripper{message: "", status: http.StatusInternalServerError}
client := newTestClient(fakeRT)
err := client.Ping()
if err == nil {
t.Fatal("Expected non nil error, got nil")
}
expectedErrMsg := "API error (500): "
if err.Error() != expectedErrMsg {
t.Fatalf("Expected error to be %q, got: %q", expectedErrMsg, err.Error())
}
}

func TestPingFailingWrongStatus(t *testing.T) {
fakeRT := &FakeRoundTripper{message: "", status: http.StatusAccepted}
client := newTestClient(fakeRT)
err := client.Ping()
if err == nil {
t.Fatal("Expected non nil error, got nil")
}
expectedErrMsg := "API error (202): "
if err.Error() != expectedErrMsg {
t.Fatalf("Expected error to be %q, got: %q", expectedErrMsg, err.Error())
}
}

type FakeRoundTripper struct {
message string
status int
Expand Down
56 changes: 45 additions & 11 deletions third_party/src/github.com/fsouza/go-dockerclient/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"net/url"
"strconv"
"strings"
"sync"
"time"
)

Expand Down Expand Up @@ -87,22 +86,19 @@ func (p Port) Proto() string {

// State represents the state of a container.
type State struct {
sync.RWMutex
Running bool
Paused bool
Pid int
ExitCode int
StartedAt time.Time
FinishedAt time.Time
Ghost bool
}

// String returns the string representation of a state.
func (s *State) String() string {
s.RLock()
defer s.RUnlock()
if s.Running {
if s.Ghost {
return "Ghost"
if s.Paused {
return "paused"
}
return fmt.Sprintf("Up %s", time.Now().UTC().Sub(s.StartedAt))
}
Expand Down Expand Up @@ -162,8 +158,8 @@ type Config struct {
Hostname string
Domainname string
User string
Memory int64
MemorySwap int64
Memory uint64
MemorySwap uint64
CpuShares int64
AttachStdin bool
AttachStdout bool
Expand Down Expand Up @@ -351,6 +347,36 @@ func (c *Client) RestartContainer(id string, timeout uint) error {
return nil
}

// PauseContainer pauses the given container.
//
// See http://goo.gl/AM5t42 for more details.
func (c *Client) PauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/pause", id)
_, status, err := c.do("POST", path, nil)
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
if err != nil {
return err
}
return nil
}

// UnpauseContainer pauses the given container.
//
// See http://goo.gl/eBrNSL for more details.
func (c *Client) UnpauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/unpause", id)
_, status, err := c.do("POST", path, nil)
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
if err != nil {
return err
}
return nil
}

// KillContainerOptions represents the set of options that can be used in a
// call to KillContainer.
type KillContainerOptions struct {
Expand Down Expand Up @@ -542,10 +568,15 @@ func (c *Client) AttachToContainer(opts AttachToContainerOptions) error {
type LogsOptions struct {
Container string `qs:"-"`
OutputStream io.Writer `qs:"-"`
ErrorStream io.Writer `qs:"-"`
Follow bool
Stdout bool
Stderr bool
Timestamps bool
Tail string

// Use raw terminal? Usually true when the container contains a TTY.
RawTerminal bool `qs:"-"`
}

// Logs gets stdout and stderr logs from the specified container.
Expand All @@ -555,8 +586,11 @@ func (c *Client) Logs(opts LogsOptions) error {
if opts.Container == "" {
return &NoSuchContainer{ID: opts.Container}
}
if opts.Tail == "" {
opts.Tail = "all"
}
path := "/containers/" + opts.Container + "/logs?" + queryString(opts)
return c.stream("GET", path, nil, nil, opts.OutputStream)
return c.stream("GET", path, opts.RawTerminal, nil, nil, opts.OutputStream, opts.ErrorStream)
}

// ResizeContainerTTY resizes the terminal to the given height and width.
Expand Down Expand Up @@ -586,7 +620,7 @@ func (c *Client) ExportContainer(opts ExportContainerOptions) error {
return NoSuchContainer{ID: opts.ID}
}
url := fmt.Sprintf("/containers/%s/export", opts.ID)
return c.stream("GET", url, nil, nil, opts.OutputStream)
return c.stream("GET", url, true, nil, nil, opts.OutputStream, nil)
}

// NoSuchContainer is the error returned when a given container does not exist.
Expand Down
Loading

0 comments on commit ea4224c

Please sign in to comment.