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
a4811daf
Commit
a4811daf
authored
Jun 23, 2017
by
Andy Goldstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix initial exec terminal dimensions
Delay attempting to send a terminal resize request to docker until after the exec has started; otherwise, the initial resize request will fail.
parent
b350527e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
exec.go
pkg/kubelet/dockershim/exec.go
+21
-3
kube_docker_client.go
pkg/kubelet/dockershim/libdocker/kube_docker_client.go
+10
-0
No files found.
pkg/kubelet/dockershim/exec.go
View file @
a4811daf
...
@@ -135,6 +135,9 @@ func (*NsenterExecHandler) ExecInContainer(client libdocker.Interface, container
...
@@ -135,6 +135,9 @@ func (*NsenterExecHandler) ExecInContainer(client libdocker.Interface, container
type
NativeExecHandler
struct
{}
type
NativeExecHandler
struct
{}
func
(
*
NativeExecHandler
)
ExecInContainer
(
client
libdocker
.
Interface
,
container
*
dockertypes
.
ContainerJSON
,
cmd
[]
string
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
,
resize
<-
chan
remotecommand
.
TerminalSize
,
timeout
time
.
Duration
)
error
{
func
(
*
NativeExecHandler
)
ExecInContainer
(
client
libdocker
.
Interface
,
container
*
dockertypes
.
ContainerJSON
,
cmd
[]
string
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
,
resize
<-
chan
remotecommand
.
TerminalSize
,
timeout
time
.
Duration
)
error
{
done
:=
make
(
chan
struct
{})
defer
close
(
done
)
createOpts
:=
dockertypes
.
ExecConfig
{
createOpts
:=
dockertypes
.
ExecConfig
{
Cmd
:
cmd
,
Cmd
:
cmd
,
AttachStdin
:
stdin
!=
nil
,
AttachStdin
:
stdin
!=
nil
,
...
@@ -149,9 +152,23 @@ func (*NativeExecHandler) ExecInContainer(client libdocker.Interface, container
...
@@ -149,9 +152,23 @@ func (*NativeExecHandler) ExecInContainer(client libdocker.Interface, container
// Have to start this before the call to client.StartExec because client.StartExec is a blocking
// Have to start this before the call to client.StartExec because client.StartExec is a blocking
// call :-( Otherwise, resize events don't get processed and the terminal never resizes.
// call :-( Otherwise, resize events don't get processed and the terminal never resizes.
kubecontainer
.
HandleResizing
(
resize
,
func
(
size
remotecommand
.
TerminalSize
)
{
//
client
.
ResizeExecTTY
(
execObj
.
ID
,
uint
(
size
.
Height
),
uint
(
size
.
Width
))
// We also have to delay attempting to send a terminal resize request to docker until after the
})
// exec has started; otherwise, the initial resize request will fail.
execStarted
:=
make
(
chan
struct
{})
go
func
()
{
select
{
case
<-
execStarted
:
// client.StartExec has started the exec, so we can start resizing
case
<-
done
:
// ExecInContainer has returned, so short-circuit
return
}
kubecontainer
.
HandleResizing
(
resize
,
func
(
size
remotecommand
.
TerminalSize
)
{
client
.
ResizeExecTTY
(
execObj
.
ID
,
uint
(
size
.
Height
),
uint
(
size
.
Width
))
})
}()
startOpts
:=
dockertypes
.
ExecStartCheck
{
Detach
:
false
,
Tty
:
tty
}
startOpts
:=
dockertypes
.
ExecStartCheck
{
Detach
:
false
,
Tty
:
tty
}
streamOpts
:=
libdocker
.
StreamOptions
{
streamOpts
:=
libdocker
.
StreamOptions
{
...
@@ -159,6 +176,7 @@ func (*NativeExecHandler) ExecInContainer(client libdocker.Interface, container
...
@@ -159,6 +176,7 @@ func (*NativeExecHandler) ExecInContainer(client libdocker.Interface, container
OutputStream
:
stdout
,
OutputStream
:
stdout
,
ErrorStream
:
stderr
,
ErrorStream
:
stderr
,
RawTerminal
:
tty
,
RawTerminal
:
tty
,
ExecStarted
:
execStarted
,
}
}
err
=
client
.
StartExec
(
execObj
.
ID
,
startOpts
,
streamOpts
)
err
=
client
.
StartExec
(
execObj
.
ID
,
startOpts
,
streamOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubelet/dockershim/libdocker/kube_docker_client.go
View file @
a4811daf
...
@@ -454,6 +454,15 @@ func (d *kubeDockerClient) StartExec(startExec string, opts dockertypes.ExecStar
...
@@ -454,6 +454,15 @@ func (d *kubeDockerClient) StartExec(startExec string, opts dockertypes.ExecStar
return
err
return
err
}
}
defer
resp
.
Close
()
defer
resp
.
Close
()
if
sopts
.
ExecStarted
!=
nil
{
// Send a message to the channel indicating that the exec has started. This is needed so
// interactive execs can handle resizing correctly - the request to resize the TTY has to happen
// after the call to d.client.ContainerExecAttach, and because d.holdHijackedConnection below
// blocks, we use sopts.ExecStarted to signal the caller that it's ok to resize.
sopts
.
ExecStarted
<-
struct
{}{}
}
return
d
.
holdHijackedConnection
(
sopts
.
RawTerminal
||
opts
.
Tty
,
sopts
.
InputStream
,
sopts
.
OutputStream
,
sopts
.
ErrorStream
,
resp
)
return
d
.
holdHijackedConnection
(
sopts
.
RawTerminal
||
opts
.
Tty
,
sopts
.
InputStream
,
sopts
.
OutputStream
,
sopts
.
ErrorStream
,
resp
)
}
}
...
@@ -584,6 +593,7 @@ type StreamOptions struct {
...
@@ -584,6 +593,7 @@ type StreamOptions struct {
InputStream
io
.
Reader
InputStream
io
.
Reader
OutputStream
io
.
Writer
OutputStream
io
.
Writer
ErrorStream
io
.
Writer
ErrorStream
io
.
Writer
ExecStarted
chan
struct
{}
}
}
// operationTimeout is the error returned when the docker operations are timeout.
// operationTimeout is the error returned when the docker operations are timeout.
...
...
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