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
dced58dc
Unverified
Commit
dced58dc
authored
Jan 16, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Jan 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71892 from fatsheep9146/log_path_test
add test for CRI log path
parents
d857790d
77eadd37
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
65 deletions
+88
-65
log_path_test.go
test/e2e_node/log_path_test.go
+88
-65
No files found.
test/e2e_node/log_path_test.go
View file @
dced58dc
...
@@ -17,62 +17,30 @@ limitations under the License.
...
@@ -17,62 +17,30 @@ limitations under the License.
package
e2e_node
package
e2e_node
import
(
import
(
.
"github.com/onsi/ginkgo"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/kubernetes/pkg/kubelet"
"k8s.io/kubernetes/pkg/kubelet"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework"
.
"github.com/onsi/ginkgo"
)
)
const
(
const
(
logString
=
"This is the expected log content of this node e2e test"
logString
=
"This is the expected log content of this node e2e test"
logContainerName
=
"logger"
logPodName
=
"logger-pod"
logContName
=
"logger-container"
checkPodName
=
"checker-pod"
checkContName
=
"checker-container"
)
)
var
_
=
framework
.
KubeDescribe
(
"ContainerLogPath [NodeConformance]"
,
func
()
{
var
_
=
framework
.
KubeDescribe
(
"ContainerLogPath [NodeConformance]"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"kubelet-container-log-path"
)
f
:=
framework
.
NewDefaultFramework
(
"kubelet-container-log-path"
)
var
podClient
*
framework
.
PodClient
Describe
(
"Pod with a container"
,
func
()
{
Describe
(
"Pod with a container"
,
func
()
{
Context
(
"printed log to stdout"
,
func
()
{
Context
(
"printed log to stdout"
,
func
()
{
BeforeEach
(
func
()
{
makeLogPod
:=
func
(
podName
,
log
string
)
*
v1
.
Pod
{
if
framework
.
TestContext
.
ContainerRuntime
==
"docker"
{
return
&
v1
.
Pod
{
// Container Log Path support requires JSON logging driver.
// It does not work when Docker daemon is logging to journald.
d
,
err
:=
getDockerLoggingDriver
()
framework
.
ExpectNoError
(
err
)
if
d
!=
"json-file"
{
framework
.
Skipf
(
"Skipping because Docker daemon is using a logging driver other than
\"
json-file
\"
: %s"
,
d
)
}
// Even if JSON logging is in use, this test fails if SELinux support
// is enabled, since the isolation provided by the SELinux policy
// prevents processes running inside Docker containers (under SELinux
// type svirt_lxc_net_t) from accessing the log files which are owned
// by Docker (and labeled with the container_var_lib_t type.)
//
// Therefore, let's also skip this test when running with SELinux
// support enabled.
e
,
err
:=
isDockerSELinuxSupportEnabled
()
framework
.
ExpectNoError
(
err
)
if
e
{
framework
.
Skipf
(
"Skipping because Docker daemon is running with SELinux support enabled"
)
}
}
})
It
(
"should print log to correct log path"
,
func
()
{
podClient
:=
f
.
PodClient
()
ns
:=
f
.
Namespace
.
Name
logDirVolumeName
:=
"log-dir-vol"
logDir
:=
kubelet
.
ContainerLogsDir
logPod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
logP
odName
,
Name
:
p
odName
,
},
},
Spec
:
v1
.
PodSpec
{
Spec
:
v1
.
PodSpec
{
// this pod is expected to exit successfully
// this pod is expected to exit successfully
...
@@ -80,30 +48,21 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
...
@@ -80,30 +48,21 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
Containers
:
[]
v1
.
Container
{
Containers
:
[]
v1
.
Container
{
{
{
Image
:
busyboxImage
,
Image
:
busyboxImage
,
Name
:
logContName
,
Name
:
logCont
ainer
Name
,
Command
:
[]
string
{
"sh"
,
"-c"
,
"echo "
+
log
String
},
Command
:
[]
string
{
"sh"
,
"-c"
,
"echo "
+
log
},
},
},
},
},
},
},
}
}
}
podClient
.
Create
(
logPod
)
makeLogCheckPod
:=
func
(
podName
,
log
,
expectedLogPath
string
)
*
v1
.
Pod
{
err
:=
framework
.
WaitForPodSuccessInNamespace
(
f
.
ClientSet
,
logPodName
,
ns
)
framework
.
ExpectNoError
(
err
,
"Failed waiting for pod: %s to enter success state"
,
logPodName
)
// get containerID from created Pod
createdLogPod
,
err
:=
podClient
.
Get
(
logPodName
,
metav1
.
GetOptions
{})
logConID
:=
kubecontainer
.
ParseContainerID
(
createdLogPod
.
Status
.
ContainerStatuses
[
0
]
.
ContainerID
)
framework
.
ExpectNoError
(
err
,
"Failed to get pod: %s"
,
logPodName
)
expectedlogFile
:=
logDir
+
"/"
+
logPodName
+
"_"
+
ns
+
"_"
+
logContName
+
"-"
+
logConID
.
ID
+
".log"
hostPathType
:=
new
(
v1
.
HostPathType
)
hostPathType
:=
new
(
v1
.
HostPathType
)
*
hostPathType
=
v1
.
HostPathType
(
string
(
v1
.
HostPathFileOrCreate
))
*
hostPathType
=
v1
.
HostPathType
(
string
(
v1
.
HostPathFileOrCreate
))
checkPod
:=
&
v1
.
Pod
{
return
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
checkP
odName
,
Name
:
p
odName
,
},
},
Spec
:
v1
.
PodSpec
{
Spec
:
v1
.
PodSpec
{
// this pod is expected to exit successfully
// this pod is expected to exit successfully
...
@@ -111,15 +70,15 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
...
@@ -111,15 +70,15 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
Containers
:
[]
v1
.
Container
{
Containers
:
[]
v1
.
Container
{
{
{
Image
:
busyboxImage
,
Image
:
busyboxImage
,
Name
:
checkCont
Name
,
Name
:
pod
Name
,
// If we find expected log file and contains right content, exit 0
// If we find expected log file and contains right content, exit 0
// else, keep checking until test timeout
// else, keep checking until test timeout
Command
:
[]
string
{
"sh"
,
"-c"
,
"while true; do if [ -e "
+
expected
logFile
+
" ] && grep -q "
+
logString
+
" "
+
expectedlogFile
+
"; then exit 0; fi; sleep 1; done"
},
Command
:
[]
string
{
"sh"
,
"-c"
,
"while true; do if [ -e "
+
expected
LogPath
+
" ] && grep -q "
+
log
+
" "
+
expectedLogPath
+
"; then exit 0; fi; sleep 1; done"
},
VolumeMounts
:
[]
v1
.
VolumeMount
{
VolumeMounts
:
[]
v1
.
VolumeMount
{
{
{
Name
:
logDirVolumeName
,
Name
:
"logdir"
,
// mount ContainerLogsDir to the same path in container
// mount ContainerLogsDir to the same path in container
MountPath
:
expected
logFile
,
MountPath
:
expected
LogPath
,
ReadOnly
:
true
,
ReadOnly
:
true
,
},
},
},
},
...
@@ -127,10 +86,10 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
...
@@ -127,10 +86,10 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
},
},
Volumes
:
[]
v1
.
Volume
{
Volumes
:
[]
v1
.
Volume
{
{
{
Name
:
logDirVolumeName
,
Name
:
"logdir"
,
VolumeSource
:
v1
.
VolumeSource
{
VolumeSource
:
v1
.
VolumeSource
{
HostPath
:
&
v1
.
HostPathVolumeSource
{
HostPath
:
&
v1
.
HostPathVolumeSource
{
Path
:
expected
logFile
,
Path
:
expected
LogPath
,
Type
:
hostPathType
,
Type
:
hostPathType
,
},
},
},
},
...
@@ -138,10 +97,74 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
...
@@ -138,10 +97,74 @@ var _ = framework.KubeDescribe("ContainerLogPath [NodeConformance]", func() {
},
},
},
},
}
}
}
createAndWaitPod
:=
func
(
pod
*
v1
.
Pod
)
error
{
podClient
.
Create
(
pod
)
return
framework
.
WaitForPodSuccessInNamespace
(
f
.
ClientSet
,
pod
.
Name
,
f
.
Namespace
.
Name
)
}
var
logPodName
string
BeforeEach
(
func
()
{
if
framework
.
TestContext
.
ContainerRuntime
==
"docker"
{
// Container Log Path support requires JSON logging driver.
// It does not work when Docker daemon is logging to journald.
d
,
err
:=
getDockerLoggingDriver
()
framework
.
ExpectNoError
(
err
)
if
d
!=
"json-file"
{
framework
.
Skipf
(
"Skipping because Docker daemon is using a logging driver other than
\"
json-file
\"
: %s"
,
d
)
}
// Even if JSON logging is in use, this test fails if SELinux support
// is enabled, since the isolation provided by the SELinux policy
// prevents processes running inside Docker containers (under SELinux
// type svirt_lxc_net_t) from accessing the log files which are owned
// by Docker (and labeled with the container_var_lib_t type.)
//
// Therefore, let's also skip this test when running with SELinux
// support enabled.
e
,
err
:=
isDockerSELinuxSupportEnabled
()
framework
.
ExpectNoError
(
err
)
if
e
{
framework
.
Skipf
(
"Skipping because Docker daemon is running with SELinux support enabled"
)
}
}
podClient
=
f
.
PodClient
()
logPodName
=
"log-pod-"
+
string
(
uuid
.
NewUUID
())
err
:=
createAndWaitPod
(
makeLogPod
(
logPodName
,
logString
))
framework
.
ExpectNoError
(
err
,
"Failed waiting for pod: %s to enter success state"
,
logPodName
)
})
It
(
"should print log to correct log path"
,
func
()
{
logDir
:=
kubelet
.
ContainerLogsDir
// get containerID from created Pod
createdLogPod
,
err
:=
podClient
.
Get
(
logPodName
,
metav1
.
GetOptions
{})
logContainerID
:=
kubecontainer
.
ParseContainerID
(
createdLogPod
.
Status
.
ContainerStatuses
[
0
]
.
ContainerID
)
framework
.
ExpectNoError
(
err
,
"Failed to get pod: %s"
,
logPodName
)
// build log file path
expectedlogFile
:=
logDir
+
"/"
+
logPodName
+
"_"
+
f
.
Namespace
.
Name
+
"_"
+
logContainerName
+
"-"
+
logContainerID
.
ID
+
".log"
logCheckPodName
:=
"log-check-"
+
string
(
uuid
.
NewUUID
())
err
=
createAndWaitPod
(
makeLogCheckPod
(
logCheckPodName
,
logString
,
expectedlogFile
))
framework
.
ExpectNoError
(
err
,
"Failed waiting for pod: %s to enter success state"
,
logCheckPodName
)
})
It
(
"should print log to correct cri log path"
,
func
()
{
logCRIDir
:=
"/var/log/pods"
// get podID from created Pod
createdLogPod
,
err
:=
podClient
.
Get
(
logPodName
,
metav1
.
GetOptions
{})
podID
:=
string
(
createdLogPod
.
UID
)
// build log cri file path
expectedCRILogFile
:=
logCRIDir
+
"/"
+
podID
+
"/"
+
logContainerName
+
"/0.log"
podClient
.
Create
(
checkPod
)
logCRICheckPodName
:=
"log-cri-check-"
+
string
(
uuid
.
NewUUID
()
)
err
=
framework
.
WaitForPodSuccessInNamespace
(
f
.
ClientSet
,
checkPodName
,
ns
)
err
=
createAndWaitPod
(
makeLogCheckPod
(
logCRICheckPodName
,
logString
,
expectedCRILogFile
)
)
framework
.
ExpectNoError
(
err
,
"Failed waiting for pod: %s to enter success state"
,
c
heckPodName
)
framework
.
ExpectNoError
(
err
,
"Failed waiting for pod: %s to enter success state"
,
logCRIC
heckPodName
)
})
})
})
})
})
})
...
...
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