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
894dc5a5
Commit
894dc5a5
authored
Nov 02, 2015
by
Lantao Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move TerminationMessagePath into docker label.
parent
5881c3c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
3 deletions
+62
-3
labels.go
pkg/kubelet/dockertools/labels.go
+15
-1
manager.go
pkg/kubelet/dockertools/manager.go
+9
-2
manager_test.go
pkg/kubelet/dockertools/manager_test.go
+38
-0
No files found.
pkg/kubelet/dockertools/labels.go
View file @
894dc5a5
...
...
@@ -32,10 +32,12 @@ const (
kubernetesPodNamespaceLabel
=
"io.kubernetes.pod.namespace"
kubernetesPodUID
=
"io.kubernetes.pod.uid"
kubernetesContainerRestartCountLabel
=
"io.kubernetes.container.restartCount"
kubernetesContainerTerminationMessagePath
=
"io.kubernetes.container.terminationMessagePath"
kubernetesPodLabel
=
"io.kubernetes.pod.data"
kubernetesTerminationGracePeriodLabel
=
"io.kubernetes.pod.terminationGracePeriod"
kubernetesContainerLabel
=
"io.kubernetes.container.name"
kubernetesContainerRestartCountLabel
=
"io.kubernetes.container.restartCount"
)
func
newLabels
(
container
*
api
.
Container
,
pod
*
api
.
Pod
,
restartCount
int
)
map
[
string
]
string
{
...
...
@@ -46,6 +48,7 @@ func newLabels(container *api.Container, pod *api.Pod, restartCount int) map[str
labels
[
kubernetesPodUID
]
=
string
(
pod
.
UID
)
labels
[
kubernetesContainerRestartCountLabel
]
=
strconv
.
Itoa
(
restartCount
)
labels
[
kubernetesContainerTerminationMessagePath
]
=
container
.
TerminationMessagePath
return
labels
}
...
...
@@ -65,3 +68,14 @@ func getRestartCountFromLabel(labels map[string]string) (restartCount int, err e
}
return
restartCount
,
err
}
func
getTerminationMessagePathFromLabel
(
labels
map
[
string
]
string
)
string
{
if
terminationMessagePath
,
found
:=
labels
[
kubernetesContainerTerminationMessagePath
];
found
{
return
terminationMessagePath
}
else
{
// Do not report error, because there should be many old containers without this label now.
// Return empty string "" for these containers, the caller will get terminationMessagePath by other ways.
glog
.
V
(
3
)
.
Infof
(
"Container doesn't have label %s, it may be an old or invalid container"
,
kubernetesContainerTerminationMessagePath
)
return
""
}
}
pkg/kubelet/dockertools/manager.go
View file @
894dc5a5
...
...
@@ -338,6 +338,7 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont
return
result
}
// TODO (random-liu) Remove parameter tPath when old containers are deprecated.
func
(
dm
*
DockerManager
)
inspectContainer
(
dockerID
,
containerName
,
tPath
string
,
pod
*
api
.
Pod
)
*
containerStatusResult
{
result
:=
containerStatusResult
{
api
.
ContainerStatus
{},
""
,
nil
}
...
...
@@ -408,8 +409,14 @@ func (dm *DockerManager) inspectContainer(dockerID, containerName, tPath string,
FinishedAt
:
finishedAt
,
ContainerID
:
DockerPrefix
+
dockerID
,
}
if
tPath
!=
""
{
path
,
found
:=
inspectResult
.
Volumes
[
tPath
]
terminationMessagePath
:=
getTerminationMessagePathFromLabel
(
inspectResult
.
Config
.
Labels
)
if
terminationMessagePath
==
""
{
// Because old containers have no terminationMessagePath Label, we stil have to rely on the information from apiserver here.
// TODO (random-liu) Remove this later when old containers with no labels are deprecated.
terminationMessagePath
=
tPath
}
if
terminationMessagePath
!=
""
{
path
,
found
:=
inspectResult
.
Volumes
[
terminationMessagePath
]
if
found
{
data
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
...
...
pkg/kubelet/dockertools/manager_test.go
View file @
894dc5a5
...
...
@@ -1600,6 +1600,44 @@ func TestGetRestartCount(t *testing.T) {
pod
.
Status
=
verifyRestartCount
(
&
pod
,
4
)
}
func
TestGetTerminationMessagePath
(
t
*
testing
.
T
)
{
dm
,
fakeDocker
:=
newTestDockerManager
()
containers
:=
[]
api
.
Container
{
{
Name
:
"bar"
,
TerminationMessagePath
:
"/dev/somepath"
,
},
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345678"
,
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
containers
,
},
}
fakeDocker
.
ContainerMap
=
map
[
string
]
*
docker
.
Container
{}
runSyncPod
(
t
,
dm
,
fakeDocker
,
pod
,
nil
)
containerList
:=
fakeDocker
.
ContainerList
if
len
(
containerList
)
!=
2
{
// One for infra container, one for container "bar"
t
.
Fatalf
(
"unexpected container list length %d"
,
len
(
containerList
))
}
inspectResult
,
err
:=
dm
.
client
.
InspectContainer
(
containerList
[
0
]
.
ID
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected inspect error %v"
,
err
)
}
terminationMessagePath
:=
getTerminationMessagePathFromLabel
(
inspectResult
.
Config
.
Labels
)
if
terminationMessagePath
!=
containers
[
0
]
.
TerminationMessagePath
{
t
.
Errorf
(
"expected termination message path %s, got %s"
,
containers
[
0
]
.
TerminationMessagePath
,
terminationMessagePath
)
}
}
func
TestSyncPodWithPodInfraCreatesContainerCallsHandler
(
t
*
testing
.
T
)
{
fakeHTTPClient
:=
&
fakeHTTP
{}
dm
,
fakeDocker
:=
newTestDockerManagerWithHTTPClient
(
fakeHTTPClient
)
...
...
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