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
8e25f938
Commit
8e25f938
authored
Sep 30, 2016
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kubelet: fix port forward for dockershim
Signed-off-by:
Pengfei Ni
<
feiskyer@gmail.com
>
parent
1ebf6e1a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
20 deletions
+29
-20
helpers.go
pkg/kubelet/container/helpers.go
+9
-0
docker_service.go
pkg/kubelet/dockershim/docker_service.go
+1
-1
legacy.go
pkg/kubelet/dockershim/legacy.go
+2
-2
docker_manager.go
pkg/kubelet/dockertools/docker_manager.go
+7
-6
kuberuntime_manager.go
pkg/kubelet/kuberuntime/kuberuntime_manager.go
+10
-11
No files found.
pkg/kubelet/container/helpers.go
View file @
8e25f938
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
container
import
(
"fmt"
"hash/adler32"
"strings"
...
...
@@ -214,3 +215,11 @@ func SandboxToContainerState(state runtimeApi.PodSandBoxState) ContainerState {
}
return
ContainerStateUnknown
}
// FormatPod returns a string representing a pod in a human readable format,
// with pod UID as part of the string.
func
FormatPod
(
pod
*
Pod
)
string
{
// Use underscore as the delimiter because it is not allowed in pod name
// (DNS subdomain format), while allowed in the container name format.
return
fmt
.
Sprintf
(
"%s_%s(%s)"
,
pod
.
Name
,
pod
.
Namespace
,
pod
.
ID
)
}
pkg/kubelet/dockershim/docker_service.go
View file @
8e25f938
...
...
@@ -69,7 +69,7 @@ type DockerLegacyService interface {
// Supporting legacy methods for docker.
GetContainerLogs
(
pod
*
api
.
Pod
,
containerID
kubecontainer
.
ContainerID
,
logOptions
*
api
.
PodLogOptions
,
stdout
,
stderr
io
.
Writer
)
(
err
error
)
kubecontainer
.
ContainerAttacher
PortForward
(
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
PortForward
(
sandboxID
string
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
// TODO: Remove this once exec is properly defined in CRI.
ExecInContainer
(
containerID
kubecontainer
.
ContainerID
,
cmd
[]
string
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
,
resize
<-
chan
term
.
Size
)
error
...
...
pkg/kubelet/dockershim/legacy.go
View file @
8e25f938
...
...
@@ -39,8 +39,8 @@ func (ds *dockerService) GetContainerLogs(pod *api.Pod, containerID kubecontaine
return
dockertools
.
GetContainerLogs
(
ds
.
client
,
pod
,
containerID
,
logOptions
,
stdout
,
stderr
)
}
func
(
ds
*
dockerService
)
PortForward
(
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
return
dockertools
.
PortForward
(
ds
.
client
,
pod
,
port
,
stream
)
func
(
ds
*
dockerService
)
PortForward
(
sandboxID
string
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
return
dockertools
.
PortForward
(
ds
.
client
,
sandboxID
,
port
,
stream
)
}
func
(
ds
*
dockerService
)
ExecInContainer
(
containerID
kubecontainer
.
ContainerID
,
cmd
[]
string
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
,
resize
<-
chan
term
.
Size
)
error
{
...
...
pkg/kubelet/dockertools/docker_manager.go
View file @
8e25f938
...
...
@@ -1273,16 +1273,17 @@ func noPodInfraContainerError(podName, podNamespace string) error {
// - should we support nsenter + socat on the host? (current impl)
// - should we support nsenter + socat in a container, running with elevated privs and --pid=host?
func
(
dm
*
DockerManager
)
PortForward
(
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
return
PortForward
(
dm
.
client
,
pod
,
port
,
stream
)
}
// Temporarily export this function to share with dockershim.
func
PortForward
(
client
DockerInterface
,
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
podInfraContainer
:=
pod
.
FindContainerByName
(
PodInfraContainerName
)
if
podInfraContainer
==
nil
{
return
noPodInfraContainerError
(
pod
.
Name
,
pod
.
Namespace
)
}
container
,
err
:=
client
.
InspectContainer
(
podInfraContainer
.
ID
.
ID
)
return
PortForward
(
dm
.
client
,
podInfraContainer
.
ID
.
ID
,
port
,
stream
)
}
// Temporarily export this function to share with dockershim.
func
PortForward
(
client
DockerInterface
,
podInfraContainerID
string
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
container
,
err
:=
client
.
InspectContainer
(
podInfraContainerID
)
if
err
!=
nil
{
return
err
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_manager.go
View file @
8e25f938
...
...
@@ -833,17 +833,10 @@ func (m *kubeGenericRuntimeManager) GarbageCollect(gcPolicy kubecontainer.Contai
// GetPodContainerID gets pod sandbox ID
func
(
m
*
kubeGenericRuntimeManager
)
GetPodContainerID
(
pod
*
kubecontainer
.
Pod
)
(
kubecontainer
.
ContainerID
,
error
)
{
// TODO: add a format function for kubecontainer.Pod
podFullName
:=
format
.
Pod
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
pod
.
Name
,
Namespace
:
pod
.
Namespace
,
UID
:
pod
.
ID
,
},
})
formattedPod
:=
kubecontainer
.
FormatPod
(
pod
)
if
len
(
pod
.
Sandboxes
)
==
0
{
glog
.
Errorf
(
"No sandboxes are found for pod %q"
,
podFullName
)
return
kubecontainer
.
ContainerID
{},
fmt
.
Errorf
(
"sandboxes for pod %q not found"
,
podFullName
)
glog
.
Errorf
(
"No sandboxes are found for pod %q"
,
formattedPod
)
return
kubecontainer
.
ContainerID
{},
fmt
.
Errorf
(
"sandboxes for pod %q not found"
,
formattedPod
)
}
// return sandboxID of the first sandbox since it is the latest one
...
...
@@ -852,11 +845,17 @@ func (m *kubeGenericRuntimeManager) GetPodContainerID(pod *kubecontainer.Pod) (k
// Forward the specified port from the specified pod to the stream.
func
(
m
*
kubeGenericRuntimeManager
)
PortForward
(
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
formattedPod
:=
kubecontainer
.
FormatPod
(
pod
)
if
len
(
pod
.
Sandboxes
)
==
0
{
glog
.
Errorf
(
"No sandboxes are found for pod %q"
,
formattedPod
)
return
fmt
.
Errorf
(
"sandbox for pod %q not found"
,
formattedPod
)
}
// Use docker portforward directly for in-process docker integration
// now to unblock other tests.
// TODO: remove this hack after portforward is defined in CRI.
if
ds
,
ok
:=
m
.
runtimeService
.
(
dockershim
.
DockerLegacyService
);
ok
{
return
ds
.
PortForward
(
pod
,
port
,
stream
)
return
ds
.
PortForward
(
pod
.
Sandboxes
[
0
]
.
ID
.
ID
,
port
,
stream
)
}
return
fmt
.
Errorf
(
"not implemented"
)
...
...
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