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
94b5d52b
Commit
94b5d52b
authored
Jul 29, 2016
by
k8s-merge-robot
Committed by
GitHub
Jul 29, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #29580 from yujuhong/dshim2
Automatic merge from submit-queue dockershim: Implement more functions. Based on #29553. Only the last two commits are new.
parents
03c455fd
e80ad2be
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
16 deletions
+156
-16
docker_container.go
pkg/kubelet/dockershim/docker_container.go
+104
-3
docker_service_test.go
pkg/kubelet/dockershim/docker_service_test.go
+27
-0
legacy.go
pkg/kubelet/dockershim/legacy.go
+3
-2
container_gc.go
pkg/kubelet/dockertools/container_gc.go
+1
-1
docker_manager.go
pkg/kubelet/dockertools/docker_manager.go
+19
-8
kube_docker_client.go
pkg/kubelet/dockertools/kube_docker_client.go
+2
-2
No files found.
pkg/kubelet/dockershim/docker_container.go
View file @
94b5d52b
...
...
@@ -19,12 +19,15 @@ package dockershim
import
(
"fmt"
"io"
"time"
dockertypes
"github.com/docker/engine-api/types"
dockercontainer
"github.com/docker/engine-api/types/container"
dockerfilters
"github.com/docker/engine-api/types/filters"
dockerstrslice
"github.com/docker/engine-api/types/strslice"
runtimeApi
"k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
)
// ListContainers lists all containers matching the filter.
...
...
@@ -190,14 +193,112 @@ func (ds *dockerService) RemoveContainer(rawContainerID string) error {
return
ds
.
client
.
RemoveContainer
(
rawContainerID
,
dockertypes
.
ContainerRemoveOptions
{
RemoveVolumes
:
true
})
}
func
getContainerTimestamps
(
r
*
dockertypes
.
ContainerJSON
)
(
time
.
Time
,
time
.
Time
,
time
.
Time
,
error
)
{
var
createdAt
,
startedAt
,
finishedAt
time
.
Time
var
err
error
createdAt
,
err
=
dockertools
.
ParseDockerTimestamp
(
r
.
Created
)
if
err
!=
nil
{
return
createdAt
,
startedAt
,
finishedAt
,
err
}
startedAt
,
err
=
dockertools
.
ParseDockerTimestamp
(
r
.
State
.
StartedAt
)
if
err
!=
nil
{
return
createdAt
,
startedAt
,
finishedAt
,
err
}
finishedAt
,
err
=
dockertools
.
ParseDockerTimestamp
(
r
.
State
.
FinishedAt
)
if
err
!=
nil
{
return
createdAt
,
startedAt
,
finishedAt
,
err
}
return
createdAt
,
startedAt
,
finishedAt
,
nil
}
// ContainerStatus returns the container status.
// TODO: Implement the function.
func
(
ds
*
dockerService
)
ContainerStatus
(
rawContainerID
string
)
(
*
runtimeApi
.
ContainerStatus
,
error
)
{
return
nil
,
fmt
.
Errorf
(
"not implemented"
)
r
,
err
:=
ds
.
client
.
InspectContainer
(
rawContainerID
)
if
err
!=
nil
{
return
nil
,
err
}
// Parse the timstamps.
createdAt
,
startedAt
,
finishedAt
,
err
:=
getContainerTimestamps
(
r
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to parse timestamp for container %q: %v"
,
rawContainerID
,
err
)
}
// Convert the mounts.
mounts
:=
[]
*
runtimeApi
.
Mount
{}
for
_
,
m
:=
range
r
.
Mounts
{
readonly
:=
!
m
.
RW
mounts
=
append
(
mounts
,
&
runtimeApi
.
Mount
{
Name
:
&
m
.
Name
,
HostPath
:
&
m
.
Source
,
ContainerPath
:
&
m
.
Destination
,
Readonly
:
&
readonly
,
// Note: Can't set SeLinuxRelabel
})
}
// Interpret container states.
var
state
runtimeApi
.
ContainerState
var
reason
string
if
r
.
State
.
Running
{
// Container is running.
state
=
runtimeApi
.
ContainerState_RUNNING
}
else
{
// Container is *not* running. We need to get more details.
// * Case 1: container has run and exited with non-zero finishedAt
// time.
// * Case 2: container has failed to start; it has a zero finishedAt
// time, but a non-zero exit code.
// * Case 3: container has been created, but not started (yet).
if
!
finishedAt
.
IsZero
()
{
// Case 1
state
=
runtimeApi
.
ContainerState_EXITED
switch
{
case
r
.
State
.
OOMKilled
:
// TODO: consider exposing OOMKilled via the runtimeAPI.
// Note: if an application handles OOMKilled gracefully, the
// exit code could be zero.
reason
=
"OOMKilled"
case
r
.
State
.
ExitCode
==
0
:
reason
=
"Completed"
default
:
reason
=
fmt
.
Sprintf
(
"Error: %s"
,
r
.
State
.
Error
)
}
}
else
if
!
finishedAt
.
IsZero
()
&&
r
.
State
.
ExitCode
!=
0
{
// Case 2
state
=
runtimeApi
.
ContainerState_EXITED
// Adjust finshedAt and startedAt time to createdAt time to avoid
// the confusion.
finishedAt
,
startedAt
=
createdAt
,
createdAt
reason
=
"ContainerCannotRun"
}
else
{
// Case 3
state
=
runtimeApi
.
ContainerState_CREATED
}
}
// Convert to unix timestamps.
ct
,
st
,
ft
:=
createdAt
.
Unix
(),
startedAt
.
Unix
(),
finishedAt
.
Unix
()
exitCode
:=
int32
(
r
.
State
.
ExitCode
)
return
&
runtimeApi
.
ContainerStatus
{
Id
:
&
r
.
ID
,
Name
:
&
r
.
Name
,
Image
:
&
runtimeApi
.
ImageSpec
{
Image
:
&
r
.
Config
.
Image
},
ImageRef
:
&
r
.
Image
,
Mounts
:
mounts
,
ExitCode
:
&
exitCode
,
State
:
&
state
,
CreatedAt
:
&
ct
,
StartedAt
:
&
st
,
FinishedAt
:
&
ft
,
Reason
:
&
reason
,
// TODO: We write annotations as labels on the docker containers. All
// these annotations will be read back as labels. Need to fix this.
Labels
:
r
.
Config
.
Labels
,
},
nil
}
// Exec execute a command in the container.
// TODO: Implement the function.
// TODO: Need to handle terminal resizing before implementing this function.
// https://github.com/kubernetes/kubernetes/issues/29579.
func
(
ds
*
dockerService
)
Exec
(
rawContainerID
string
,
cmd
[]
string
,
tty
bool
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
)
error
{
return
fmt
.
Errorf
(
"not implemented"
)
}
pkg/kubelet/dockershim/docker_service_test.go
0 → 100644
View file @
94b5d52b
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
dockershim
import
(
"k8s.io/kubernetes/pkg/kubelet/dockertools"
)
func
newFakeDockerSevice
()
*
dockerService
{
return
&
dockerService
{
client
:
dockertools
.
NewFakeDockerClient
(),
}
}
pkg/kubelet/dockershim/legacy.go
View file @
94b5d52b
...
...
@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/util/term"
)
...
...
@@ -31,11 +32,11 @@ import (
// TODO: implement the methods in this file.
func
(
ds
*
dockerService
)
AttachContainer
(
id
kubecontainer
.
ContainerID
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
,
resize
<-
chan
term
.
Size
)
(
err
error
)
{
return
fmt
.
Errorf
(
"not implemented"
)
return
dockertools
.
AttachContainer
(
ds
.
client
,
id
,
stdin
,
stdout
,
stderr
,
tty
,
resize
)
}
func
(
ds
*
dockerService
)
GetContainerLogs
(
pod
*
api
.
Pod
,
containerID
kubecontainer
.
ContainerID
,
logOptions
*
api
.
PodLogOptions
,
stdout
,
stderr
io
.
Writer
)
(
err
error
)
{
return
fmt
.
Errorf
(
"not implemented"
)
return
dockertools
.
GetContainerLogs
(
ds
.
client
,
pod
,
containerID
,
logOptions
,
stdout
,
stderr
)
}
func
(
ds
*
dockerService
)
PortForward
(
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
...
...
pkg/kubelet/dockertools/container_gc.go
View file @
94b5d52b
...
...
@@ -139,7 +139,7 @@ func (cgc *containerGC) evictableContainers(minAge time.Duration) (containersByE
continue
}
created
,
err
:=
p
arseDockerTimestamp
(
data
.
Created
)
created
,
err
:=
P
arseDockerTimestamp
(
data
.
Created
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to parse Created timestamp %q for container %q"
,
data
.
Created
,
container
.
ID
)
}
...
...
pkg/kubelet/dockertools/docker_manager.go
View file @
94b5d52b
...
...
@@ -285,7 +285,13 @@ func NewDockerManager(
// stream the log. Set 'follow' to false and specify the number of lines (e.g.
// "100" or "all") to tail the log.
// TODO: Make 'RawTerminal' option flagable.
func
(
dm
*
DockerManager
)
GetContainerLogs
(
pod
*
api
.
Pod
,
containerID
kubecontainer
.
ContainerID
,
logOptions
*
api
.
PodLogOptions
,
stdout
,
stderr
io
.
Writer
)
(
err
error
)
{
func
(
dm
*
DockerManager
)
GetContainerLogs
(
pod
*
api
.
Pod
,
containerID
kubecontainer
.
ContainerID
,
logOptions
*
api
.
PodLogOptions
,
stdout
,
stderr
io
.
Writer
)
error
{
return
GetContainerLogs
(
dm
.
client
,
pod
,
containerID
,
logOptions
,
stdout
,
stderr
)
}
// Temporarily export this function to share with dockershim.
// TODO: clean this up.
func
GetContainerLogs
(
client
DockerInterface
,
pod
*
api
.
Pod
,
containerID
kubecontainer
.
ContainerID
,
logOptions
*
api
.
PodLogOptions
,
stdout
,
stderr
io
.
Writer
)
error
{
var
since
int64
if
logOptions
.
SinceSeconds
!=
nil
{
t
:=
unversioned
.
Now
()
.
Add
(
-
time
.
Duration
(
*
logOptions
.
SinceSeconds
)
*
time
.
Second
)
...
...
@@ -309,8 +315,7 @@ func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID kubecontaine
ErrorStream
:
stderr
,
RawTerminal
:
false
,
}
err
=
dm
.
client
.
Logs
(
containerID
.
ID
,
opts
,
sopts
)
return
return
client
.
Logs
(
containerID
.
ID
,
opts
,
sopts
)
}
var
(
...
...
@@ -374,13 +379,13 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
glog
.
Errorf
(
"Failed to parse %q timestamp %q for container %q of pod %q"
,
label
,
s
,
id
,
kubecontainer
.
BuildPodFullName
(
podName
,
podNamespace
))
}
var
createdAt
,
startedAt
,
finishedAt
time
.
Time
if
createdAt
,
err
=
p
arseDockerTimestamp
(
iResult
.
Created
);
err
!=
nil
{
if
createdAt
,
err
=
P
arseDockerTimestamp
(
iResult
.
Created
);
err
!=
nil
{
parseTimestampError
(
"Created"
,
iResult
.
Created
)
}
if
startedAt
,
err
=
p
arseDockerTimestamp
(
iResult
.
State
.
StartedAt
);
err
!=
nil
{
if
startedAt
,
err
=
P
arseDockerTimestamp
(
iResult
.
State
.
StartedAt
);
err
!=
nil
{
parseTimestampError
(
"StartedAt"
,
iResult
.
State
.
StartedAt
)
}
if
finishedAt
,
err
=
p
arseDockerTimestamp
(
iResult
.
State
.
FinishedAt
);
err
!=
nil
{
if
finishedAt
,
err
=
P
arseDockerTimestamp
(
iResult
.
State
.
FinishedAt
);
err
!=
nil
{
parseTimestampError
(
"FinishedAt"
,
iResult
.
State
.
FinishedAt
)
}
...
...
@@ -1123,10 +1128,16 @@ func (dm *DockerManager) ExecInContainer(containerID kubecontainer.ContainerID,
}
func
(
dm
*
DockerManager
)
AttachContainer
(
containerID
kubecontainer
.
ContainerID
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
,
resize
<-
chan
term
.
Size
)
error
{
return
AttachContainer
(
dm
.
client
,
containerID
,
stdin
,
stdout
,
stderr
,
tty
,
resize
)
}
// Temporarily export this function to share with dockershim.
// TODO: clean this up.
func
AttachContainer
(
client
DockerInterface
,
containerID
kubecontainer
.
ContainerID
,
stdin
io
.
Reader
,
stdout
,
stderr
io
.
WriteCloser
,
tty
bool
,
resize
<-
chan
term
.
Size
)
error
{
// Have to start this before the call to client.AttachToContainer because client.AttachToContainer is a blocking
// call :-( Otherwise, resize events don't get processed and the terminal never resizes.
kubecontainer
.
HandleResizing
(
resize
,
func
(
size
term
.
Size
)
{
dm
.
client
.
ResizeContainerTTY
(
containerID
.
ID
,
int
(
size
.
Height
),
int
(
size
.
Width
))
client
.
ResizeContainerTTY
(
containerID
.
ID
,
int
(
size
.
Height
),
int
(
size
.
Width
))
})
// TODO(random-liu): Do we really use the *Logs* field here?
...
...
@@ -1142,7 +1153,7 @@ func (dm *DockerManager) AttachContainer(containerID kubecontainer.ContainerID,
ErrorStream
:
stderr
,
RawTerminal
:
tty
,
}
return
dm
.
client
.
AttachToContainer
(
containerID
.
ID
,
opts
,
sopts
)
return
client
.
AttachToContainer
(
containerID
.
ID
,
opts
,
sopts
)
}
func
noPodInfraContainerError
(
podName
,
podNamespace
string
)
error
{
...
...
pkg/kubelet/dockertools/kube_docker_client.go
View file @
94b5d52b
...
...
@@ -531,8 +531,8 @@ func (d *kubeDockerClient) getTimeoutContext() (context.Context, context.CancelF
return
context
.
WithTimeout
(
context
.
Background
(),
d
.
timeout
)
}
//
p
arseDockerTimestamp parses the timestamp returned by DockerInterface from string to time.Time
func
p
arseDockerTimestamp
(
s
string
)
(
time
.
Time
,
error
)
{
//
P
arseDockerTimestamp parses the timestamp returned by DockerInterface from string to time.Time
func
P
arseDockerTimestamp
(
s
string
)
(
time
.
Time
,
error
)
{
// Timestamp returned by Docker is in time.RFC3339Nano format.
return
time
.
Parse
(
time
.
RFC3339Nano
,
s
)
}
...
...
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