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
d5eda340
Commit
d5eda340
authored
Feb 16, 2017
by
Guangya Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved code coverage for pkg/kubelet/util.
The test coverage for pkg/kubelet/util.go increased from 45.1% to 84.3%.
parent
a673d997
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
130 additions
and
0 deletions
+130
-0
kubelet_test.go
pkg/kubelet/kubelet_test.go
+130
-0
No files found.
pkg/kubelet/kubelet_test.go
View file @
d5eda340
...
@@ -1039,6 +1039,136 @@ func TestHostNetworkDisallowed(t *testing.T) {
...
@@ -1039,6 +1039,136 @@ func TestHostNetworkDisallowed(t *testing.T) {
assert
.
Error
(
t
,
err
,
"expected pod infra creation to fail"
)
assert
.
Error
(
t
,
err
,
"expected pod infra creation to fail"
)
}
}
func
TestHostPIDAllowed
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
defer
testKubelet
.
Cleanup
()
testKubelet
.
fakeCadvisor
.
On
(
"Start"
)
.
Return
(
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"VersionInfo"
)
.
Return
(
&
cadvisorapi
.
VersionInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"ImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
kubelet
:=
testKubelet
.
kubelet
capabilities
.
SetForTests
(
capabilities
.
Capabilities
{
PrivilegedSources
:
capabilities
.
PrivilegedSources
{
HostPIDSources
:
[]
string
{
kubetypes
.
ApiserverSource
,
kubetypes
.
FileSource
},
},
})
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
Name
:
"foo"
},
},
HostPID
:
true
,
})
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
kubetypes
.
FileSource
kubelet
.
podManager
.
SetPods
([]
*
v1
.
Pod
{
pod
})
err
:=
kubelet
.
syncPod
(
syncPodOptions
{
pod
:
pod
,
podStatus
:
&
kubecontainer
.
PodStatus
{},
updateType
:
kubetypes
.
SyncPodUpdate
,
})
assert
.
NoError
(
t
,
err
,
"expected pod infra creation to succeed"
)
}
func
TestHostPIDDisallowed
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
defer
testKubelet
.
Cleanup
()
testKubelet
.
fakeCadvisor
.
On
(
"Start"
)
.
Return
(
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"VersionInfo"
)
.
Return
(
&
cadvisorapi
.
VersionInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"ImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
kubelet
:=
testKubelet
.
kubelet
capabilities
.
SetForTests
(
capabilities
.
Capabilities
{
PrivilegedSources
:
capabilities
.
PrivilegedSources
{
HostPIDSources
:
[]
string
{},
},
})
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
Name
:
"foo"
},
},
HostPID
:
true
,
})
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
kubetypes
.
FileSource
err
:=
kubelet
.
syncPod
(
syncPodOptions
{
pod
:
pod
,
podStatus
:
&
kubecontainer
.
PodStatus
{},
updateType
:
kubetypes
.
SyncPodUpdate
,
})
assert
.
Error
(
t
,
err
,
"expected pod infra creation to fail"
)
}
func
TestHostIPCAllowed
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
defer
testKubelet
.
Cleanup
()
testKubelet
.
fakeCadvisor
.
On
(
"Start"
)
.
Return
(
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"VersionInfo"
)
.
Return
(
&
cadvisorapi
.
VersionInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"ImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
kubelet
:=
testKubelet
.
kubelet
capabilities
.
SetForTests
(
capabilities
.
Capabilities
{
PrivilegedSources
:
capabilities
.
PrivilegedSources
{
HostIPCSources
:
[]
string
{
kubetypes
.
ApiserverSource
,
kubetypes
.
FileSource
},
},
})
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
Name
:
"foo"
},
},
HostIPC
:
true
,
})
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
kubetypes
.
FileSource
kubelet
.
podManager
.
SetPods
([]
*
v1
.
Pod
{
pod
})
err
:=
kubelet
.
syncPod
(
syncPodOptions
{
pod
:
pod
,
podStatus
:
&
kubecontainer
.
PodStatus
{},
updateType
:
kubetypes
.
SyncPodUpdate
,
})
assert
.
NoError
(
t
,
err
,
"expected pod infra creation to succeed"
)
}
func
TestHostIPCDisallowed
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
defer
testKubelet
.
Cleanup
()
testKubelet
.
fakeCadvisor
.
On
(
"Start"
)
.
Return
(
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"VersionInfo"
)
.
Return
(
&
cadvisorapi
.
VersionInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"ImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
kubelet
:=
testKubelet
.
kubelet
capabilities
.
SetForTests
(
capabilities
.
Capabilities
{
PrivilegedSources
:
capabilities
.
PrivilegedSources
{
HostIPCSources
:
[]
string
{},
},
})
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
Name
:
"foo"
},
},
HostIPC
:
true
,
})
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
kubetypes
.
FileSource
err
:=
kubelet
.
syncPod
(
syncPodOptions
{
pod
:
pod
,
podStatus
:
&
kubecontainer
.
PodStatus
{},
updateType
:
kubetypes
.
SyncPodUpdate
,
})
assert
.
Error
(
t
,
err
,
"expected pod infra creation to fail"
)
}
func
TestPrivilegeContainerAllowed
(
t
*
testing
.
T
)
{
func
TestPrivilegeContainerAllowed
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
defer
testKubelet
.
Cleanup
()
defer
testKubelet
.
Cleanup
()
...
...
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