Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d33b69a0
Commit
d33b69a0
authored
Apr 17, 2016
by
Random-Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor AttachToContainer and Logs.
parent
de5f4070
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
55 deletions
+37
-55
docker.go
pkg/kubelet/dockertools/docker.go
+2
-2
fake_docker_client.go
pkg/kubelet/dockertools/fake_docker_client.go
+2
-2
instrumented_docker.go
pkg/kubelet/dockertools/instrumented_docker.go
+4
-4
kube_docker_client.go
pkg/kubelet/dockertools/kube_docker_client.go
+8
-26
manager.go
pkg/kubelet/dockertools/manager.go
+21
-21
No files found.
pkg/kubelet/dockertools/docker.go
View file @
d33b69a0
...
@@ -68,13 +68,13 @@ type DockerInterface interface {
...
@@ -68,13 +68,13 @@ type DockerInterface interface {
ListImages
(
opts
docker
.
ListImagesOptions
)
([]
docker
.
APIImages
,
error
)
ListImages
(
opts
docker
.
ListImagesOptions
)
([]
docker
.
APIImages
,
error
)
PullImage
(
opts
docker
.
PullImageOptions
,
auth
docker
.
AuthConfiguration
)
error
PullImage
(
opts
docker
.
PullImageOptions
,
auth
docker
.
AuthConfiguration
)
error
RemoveImage
(
image
string
)
error
RemoveImage
(
image
string
)
error
Logs
(
opts
docker
.
Logs
Options
)
error
Logs
(
string
,
dockertypes
.
ContainerLogsOptions
,
Stream
Options
)
error
Version
()
(
*
docker
.
Env
,
error
)
Version
()
(
*
docker
.
Env
,
error
)
Info
()
(
*
docker
.
Env
,
error
)
Info
()
(
*
docker
.
Env
,
error
)
CreateExec
(
string
,
dockertypes
.
ExecConfig
)
(
*
dockertypes
.
ContainerExecCreateResponse
,
error
)
CreateExec
(
string
,
dockertypes
.
ExecConfig
)
(
*
dockertypes
.
ContainerExecCreateResponse
,
error
)
StartExec
(
string
,
dockertypes
.
ExecStartCheck
,
StreamOptions
)
error
StartExec
(
string
,
dockertypes
.
ExecStartCheck
,
StreamOptions
)
error
InspectExec
(
id
string
)
(
*
dockertypes
.
ContainerExecInspect
,
error
)
InspectExec
(
id
string
)
(
*
dockertypes
.
ContainerExecInspect
,
error
)
AttachToContainer
(
opts
docker
.
AttachToContainer
Options
)
error
AttachToContainer
(
string
,
dockertypes
.
ContainerAttachOptions
,
Stream
Options
)
error
}
}
// KubeletContainerName encapsulates a pod name and a Kubernetes container name.
// KubeletContainerName encapsulates a pod name and a Kubernetes container name.
...
...
pkg/kubelet/dockertools/fake_docker_client.go
View file @
d33b69a0
...
@@ -412,7 +412,7 @@ func (f *FakeDockerClient) RemoveContainer(id string, opts dockertypes.Container
...
@@ -412,7 +412,7 @@ func (f *FakeDockerClient) RemoveContainer(id string, opts dockertypes.Container
// Logs is a test-spy implementation of DockerInterface.Logs.
// Logs is a test-spy implementation of DockerInterface.Logs.
// It adds an entry "logs" to the internal method call record.
// It adds an entry "logs" to the internal method call record.
func
(
f
*
FakeDockerClient
)
Logs
(
opts
docker
.
Logs
Options
)
error
{
func
(
f
*
FakeDockerClient
)
Logs
(
id
string
,
opts
dockertypes
.
ContainerLogsOptions
,
sopts
Stream
Options
)
error
{
f
.
Lock
()
f
.
Lock
()
defer
f
.
Unlock
()
defer
f
.
Unlock
()
f
.
called
=
append
(
f
.
called
,
"logs"
)
f
.
called
=
append
(
f
.
called
,
"logs"
)
...
@@ -462,7 +462,7 @@ func (f *FakeDockerClient) StartExec(startExec string, opts dockertypes.ExecStar
...
@@ -462,7 +462,7 @@ func (f *FakeDockerClient) StartExec(startExec string, opts dockertypes.ExecStar
return
nil
return
nil
}
}
func
(
f
*
FakeDockerClient
)
AttachToContainer
(
opts
docker
.
AttachToContainer
Options
)
error
{
func
(
f
*
FakeDockerClient
)
AttachToContainer
(
id
string
,
opts
dockertypes
.
ContainerAttachOptions
,
sopts
Stream
Options
)
error
{
f
.
Lock
()
f
.
Lock
()
defer
f
.
Unlock
()
defer
f
.
Unlock
()
f
.
called
=
append
(
f
.
called
,
"attach"
)
f
.
called
=
append
(
f
.
called
,
"attach"
)
...
...
pkg/kubelet/dockertools/instrumented_docker.go
View file @
d33b69a0
...
@@ -139,11 +139,11 @@ func (in instrumentedDockerInterface) RemoveImage(image string) error {
...
@@ -139,11 +139,11 @@ func (in instrumentedDockerInterface) RemoveImage(image string) error {
return
err
return
err
}
}
func
(
in
instrumentedDockerInterface
)
Logs
(
opts
docker
.
Logs
Options
)
error
{
func
(
in
instrumentedDockerInterface
)
Logs
(
id
string
,
opts
dockertypes
.
ContainerLogsOptions
,
sopts
Stream
Options
)
error
{
const
operation
=
"logs"
const
operation
=
"logs"
defer
recordOperation
(
operation
,
time
.
Now
())
defer
recordOperation
(
operation
,
time
.
Now
())
err
:=
in
.
client
.
Logs
(
opts
)
err
:=
in
.
client
.
Logs
(
id
,
opts
,
s
opts
)
recordError
(
operation
,
err
)
recordError
(
operation
,
err
)
return
err
return
err
}
}
...
@@ -193,11 +193,11 @@ func (in instrumentedDockerInterface) InspectExec(id string) (*dockertypes.Conta
...
@@ -193,11 +193,11 @@ func (in instrumentedDockerInterface) InspectExec(id string) (*dockertypes.Conta
return
out
,
err
return
out
,
err
}
}
func
(
in
instrumentedDockerInterface
)
AttachToContainer
(
opts
docker
.
AttachToContainer
Options
)
error
{
func
(
in
instrumentedDockerInterface
)
AttachToContainer
(
id
string
,
opts
dockertypes
.
ContainerAttachOptions
,
sopts
Stream
Options
)
error
{
const
operation
=
"attach"
const
operation
=
"attach"
defer
recordOperation
(
operation
,
time
.
Now
())
defer
recordOperation
(
operation
,
time
.
Now
())
err
:=
in
.
client
.
AttachToContainer
(
opts
)
err
:=
in
.
client
.
AttachToContainer
(
id
,
opts
,
s
opts
)
recordError
(
operation
,
err
)
recordError
(
operation
,
err
)
return
err
return
err
}
}
pkg/kubelet/dockertools/kube_docker_client.go
View file @
d33b69a0
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"strconv"
"time"
"time"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/pkg/stdcopy"
...
@@ -210,21 +209,14 @@ func (d *kubeDockerClient) RemoveImage(image string) error {
...
@@ -210,21 +209,14 @@ func (d *kubeDockerClient) RemoveImage(image string) error {
return
err
return
err
}
}
func
(
d
*
kubeDockerClient
)
Logs
(
opts
docker
.
LogsOptions
)
error
{
func
(
d
*
kubeDockerClient
)
Logs
(
id
string
,
opts
dockertypes
.
ContainerLogsOptions
,
sopts
StreamOptions
)
error
{
resp
,
err
:=
d
.
client
.
ContainerLogs
(
getDefaultContext
(),
dockertypes
.
ContainerLogsOptions
{
opts
.
ContainerID
=
id
ContainerID
:
opts
.
Container
,
resp
,
err
:=
d
.
client
.
ContainerLogs
(
getDefaultContext
(),
opts
)
ShowStdout
:
opts
.
Stdout
,
ShowStderr
:
opts
.
Stderr
,
Since
:
strconv
.
FormatInt
(
opts
.
Since
,
10
),
Timestamps
:
opts
.
Timestamps
,
Follow
:
opts
.
Follow
,
Tail
:
opts
.
Tail
,
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
resp
.
Close
()
defer
resp
.
Close
()
return
d
.
redirectResponseToOutputStream
(
opts
.
RawTerminal
,
opts
.
OutputStream
,
opts
.
ErrorStream
,
resp
)
return
d
.
redirectResponseToOutputStream
(
sopts
.
RawTerminal
,
sopts
.
OutputStream
,
s
opts
.
ErrorStream
,
resp
)
}
}
func
(
d
*
kubeDockerClient
)
Version
()
(
*
docker
.
Env
,
error
)
{
func
(
d
*
kubeDockerClient
)
Version
()
(
*
docker
.
Env
,
error
)
{
...
@@ -276,24 +268,14 @@ func (d *kubeDockerClient) InspectExec(id string) (*dockertypes.ContainerExecIns
...
@@ -276,24 +268,14 @@ func (d *kubeDockerClient) InspectExec(id string) (*dockertypes.ContainerExecIns
return
&
resp
,
nil
return
&
resp
,
nil
}
}
func
(
d
*
kubeDockerClient
)
AttachToContainer
(
opts
docker
.
AttachToContainerOptions
)
error
{
func
(
d
*
kubeDockerClient
)
AttachToContainer
(
id
string
,
opts
dockertypes
.
ContainerAttachOptions
,
sopts
StreamOptions
)
error
{
resp
,
err
:=
d
.
client
.
ContainerAttach
(
getDefaultContext
(),
dockertypes
.
ContainerAttachOptions
{
opts
.
ContainerID
=
id
ContainerID
:
opts
.
Container
,
resp
,
err
:=
d
.
client
.
ContainerAttach
(
getDefaultContext
(),
opts
)
Stream
:
opts
.
Stream
,
Stdin
:
opts
.
Stdin
,
Stdout
:
opts
.
Stdout
,
Stderr
:
opts
.
Stderr
,
// TODO: How to deal with the *Logs* here? There is no *Logs* field in the engine-api.
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
resp
.
Close
()
defer
resp
.
Close
()
if
opts
.
Success
!=
nil
{
return
d
.
holdHijackedConnection
(
sopts
.
RawTerminal
,
sopts
.
InputStream
,
sopts
.
OutputStream
,
sopts
.
ErrorStream
,
resp
)
opts
.
Success
<-
struct
{}{}
<-
opts
.
Success
}
return
d
.
holdHijackedConnection
(
opts
.
RawTerminal
,
opts
.
InputStream
,
opts
.
OutputStream
,
opts
.
ErrorStream
,
resp
)
}
}
// redirectResponseToOutputStream redirect the response stream to stdout and stderr. When tty is true, all stream will
// redirectResponseToOutputStream redirect the response stream to stdout and stderr. When tty is true, all stream will
...
...
pkg/kubelet/dockertools/manager.go
View file @
d33b69a0
...
@@ -274,23 +274,22 @@ func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID kubecontaine
...
@@ -274,23 +274,22 @@ func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID kubecontaine
if
logOptions
.
SinceTime
!=
nil
{
if
logOptions
.
SinceTime
!=
nil
{
since
=
logOptions
.
SinceTime
.
Unix
()
since
=
logOptions
.
SinceTime
.
Unix
()
}
}
opts
:=
docker
.
LogsOptions
{
opts
:=
dockertypes
.
ContainerLogsOptions
{
Container
:
containerID
.
ID
,
ShowStdout
:
true
,
Stdout
:
true
,
ShowStderr
:
true
,
Stderr
:
true
,
Since
:
strconv
.
FormatInt
(
since
,
10
),
OutputStream
:
stdout
,
Timestamps
:
logOptions
.
Timestamps
,
ErrorStream
:
stderr
,
Follow
:
logOptions
.
Follow
,
Timestamps
:
logOptions
.
Timestamps
,
Since
:
since
,
Follow
:
logOptions
.
Follow
,
RawTerminal
:
false
,
}
}
if
logOptions
.
TailLines
!=
nil
{
if
logOptions
.
TailLines
!=
nil
{
opts
.
Tail
=
strconv
.
FormatInt
(
*
logOptions
.
TailLines
,
10
)
opts
.
Tail
=
strconv
.
FormatInt
(
*
logOptions
.
TailLines
,
10
)
}
}
sopts
:=
StreamOptions
{
err
=
dm
.
client
.
Logs
(
opts
)
OutputStream
:
stdout
,
ErrorStream
:
stderr
,
RawTerminal
:
false
,
}
err
=
dm
.
client
.
Logs
(
containerID
.
ID
,
opts
,
sopts
)
return
return
}
}
...
@@ -1096,19 +1095,20 @@ func (dm *DockerManager) ExecInContainer(containerID kubecontainer.ContainerID,
...
@@ -1096,19 +1095,20 @@ func (dm *DockerManager) ExecInContainer(containerID kubecontainer.ContainerID,
}
}
func
(
dm
*
DockerManager
)
AttachContainer
(
containerID
kubecontainer
.
ContainerID
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
)
error
{
func
(
dm
*
DockerManager
)
AttachContainer
(
containerID
kubecontainer
.
ContainerID
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
)
error
{
opts
:=
docker
.
AttachToContainerOptions
{
// TODO(random-liu): Do we really use the *Logs* field here?
Container
:
containerID
.
ID
,
opts
:=
dockertypes
.
ContainerAttachOptions
{
Stream
:
true
,
Stdin
:
stdin
!=
nil
,
Stdout
:
stdout
!=
nil
,
Stderr
:
stderr
!=
nil
,
}
sopts
:=
StreamOptions
{
InputStream
:
stdin
,
InputStream
:
stdin
,
OutputStream
:
stdout
,
OutputStream
:
stdout
,
ErrorStream
:
stderr
,
ErrorStream
:
stderr
,
Stream
:
true
,
Logs
:
true
,
Stdin
:
stdin
!=
nil
,
Stdout
:
stdout
!=
nil
,
Stderr
:
stderr
!=
nil
,
RawTerminal
:
tty
,
RawTerminal
:
tty
,
}
}
return
dm
.
client
.
AttachToContainer
(
opts
)
return
dm
.
client
.
AttachToContainer
(
containerID
.
ID
,
opts
,
s
opts
)
}
}
func
noPodInfraContainerError
(
podName
,
podNamespace
string
)
error
{
func
noPodInfraContainerError
(
podName
,
podNamespace
string
)
error
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment