mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-12-02 19:49:13 +00:00
Update github.com/fsouza/go-dockerclient to pick up IpcMode support.
This commit is contained in:
1
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/.travis.yml
generated
vendored
1
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/.travis.yml
generated
vendored
@@ -2,6 +2,7 @@ language: go
|
||||
go:
|
||||
- 1.2.2
|
||||
- 1.3.1
|
||||
- 1.4
|
||||
- tip
|
||||
env:
|
||||
- GOARCH=amd64
|
||||
|
||||
5
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/AUTHORS
generated
vendored
5
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/AUTHORS
generated
vendored
@@ -3,6 +3,7 @@
|
||||
Aldrin Leal <aldrin@leal.eng.br>
|
||||
Andreas Jaekle <andreas@jaekle.net>
|
||||
Andrews Medina <andrewsmedina@gmail.com>
|
||||
Artem Sidorenko <artem@2realities.com>
|
||||
Andy Goldstein <andy.goldstein@redhat.com>
|
||||
Ben McCann <benmccann.com>
|
||||
Carlos Diaz-Padron <cpadron@mozilla.com>
|
||||
@@ -16,6 +17,7 @@ Dawn Chen <dawnchen@google.com>
|
||||
Ed <edrocksit@gmail.com>
|
||||
Eric Anderson <anderson@copperegg.com>
|
||||
Fabio Rehm <fgrehm@gmail.com>
|
||||
Fatih Arslan <ftharsln@gmail.com>
|
||||
Flavia Missi <flaviamissi@gmail.com>
|
||||
Francisco Souza <f@souza.cc>
|
||||
Jari Kolehmainen <jari.kolehmainen@digia.com>
|
||||
@@ -25,11 +27,14 @@ Jean-Baptiste Dalido <jeanbaptiste@appgratis.com>
|
||||
Jeff Mitchell <jeffrey.mitchell@gmail.com>
|
||||
Jeffrey Hulten <jhulten@gmail.com>
|
||||
Johan Euphrosine <proppy@google.com>
|
||||
Kamil Domanski <kamil@domanski.co>
|
||||
Karan Misra <kidoman@gmail.com>
|
||||
Kim, Hirokuni <hirokuni.kim@kvh.co.jp>
|
||||
Lucas Clemente <lucas@clemente.io>
|
||||
Martin Sweeney <martin@sweeney.io>
|
||||
Máximo Cuadros Ortiz <mcuadros@gmail.com>
|
||||
Mike Dillon <mike.dillon@synctree.com>
|
||||
Mrunal Patel <mrunalp@gmail.com>
|
||||
Omeid Matten <public@omeid.me>
|
||||
Paul Morie <pmorie@gmail.com>
|
||||
Peter Jihoon Kim <raingrove@gmail.com>
|
||||
|
||||
2
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/README.markdown
generated
vendored
2
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/README.markdown
generated
vendored
@@ -22,7 +22,7 @@ import (
|
||||
func main() {
|
||||
endpoint := "unix:///var/run/docker.sock"
|
||||
client, _ := docker.NewClient(endpoint)
|
||||
imgs, _ := client.ListImages(true)
|
||||
imgs, _ := client.ListImages(docker.ListImagesOptions{All: false})
|
||||
for _, img := range imgs {
|
||||
fmt.Println("ID: ", img.ID)
|
||||
fmt.Println("RepoTags: ", img.RepoTags)
|
||||
|
||||
18
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/client.go
generated
vendored
18
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/client.go
generated
vendored
@@ -460,24 +460,34 @@ func (c *Client) hijack(method, path string, success chan struct{}, setRawTermin
|
||||
protocol = "tcp"
|
||||
address = c.endpointURL.Host
|
||||
}
|
||||
dial, err := net.Dial(protocol, address)
|
||||
if err != nil {
|
||||
return err
|
||||
var dial net.Conn
|
||||
if c.TLSConfig != nil && protocol != "unix" {
|
||||
dial, err = tlsDial(protocol, address, c.TLSConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
dial, err = net.Dial(protocol, address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer dial.Close()
|
||||
clientconn := httputil.NewClientConn(dial, nil)
|
||||
defer clientconn.Close()
|
||||
clientconn.Do(req)
|
||||
if success != nil {
|
||||
success <- struct{}{}
|
||||
<-success
|
||||
}
|
||||
rwc, br := clientconn.Hijack()
|
||||
defer rwc.Close()
|
||||
errs := make(chan error, 2)
|
||||
exit := make(chan bool)
|
||||
go func() {
|
||||
defer close(exit)
|
||||
var err error
|
||||
if setRawTerminal {
|
||||
// When TTY is ON, use regular copy
|
||||
_, err = io.Copy(stdout, br)
|
||||
} else {
|
||||
_, err = stdCopy(stdout, stderr, br)
|
||||
|
||||
1
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/container.go
generated
vendored
1
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/container.go
generated
vendored
@@ -358,6 +358,7 @@ type HostConfig struct {
|
||||
ExtraHosts []string `json:"ExtraHosts,omitempty" yaml:"ExtraHosts,omitempty"`
|
||||
VolumesFrom []string `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty"`
|
||||
NetworkMode string `json:"NetworkMode,omitempty" yaml:"NetworkMode,omitempty"`
|
||||
IpcMode string `json:"IpcMode,omitempty" yaml:"IpcMode,omitempty"`
|
||||
RestartPolicy RestartPolicy `json:"RestartPolicy,omitempty" yaml:"RestartPolicy,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
48
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/exec.go
generated
vendored
48
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/exec.go
generated
vendored
@@ -56,6 +56,34 @@ type Exec struct {
|
||||
ID string `json:"Id,omitempty" yaml:"Id,omitempty"`
|
||||
}
|
||||
|
||||
// ExecProcessConfig is a type describing the command associated to a Exec
|
||||
// instance. It's used in the ExecInspect type.
|
||||
//
|
||||
// See http://goo.gl/ypQULN for more details
|
||||
type ExecProcessConfig struct {
|
||||
Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"`
|
||||
User string `json:"user,omitempty" yaml:"user,omitempty"`
|
||||
Tty bool `json:"tty,omitempty" yaml:"tty,omitempty"`
|
||||
EntryPoint string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"`
|
||||
Arguments []string `json:"arguments,omitempty" yaml:"arguments,omitempty"`
|
||||
}
|
||||
|
||||
// ExecInspect is a type with details about a exec instance, including the
|
||||
// exit code if the command has finished running. It's returned by a api
|
||||
// call to /exec/(id)/json
|
||||
//
|
||||
// See http://goo.gl/ypQULN for more details
|
||||
type ExecInspect struct {
|
||||
ID string `json:"ID,omitempty" yaml:"ID,omitempty"`
|
||||
Running bool `json:"Running,omitempty" yaml:"Running,omitempty"`
|
||||
ExitCode int `json:"ExitCode,omitempty" yaml:"ExitCode,omitempty"`
|
||||
OpenStdin bool `json:"OpenStdin,omitempty" yaml:"OpenStdin,omitempty"`
|
||||
OpenStderr bool `json:"OpenStderr,omitempty" yaml:"OpenStderr,omitempty"`
|
||||
OpenStdout bool `json:"OpenStdout,omitempty" yaml:"OpenStdout,omitempty"`
|
||||
ProcessConfig ExecProcessConfig `json:"ProcessConfig,omitempty" yaml:"ProcessConfig,omitempty"`
|
||||
Container Container `json:"Container,omitempty" yaml:"Container,omitempty"`
|
||||
}
|
||||
|
||||
// CreateExec sets up an exec instance in a running container `id`, returning the exec
|
||||
// instance, or an error in case of failure.
|
||||
//
|
||||
@@ -119,6 +147,26 @@ func (c *Client) ResizeExecTTY(id string, height, width int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// InspectExec returns low-level information about the exec command id.
|
||||
//
|
||||
// See http://goo.gl/ypQULN for more details
|
||||
func (c *Client) InspectExec(id string) (*ExecInspect, error) {
|
||||
path := fmt.Sprintf("/exec/%s/json", id)
|
||||
body, status, err := c.do("GET", path, nil)
|
||||
if status == http.StatusNotFound {
|
||||
return nil, &NoSuchExec{ID: id}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var exec ExecInspect
|
||||
err = json.Unmarshal(body, &exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &exec, nil
|
||||
}
|
||||
|
||||
// NoSuchExec is the error returned when a given exec instance does not exist.
|
||||
type NoSuchExec struct {
|
||||
ID string
|
||||
|
||||
131
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/exec_test.go
generated
vendored
131
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/exec_test.go
generated
vendored
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -126,3 +127,133 @@ func TestExecResize(t *testing.T) {
|
||||
t.Errorf("ExecCreate: Wrong path in request. Want %q. Got %q.", expectedURL.Path, gotPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecInspect(t *testing.T) {
|
||||
jsonExec := `{
|
||||
"ID": "32adfeeec34250f9530ce1dafd40c6233832315e065ea6b362d745e2f63cde0e",
|
||||
"Running": true,
|
||||
"ExitCode": 0,
|
||||
"ProcessConfig": {
|
||||
"privileged": false,
|
||||
"user": "",
|
||||
"tty": true,
|
||||
"entrypoint": "bash",
|
||||
"arguments": []
|
||||
},
|
||||
"OpenStdin": true,
|
||||
"OpenStderr": true,
|
||||
"OpenStdout": true,
|
||||
"Container": {
|
||||
"State": {
|
||||
"Running": true,
|
||||
"Paused": false,
|
||||
"Restarting": false,
|
||||
"OOMKilled": false,
|
||||
"Pid": 29392,
|
||||
"ExitCode": 0,
|
||||
"Error": "",
|
||||
"StartedAt": "2015-01-21T17:08:59.634662178Z",
|
||||
"FinishedAt": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
"ID": "922cd0568714763dc725b24b7c9801016b2a3de68e2a1dc989bf5abf07740521",
|
||||
"Created": "2015-01-21T17:08:59.46407212Z",
|
||||
"Path": "/bin/bash",
|
||||
"Args": [
|
||||
"-lc",
|
||||
"tsuru_unit_agent http://192.168.50.4:8080 689b30e0ab3adce374346de2e72512138e0e8b75 gtest /var/lib/tsuru/start && tail -f /dev/null"
|
||||
],
|
||||
"Config": {
|
||||
"Hostname": "922cd0568714",
|
||||
"Domainname": "",
|
||||
"User": "ubuntu",
|
||||
"Memory": 0,
|
||||
"MemorySwap": 0,
|
||||
"CpuShares": 100,
|
||||
"Cpuset": "",
|
||||
"AttachStdin": false,
|
||||
"AttachStdout": false,
|
||||
"AttachStderr": false,
|
||||
"PortSpecs": null,
|
||||
"ExposedPorts": {
|
||||
"8888/tcp": {}
|
||||
},
|
||||
"Tty": false,
|
||||
"OpenStdin": false,
|
||||
"StdinOnce": false,
|
||||
"Env": [
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
],
|
||||
"Cmd": [
|
||||
"/bin/bash",
|
||||
"-lc",
|
||||
"tsuru_unit_agent http://192.168.50.4:8080 689b30e0ab3adce374346de2e72512138e0e8b75 gtest /var/lib/tsuru/start && tail -f /dev/null"
|
||||
],
|
||||
"Image": "tsuru/app-gtest",
|
||||
"Volumes": null,
|
||||
"WorkingDir": "",
|
||||
"Entrypoint": null,
|
||||
"NetworkDisabled": false,
|
||||
"MacAddress": "",
|
||||
"OnBuild": null
|
||||
},
|
||||
"Image": "a88060b8b54fde0f7168c86742d0ce83b80f3f10925d85c98fdad9ed00bef544",
|
||||
"NetworkSettings": {
|
||||
"IPAddress": "172.17.0.8",
|
||||
"IPPrefixLen": 16,
|
||||
"MacAddress": "02:42:ac:11:00:08",
|
||||
"LinkLocalIPv6Address": "fe80::42:acff:fe11:8",
|
||||
"LinkLocalIPv6PrefixLen": 64,
|
||||
"GlobalIPv6Address": "",
|
||||
"GlobalIPv6PrefixLen": 0,
|
||||
"Gateway": "172.17.42.1",
|
||||
"IPv6Gateway": "",
|
||||
"Bridge": "docker0",
|
||||
"PortMapping": null,
|
||||
"Ports": {
|
||||
"8888/tcp": [
|
||||
{
|
||||
"HostIp": "0.0.0.0",
|
||||
"HostPort": "49156"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"ResolvConfPath": "/var/lib/docker/containers/922cd0568714763dc725b24b7c9801016b2a3de68e2a1dc989bf5abf07740521/resolv.conf",
|
||||
"HostnamePath": "/var/lib/docker/containers/922cd0568714763dc725b24b7c9801016b2a3de68e2a1dc989bf5abf07740521/hostname",
|
||||
"HostsPath": "/var/lib/docker/containers/922cd0568714763dc725b24b7c9801016b2a3de68e2a1dc989bf5abf07740521/hosts",
|
||||
"Name": "/c7e43b72288ee9d0270a",
|
||||
"Driver": "aufs",
|
||||
"ExecDriver": "native-0.2",
|
||||
"MountLabel": "",
|
||||
"ProcessLabel": "",
|
||||
"AppArmorProfile": "",
|
||||
"RestartCount": 0,
|
||||
"UpdateDns": false,
|
||||
"Volumes": {},
|
||||
"VolumesRW": {}
|
||||
}
|
||||
}`
|
||||
var expected ExecInspect
|
||||
err := json.Unmarshal([]byte(jsonExec), &expected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fakeRT := &FakeRoundTripper{message: jsonExec, status: http.StatusOK}
|
||||
client := newTestClient(fakeRT)
|
||||
expectedID := "32adfeeec34250f9530ce1dafd40c6233832315e065ea6b362d745e2f63cde0e"
|
||||
execObj, err := client.InspectExec(expectedID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(*execObj, expected) {
|
||||
t.Errorf("ExecInspect: Expected %#v. Got %#v.", expected, *execObj)
|
||||
}
|
||||
req := fakeRT.requests[0]
|
||||
if req.Method != "GET" {
|
||||
t.Errorf("ExecInspect: wrong HTTP method. Want %q. Got %q.", "GET", req.Method)
|
||||
}
|
||||
expectedURL, _ := url.Parse(client.getURL("/exec/" + expectedID + "/json"))
|
||||
if gotPath := fakeRT.requests[0].URL.Path; gotPath != expectedURL.Path {
|
||||
t.Errorf("ExecInspect: Wrong path in request. Want %q. Got %q.", expectedURL.Path, gotPath)
|
||||
}
|
||||
}
|
||||
|
||||
6
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/tar.go
generated
vendored
6
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/tar.go
generated
vendored
@@ -27,9 +27,9 @@ func createTarStream(srcPath string) (io.ReadCloser, error) {
|
||||
return nil, err
|
||||
}
|
||||
tarOpts := &archive.TarOptions{
|
||||
Excludes: excludes,
|
||||
Compression: archive.Uncompressed,
|
||||
NoLchown: true,
|
||||
ExcludePatterns: excludes,
|
||||
Compression: archive.Uncompressed,
|
||||
NoLchown: true,
|
||||
}
|
||||
return archive.TarWithOptions(srcPath, tarOpts)
|
||||
}
|
||||
|
||||
2
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/bin/fmtpolice
generated
vendored
2
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/bin/fmtpolice
generated
vendored
@@ -31,7 +31,7 @@ _lint_verbose() {
|
||||
|
||||
_install_linter() {
|
||||
if [[ ! -x "${GOPATH}/bin/golint" ]] ; then
|
||||
go get -u github.com/golang/lint/golint
|
||||
go get -u -f github.com/golang/lint/golint
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
53
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server.go
generated
vendored
53
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server.go
generated
vendored
@@ -34,7 +34,7 @@ import (
|
||||
// For more details on the remote API, check http://goo.gl/G3plxW.
|
||||
type DockerServer struct {
|
||||
containers []*docker.Container
|
||||
execs []*docker.Exec
|
||||
execs []*docker.ExecInspect
|
||||
cMut sync.RWMutex
|
||||
images []docker.Image
|
||||
iMut sync.RWMutex
|
||||
@@ -99,7 +99,9 @@ func (s *DockerServer) buildMuxer() {
|
||||
s.mux.Path("/containers/{id:.*}/attach").Methods("POST").HandlerFunc(s.handlerWrapper(s.attachContainer))
|
||||
s.mux.Path("/containers/{id:.*}").Methods("DELETE").HandlerFunc(s.handlerWrapper(s.removeContainer))
|
||||
s.mux.Path("/containers/{id:.*}/exec").Methods("POST").HandlerFunc(s.handlerWrapper(s.createExecContainer))
|
||||
s.mux.Path("/exec/{id:.*}/resize").Methods("POST").HandlerFunc(s.handlerWrapper(s.resizeExecContainer))
|
||||
s.mux.Path("/exec/{id:.*}/start").Methods("POST").HandlerFunc(s.handlerWrapper(s.startExecContainer))
|
||||
s.mux.Path("/exec/{id:.*}/json").Methods("GET").HandlerFunc(s.handlerWrapper(s.inspectExecContainer))
|
||||
s.mux.Path("/images/create").Methods("POST").HandlerFunc(s.handlerWrapper(s.pullImage))
|
||||
s.mux.Path("/build").Methods("POST").HandlerFunc(s.handlerWrapper(s.buildImage))
|
||||
s.mux.Path("/images/json").Methods("GET").HandlerFunc(s.handlerWrapper(s.listImages))
|
||||
@@ -724,10 +726,31 @@ func (s *DockerServer) getImage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DockerServer) createExecContainer(w http.ResponseWriter, r *http.Request) {
|
||||
id := mux.Vars(r)["id"]
|
||||
container, _, err := s.findContainer(id)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
exec := docker.ExecInspect{
|
||||
ID: "id-exec-created-by-test",
|
||||
Container: *container,
|
||||
}
|
||||
var params docker.CreateExecOptions
|
||||
err = json.NewDecoder(r.Body).Decode(¶ms)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(params.Cmd) > 0 {
|
||||
exec.ProcessConfig.EntryPoint = params.Cmd[0]
|
||||
if len(params.Cmd) > 1 {
|
||||
exec.ProcessConfig.Arguments = params.Cmd[1:]
|
||||
}
|
||||
}
|
||||
s.execs = append(s.execs, &exec)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
exec := docker.Exec{ID: "id-exec-created-by-test"}
|
||||
s.execs = append(s.execs, &exec)
|
||||
json.NewEncoder(w).Encode(map[string]string{"Id": exec.ID})
|
||||
|
||||
}
|
||||
@@ -742,3 +765,27 @@ func (s *DockerServer) startExecContainer(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (s *DockerServer) resizeExecContainer(w http.ResponseWriter, r *http.Request) {
|
||||
id := mux.Vars(r)["id"]
|
||||
for _, exec := range s.execs {
|
||||
if exec.ID == id {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (s *DockerServer) inspectExecContainer(w http.ResponseWriter, r *http.Request) {
|
||||
id := mux.Vars(r)["id"]
|
||||
for _, exec := range s.execs {
|
||||
if exec.ID == id {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(exec)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
|
||||
80
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server_test.go
generated
vendored
80
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server_test.go
generated
vendored
@@ -1089,3 +1089,83 @@ func TestDefaultHandler(t *testing.T) {
|
||||
t.Fatalf("DefaultHandler: Expected to return server.mux, got: %#v", server.DefaultHandler())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateExecContainer(t *testing.T) {
|
||||
server := DockerServer{}
|
||||
addContainers(&server, 2)
|
||||
server.buildMuxer()
|
||||
recorder := httptest.NewRecorder()
|
||||
body := `{"Cmd": ["bash", "-c", "ls"]}`
|
||||
path := fmt.Sprintf("/containers/%s/exec", server.containers[0].ID)
|
||||
request, _ := http.NewRequest("POST", path, strings.NewReader(body))
|
||||
server.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("CreateExec: wrong status. Want %d. Got %d.", http.StatusOK, recorder.Code)
|
||||
}
|
||||
serverExec := server.execs[0]
|
||||
var got docker.Exec
|
||||
err := json.NewDecoder(recorder.Body).Decode(&got)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.ID != serverExec.ID {
|
||||
t.Errorf("CreateExec: wrong value. Want %#v. Got %#v.", serverExec.ID, got.ID)
|
||||
}
|
||||
expected := docker.ExecInspect{
|
||||
ID: got.ID,
|
||||
ProcessConfig: docker.ExecProcessConfig{
|
||||
EntryPoint: "bash",
|
||||
Arguments: []string{"-c", "ls"},
|
||||
},
|
||||
Container: *server.containers[0],
|
||||
}
|
||||
if !reflect.DeepEqual(*serverExec, expected) {
|
||||
t.Errorf("InspectContainer: wrong value. Want:\n%#v\nGot:\n%#v\n", expected, *serverExec)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInspectExecContainer(t *testing.T) {
|
||||
server := DockerServer{}
|
||||
addContainers(&server, 1)
|
||||
server.buildMuxer()
|
||||
recorder := httptest.NewRecorder()
|
||||
body := `{"Cmd": ["bash", "-c", "ls"]}`
|
||||
path := fmt.Sprintf("/containers/%s/exec", server.containers[0].ID)
|
||||
request, _ := http.NewRequest("POST", path, strings.NewReader(body))
|
||||
server.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("CreateExec: wrong status. Want %d. Got %d.", http.StatusOK, recorder.Code)
|
||||
}
|
||||
var got docker.Exec
|
||||
err := json.NewDecoder(recorder.Body).Decode(&got)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path = fmt.Sprintf("/exec/%s/json", got.ID)
|
||||
request, _ = http.NewRequest("GET", path, nil)
|
||||
server.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("CreateExec: wrong status. Want %d. Got %d.", http.StatusOK, recorder.Code)
|
||||
}
|
||||
var got2 docker.ExecInspect
|
||||
err = json.NewDecoder(recorder.Body).Decode(&got2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := docker.ExecInspect{
|
||||
ID: got.ID,
|
||||
ProcessConfig: docker.ExecProcessConfig{
|
||||
EntryPoint: "bash",
|
||||
Arguments: []string{"-c", "ls"},
|
||||
},
|
||||
Container: *server.containers[0],
|
||||
}
|
||||
got2.Container.State.StartedAt = expected.Container.State.StartedAt
|
||||
got2.Container.State.FinishedAt = expected.Container.State.FinishedAt
|
||||
got2.Container.Config = expected.Container.Config
|
||||
got2.Container.Created = expected.Container.Created
|
||||
got2.Container.NetworkSettings = expected.Container.NetworkSettings
|
||||
if !reflect.DeepEqual(got2, expected) {
|
||||
t.Errorf("InspectContainer: wrong value. Want:\n%#v\nGot:\n%#v\n", expected, got2)
|
||||
}
|
||||
}
|
||||
|
||||
100
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/tls.go
generated
vendored
Normal file
100
Godeps/_workspace/src/github.com/fsouza/go-dockerclient/tls.go
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
// Copyright 2014 go-dockerclient authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
//
|
||||
// The content is borrowed from Docker's own source code to provide a simple
|
||||
// tls based dialer
|
||||
|
||||
package docker
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type tlsClientCon struct {
|
||||
*tls.Conn
|
||||
rawConn net.Conn
|
||||
}
|
||||
|
||||
func (c *tlsClientCon) CloseWrite() error {
|
||||
// Go standard tls.Conn doesn't provide the CloseWrite() method so we do it
|
||||
// on its underlying connection.
|
||||
if cwc, ok := c.rawConn.(interface {
|
||||
CloseWrite() error
|
||||
}); ok {
|
||||
return cwc.CloseWrite()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func tlsDialWithDialer(dialer *net.Dialer, network, addr string, config *tls.Config) (net.Conn, error) {
|
||||
// We want the Timeout and Deadline values from dialer to cover the
|
||||
// whole process: TCP connection and TLS handshake. This means that we
|
||||
// also need to start our own timers now.
|
||||
timeout := dialer.Timeout
|
||||
|
||||
if !dialer.Deadline.IsZero() {
|
||||
deadlineTimeout := dialer.Deadline.Sub(time.Now())
|
||||
if timeout == 0 || deadlineTimeout < timeout {
|
||||
timeout = deadlineTimeout
|
||||
}
|
||||
}
|
||||
|
||||
var errChannel chan error
|
||||
|
||||
if timeout != 0 {
|
||||
errChannel = make(chan error, 2)
|
||||
time.AfterFunc(timeout, func() {
|
||||
errChannel <- errors.New("")
|
||||
})
|
||||
}
|
||||
|
||||
rawConn, err := dialer.Dial(network, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
colonPos := strings.LastIndex(addr, ":")
|
||||
if colonPos == -1 {
|
||||
colonPos = len(addr)
|
||||
}
|
||||
hostname := addr[:colonPos]
|
||||
|
||||
// If no ServerName is set, infer the ServerName
|
||||
// from the hostname we're connecting to.
|
||||
if config.ServerName == "" {
|
||||
// Make a copy to avoid polluting argument or default.
|
||||
c := *config
|
||||
c.ServerName = hostname
|
||||
config = &c
|
||||
}
|
||||
|
||||
conn := tls.Client(rawConn, config)
|
||||
|
||||
if timeout == 0 {
|
||||
err = conn.Handshake()
|
||||
} else {
|
||||
go func() {
|
||||
errChannel <- conn.Handshake()
|
||||
}()
|
||||
|
||||
err = <-errChannel
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
rawConn.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// This is Docker difference with standard's crypto/tls package: returned a
|
||||
// wrapper which holds both the TLS and raw connections.
|
||||
return &tlsClientCon{conn, rawConn}, nil
|
||||
}
|
||||
|
||||
func tlsDial(network, addr string, config *tls.Config) (net.Conn, error) {
|
||||
return tlsDialWithDialer(new(net.Dialer), network, addr, config)
|
||||
}
|
||||
Reference in New Issue
Block a user