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
a94aeb27
Commit
a94aeb27
authored
Apr 30, 2015
by
Victor Marmol
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7586 from yujuhong/container_info
Remove more docker references in kubelet
parents
248508ca
644ec0db
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
45 deletions
+26
-45
helpers.go
pkg/kubelet/container/helpers.go
+5
-5
manager.go
pkg/kubelet/dockertools/manager.go
+1
-1
kubelet.go
pkg/kubelet/kubelet.go
+10
-18
kubelet_test.go
pkg/kubelet/kubelet_test.go
+9
-20
server.go
pkg/kubelet/server.go
+1
-1
No files found.
pkg/kubelet/container/helpers.go
View file @
a94aeb27
...
...
@@ -34,13 +34,13 @@ type RunContainerOptionsGenerator interface {
GenerateRunContainerOptions
(
pod
*
api
.
Pod
,
container
*
api
.
Container
,
netMode
,
ipcMode
string
)
(
*
RunContainerOptions
,
error
)
}
// Trims runtime prefix from image name (e.g.: docker://busybox -> busybox).
func
TrimRuntimePrefix
FromImage
(
im
g
string
)
string
{
// Trims runtime prefix from
ID or
image name (e.g.: docker://busybox -> busybox).
func
TrimRuntimePrefix
(
fullStrin
g
string
)
string
{
const
prefixSeparator
=
"://"
idx
:=
strings
.
Index
(
im
g
,
prefixSeparator
)
idx
:=
strings
.
Index
(
fullStrin
g
,
prefixSeparator
)
if
idx
<
0
{
return
im
g
return
fullStrin
g
}
return
im
g
[
idx
+
len
(
prefixSeparator
)
:
]
return
fullStrin
g
[
idx
+
len
(
prefixSeparator
)
:
]
}
pkg/kubelet/dockertools/manager.go
View file @
a94aeb27
...
...
@@ -1299,7 +1299,7 @@ func shouldContainerBeRestarted(container *api.Container, pod *api.Pod, podStatu
// Set dead containers to unready state.
for
_
,
c
:=
range
resultStatus
{
readinessManager
.
RemoveReadiness
(
kubecontainer
.
TrimRuntimePrefix
FromImage
(
c
.
ContainerID
))
readinessManager
.
RemoveReadiness
(
kubecontainer
.
TrimRuntimePrefix
(
c
.
ContainerID
))
}
// Check RestartPolicy for dead container.
...
...
pkg/kubelet/kubelet.go
View file @
a94aeb27
...
...
@@ -76,10 +76,6 @@ const (
)
var
(
// ErrNoKubeletContainers returned when there are not containers managed by
// the kubelet (ie: either no containers on the node, or none that the kubelet cares about).
ErrNoKubeletContainers
=
errors
.
New
(
"no containers managed by kubelet"
)
// ErrContainerNotFound returned when a container in the given pod with the
// given container name was not found, amongst those managed by the kubelet.
ErrContainerNotFound
=
errors
.
New
(
"no matching container"
)
...
...
@@ -1435,7 +1431,7 @@ func (kl *Kubelet) validatePodPhase(podStatus *api.PodStatus) error {
return
fmt
.
Errorf
(
"pod is not in 'Running', 'Succeeded' or 'Failed' state - State: %q"
,
podStatus
.
Phase
)
}
func
(
kl
*
Kubelet
)
validateContainerStatus
(
podStatus
*
api
.
PodStatus
,
containerName
string
)
(
dock
erID
string
,
err
error
)
{
func
(
kl
*
Kubelet
)
validateContainerStatus
(
podStatus
*
api
.
PodStatus
,
containerName
string
)
(
contain
erID
string
,
err
error
)
{
cStatus
,
found
:=
api
.
GetContainerStatus
(
podStatus
.
ContainerStatuses
,
containerName
)
if
!
found
{
return
""
,
fmt
.
Errorf
(
"container %q not found in pod"
,
containerName
)
...
...
@@ -1443,7 +1439,7 @@ func (kl *Kubelet) validateContainerStatus(podStatus *api.PodStatus, containerNa
if
cStatus
.
State
.
Waiting
!=
nil
{
return
""
,
fmt
.
Errorf
(
"container %q is in waiting state."
,
containerName
)
}
return
kubecontainer
.
TrimRuntimePrefix
FromImage
(
cStatus
.
ContainerID
),
nil
return
kubecontainer
.
TrimRuntimePrefix
(
cStatus
.
ContainerID
),
nil
}
// GetKubeletContainerLogs returns logs from the container
...
...
@@ -1458,13 +1454,13 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail stri
// No log is available if pod is not in a "known" phase (e.g. Unknown).
return
err
}
dockerC
ontainerID
,
err
:=
kl
.
validateContainerStatus
(
&
podStatus
,
containerName
)
c
ontainerID
,
err
:=
kl
.
validateContainerStatus
(
&
podStatus
,
containerName
)
if
err
!=
nil
{
// No log is available if the container status is missing or is in the
// waiting state.
return
err
}
return
kl
.
containerManager
.
GetContainerLogs
(
dockerC
ontainerID
,
tail
,
follow
,
stdout
,
stderr
)
return
kl
.
containerManager
.
GetContainerLogs
(
c
ontainerID
,
tail
,
follow
,
stdout
,
stderr
)
}
// GetHostname Returns the hostname as the kubelet sees it.
...
...
@@ -1756,7 +1752,7 @@ func (kl *Kubelet) generatePodStatus(pod *api.Pod) (api.PodStatus, error) {
for
_
,
c
:=
range
spec
.
Containers
{
for
i
,
st
:=
range
podStatus
.
ContainerStatuses
{
if
st
.
Name
==
c
.
Name
{
ready
:=
st
.
State
.
Running
!=
nil
&&
kl
.
readinessManager
.
GetReadiness
(
strings
.
TrimPrefix
(
st
.
ContainerID
,
"docker://"
))
ready
:=
st
.
State
.
Running
!=
nil
&&
kl
.
readinessManager
.
GetReadiness
(
kubecontainer
.
TrimRuntimePrefix
(
st
.
ContainerID
))
podStatus
.
ContainerStatuses
[
i
]
.
Ready
=
ready
break
}
...
...
@@ -1855,23 +1851,19 @@ func (kl *Kubelet) StreamingConnectionIdleTimeout() time.Duration {
}
// GetContainerInfo returns stats (from Cadvisor) for a container.
func
(
kl
*
Kubelet
)
GetContainerInfo
(
podFullName
string
,
uid
types
.
UID
,
containerName
string
,
req
*
cadvisorApi
.
ContainerInfoRequest
)
(
*
cadvisorApi
.
ContainerInfo
,
error
)
{
func
(
kl
*
Kubelet
)
GetContainerInfo
(
podFullName
string
,
podUID
types
.
UID
,
containerName
string
,
req
*
cadvisorApi
.
ContainerInfoRequest
)
(
*
cadvisorApi
.
ContainerInfo
,
error
)
{
uid
=
kl
.
podManager
.
TranslatePodUID
(
uid
)
podUID
=
kl
.
podManager
.
TranslatePodUID
(
podUID
)
dockerContainers
,
err
:=
dockertools
.
GetKubeletDockerContainers
(
kl
.
dockerClient
,
fals
e
)
container
,
err
:=
kl
.
findContainer
(
podFullName
,
podUID
,
containerNam
e
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
dockerContainers
)
==
0
{
return
nil
,
ErrNoKubeletContainers
}
dockerContainer
,
found
,
_
:=
dockerContainers
.
FindPodContainer
(
podFullName
,
uid
,
containerName
)
if
!
found
{
if
container
==
nil
{
return
nil
,
ErrContainerNotFound
}
ci
,
err
:=
kl
.
cadvisor
.
DockerContainer
(
dockerContainer
.
ID
,
req
)
ci
,
err
:=
kl
.
cadvisor
.
DockerContainer
(
string
(
container
.
ID
)
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/kubelet/kubelet_test.go
View file @
a94aeb27
...
...
@@ -1416,16 +1416,6 @@ func TestMakeVolumesAndBinds(t *testing.T) {
verifyStringArrayEquals
(
t
,
binds
,
expectedBinds
)
}
type
errorTestingDockerClient
struct
{
dockertools
.
FakeDockerClient
listContainersError
error
containerList
[]
docker
.
APIContainers
}
func
(
f
*
errorTestingDockerClient
)
ListContainers
(
options
docker
.
ListContainersOptions
)
([]
docker
.
APIContainers
,
error
)
{
return
f
.
containerList
,
f
.
listContainersError
}
func
TestGetContainerInfo
(
t
*
testing
.
T
)
{
containerID
:=
"ab2cdf"
containerPath
:=
fmt
.
Sprintf
(
"/docker/%v"
,
containerID
)
...
...
@@ -1573,15 +1563,16 @@ func TestGetContainerInfoWhenDockerToolsFailed(t *testing.T) {
testKubelet
:=
newTestKubelet
(
t
)
kubelet
:=
testKubelet
.
kubelet
mockCadvisor
:=
testKubelet
.
fakeCadvisor
fakeDocker
:=
testKubelet
.
fakeDocker
expectedErr
:=
fmt
.
Errorf
(
"List containers error"
)
kubelet
.
dockerClient
=
&
errorTestingDockerClient
{
listContainersError
:
expectedErr
}
fakeDocker
.
Errors
[
"list"
]
=
expectedErr
stats
,
err
:=
kubelet
.
GetContainerInfo
(
"qux"
,
""
,
"foo"
,
nil
)
if
err
==
nil
{
t
.
Errorf
(
"
E
xpected error from dockertools, got none"
)
t
.
Errorf
(
"
e
xpected error from dockertools, got none"
)
}
if
err
.
Error
()
!=
expectedErr
.
Error
()
{
t
.
Errorf
(
"
E
xpected error %v got %v"
,
expectedErr
.
Error
(),
err
.
Error
())
t
.
Errorf
(
"
e
xpected error %v got %v"
,
expectedErr
.
Error
(),
err
.
Error
())
}
if
stats
!=
nil
{
t
.
Errorf
(
"non-nil stats when dockertools failed"
)
...
...
@@ -1594,13 +1585,12 @@ func TestGetContainerInfoWithNoContainers(t *testing.T) {
kubelet
:=
testKubelet
.
kubelet
mockCadvisor
:=
testKubelet
.
fakeCadvisor
kubelet
.
dockerClient
=
&
errorTestingDockerClient
{
listContainersError
:
nil
}
stats
,
err
:=
kubelet
.
GetContainerInfo
(
"qux_ns"
,
""
,
"foo"
,
nil
)
if
err
==
nil
{
t
.
Errorf
(
"
E
xpected error from cadvisor client, got none"
)
t
.
Errorf
(
"
e
xpected error from cadvisor client, got none"
)
}
if
err
!=
Err
NoKubeletContainers
{
t
.
Errorf
(
"
Expected error %v, got %v"
,
ErrNoKubeletContainers
.
Error
(),
err
.
Error
())
if
err
!=
Err
ContainerNotFound
{
t
.
Errorf
(
"
expected error %v, got %v"
,
ErrContainerNotFound
.
Error
(),
err
.
Error
())
}
if
stats
!=
nil
{
t
.
Errorf
(
"non-nil stats when dockertools returned no containers"
)
...
...
@@ -1612,15 +1602,14 @@ func TestGetContainerInfoWithNoMatchingContainers(t *testing.T) {
testKubelet
:=
newTestKubelet
(
t
)
kubelet
:=
testKubelet
.
kubelet
mockCadvisor
:=
testKubelet
.
fakeCadvisor
containerList
:
=
[]
docker
.
APIContainers
{
fakeDocker
:=
testKubelet
.
fakeDocker
fakeDocker
.
ContainerList
=
[]
docker
.
APIContainers
{
{
ID
:
"fakeId"
,
Names
:
[]
string
{
"/k8s_bar_qux_ns_1234_42"
},
},
}
kubelet
.
dockerClient
=
&
errorTestingDockerClient
{
listContainersError
:
nil
,
containerList
:
containerList
}
stats
,
err
:=
kubelet
.
GetContainerInfo
(
"qux_ns"
,
""
,
"foo"
,
nil
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error from cadvisor client, got none"
)
...
...
pkg/kubelet/server.go
View file @
a94aeb27
...
...
@@ -718,7 +718,7 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
switch
err
{
case
nil
:
break
case
Err
NoKubeletContainers
,
Err
ContainerNotFound
:
case
ErrContainerNotFound
:
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusNotFound
)
return
default
:
...
...
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