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
7fed242d
Commit
7fed242d
authored
Dec 13, 2016
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only create the symlink when container log path exists
parent
d306acca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
10 deletions
+54
-10
docker_container.go
pkg/kubelet/dockershim/docker_container.go
+28
-2
docker_manager.go
pkg/kubelet/dockertools/docker_manager.go
+26
-8
No files found.
pkg/kubelet/dockershim/docker_container.go
View file @
7fed242d
...
@@ -32,6 +32,10 @@ import (
...
@@ -32,6 +32,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
)
)
const
(
dockerDefaultLoggingDriver
=
"json-file"
)
// ListContainers lists all containers matching the filter.
// ListContainers lists all containers matching the filter.
func
(
ds
*
dockerService
)
ListContainers
(
filter
*
runtimeapi
.
ContainerFilter
)
([]
*
runtimeapi
.
Container
,
error
)
{
func
(
ds
*
dockerService
)
ListContainers
(
filter
*
runtimeapi
.
ContainerFilter
)
([]
*
runtimeapi
.
Container
,
error
)
{
opts
:=
dockertypes
.
ContainerListOptions
{
All
:
true
}
opts
:=
dockertypes
.
ContainerListOptions
{
All
:
true
}
...
@@ -217,13 +221,35 @@ func (ds *dockerService) createContainerLogSymlink(containerID string) error {
...
@@ -217,13 +221,35 @@ func (ds *dockerService) createContainerLogSymlink(containerID string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get container %q log path: %v"
,
containerID
,
err
)
return
fmt
.
Errorf
(
"failed to get container %q log path: %v"
,
containerID
,
err
)
}
}
if
path
!=
""
&&
realPath
!=
""
{
// Only create the symlink when container log path is specified.
if
path
==
""
{
glog
.
V
(
5
)
.
Infof
(
"Container %s log path isn't specified, will not create the symlink"
,
containerID
)
return
nil
}
if
realPath
!=
""
{
// Only create the symlink when container log path is specified and log file exists.
if
err
=
ds
.
os
.
Symlink
(
realPath
,
path
);
err
!=
nil
{
if
err
=
ds
.
os
.
Symlink
(
realPath
,
path
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create symbolic link %q to the container log file %q for container %q: %v"
,
return
fmt
.
Errorf
(
"failed to create symbolic link %q to the container log file %q for container %q: %v"
,
path
,
realPath
,
containerID
,
err
)
path
,
realPath
,
containerID
,
err
)
}
}
}
else
{
dockerLoggingDriver
:=
""
dockerInfo
,
err
:=
ds
.
client
.
Info
()
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to execute Info() call to the Docker client: %v"
,
err
)
}
else
{
dockerLoggingDriver
=
dockerInfo
.
LoggingDriver
glog
.
V
(
10
)
.
Infof
(
"Docker logging driver is %s"
,
dockerLoggingDriver
)
}
if
dockerLoggingDriver
==
dockerDefaultLoggingDriver
{
glog
.
Errorf
(
"Cannot create symbolic link because container log file doesn't exist!"
)
}
else
{
glog
.
V
(
5
)
.
Infof
(
"Unsupported logging driver: %s"
,
dockerLoggingDriver
)
}
}
}
return
nil
return
nil
}
}
...
...
pkg/kubelet/dockertools/docker_manager.go
View file @
7fed242d
...
@@ -78,7 +78,8 @@ import (
...
@@ -78,7 +78,8 @@ import (
)
)
const
(
const
(
DockerType
=
"docker"
DockerType
=
"docker"
dockerDefaultLoggingDriver
=
"json-file"
// https://docs.docker.com/engine/reference/api/docker_remote_api/
// https://docs.docker.com/engine/reference/api/docker_remote_api/
// docker version should be at least 1.9.x
// docker version should be at least 1.9.x
...
@@ -1793,14 +1794,31 @@ func (dm *DockerManager) runContainerInPod(pod *v1.Pod, container *v1.Container,
...
@@ -1793,14 +1794,31 @@ func (dm *DockerManager) runContainerInPod(pod *v1.Pod, container *v1.Container,
return
kubecontainer
.
ContainerID
{},
fmt
.
Errorf
(
"InspectContainer: %v"
,
err
)
return
kubecontainer
.
ContainerID
{},
fmt
.
Errorf
(
"InspectContainer: %v"
,
err
)
}
}
// Create a symbolic link to the Docker container log file using a name which captures the
// full pod name, the container name and the Docker container ID. Cluster level logging will
// capture these symbolic filenames which can be used for search terms in Elasticsearch or for
// labels for Cloud Logging.
containerLogFile
:=
containerInfo
.
LogPath
containerLogFile
:=
containerInfo
.
LogPath
symlinkFile
:=
LogSymlink
(
dm
.
containerLogsDir
,
kubecontainer
.
GetPodFullName
(
pod
),
container
.
Name
,
id
.
ID
)
if
containerLogFile
!=
""
{
if
err
=
dm
.
os
.
Symlink
(
containerLogFile
,
symlinkFile
);
err
!=
nil
{
// Create a symbolic link to the Docker container log file using a name which captures the
glog
.
Errorf
(
"Failed to create symbolic link to the log file of pod %q container %q: %v"
,
format
.
Pod
(
pod
),
container
.
Name
,
err
)
// full pod name, the container name and the Docker container ID. Cluster level logging will
// capture these symbolic filenames which can be used for search terms in Elasticsearch or for
// labels for Cloud Logging.
symlinkFile
:=
LogSymlink
(
dm
.
containerLogsDir
,
kubecontainer
.
GetPodFullName
(
pod
),
container
.
Name
,
id
.
ID
)
if
err
=
dm
.
os
.
Symlink
(
containerLogFile
,
symlinkFile
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to create symbolic link to the log file of pod %q container %q: %v"
,
format
.
Pod
(
pod
),
container
.
Name
,
err
)
}
}
else
{
dockerLoggingDriver
:=
""
dockerInfo
,
err
:=
dm
.
client
.
Info
()
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to execute Info() call to the Docker client: %v"
,
err
)
}
else
{
dockerLoggingDriver
=
dockerInfo
.
LoggingDriver
glog
.
V
(
10
)
.
Infof
(
"Docker logging driver is %s"
,
dockerLoggingDriver
)
}
if
dockerLoggingDriver
==
dockerDefaultLoggingDriver
{
glog
.
Errorf
(
"Cannot create symbolic link because container log file doesn't exist!"
)
}
else
{
glog
.
V
(
5
)
.
Infof
(
"Unsupported logging driver: %s"
,
dockerLoggingDriver
)
}
}
}
// Check if current docker version is higher than 1.10. Otherwise, we have to apply OOMScoreAdj instead of using docker API.
// Check if current docker version is higher than 1.10. Otherwise, we have to apply OOMScoreAdj instead of using docker API.
...
...
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