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
25f37007
Commit
25f37007
authored
May 12, 2016
by
Saad Ali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24846 from pmorie/kubelet-test-loc
Reduce LOC in kubelet tests
parents
19169889
d1e0e726
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
198 additions
and
467 deletions
+198
-467
docker_test.go
pkg/kubelet/dockertools/docker_test.go
+28
-54
kubelet_test.go
pkg/kubelet/kubelet_test.go
+166
-385
pod_workers_test.go
pkg/kubelet/pod_workers_test.go
+4
-28
No files found.
pkg/kubelet/dockertools/docker_test.go
View file @
25f37007
...
@@ -674,37 +674,29 @@ func TestFindContainersByPod(t *testing.T) {
...
@@ -674,37 +674,29 @@ func TestFindContainersByPod(t *testing.T) {
}
}
func
TestMakePortsAndBindings
(
t
*
testing
.
T
)
{
func
TestMakePortsAndBindings
(
t
*
testing
.
T
)
{
portMapping
:=
func
(
container
,
host
int
,
protocol
api
.
Protocol
,
ip
string
)
kubecontainer
.
PortMapping
{
return
kubecontainer
.
PortMapping
{
ContainerPort
:
container
,
HostPort
:
host
,
Protocol
:
protocol
,
HostIP
:
ip
,
}
}
portBinding
:=
func
(
port
,
ip
string
)
dockernat
.
PortBinding
{
return
dockernat
.
PortBinding
{
HostPort
:
port
,
HostIP
:
ip
,
}
}
ports
:=
[]
kubecontainer
.
PortMapping
{
ports
:=
[]
kubecontainer
.
PortMapping
{
{
portMapping
(
80
,
8080
,
""
,
"127.0.0.1"
),
ContainerPort
:
80
,
portMapping
(
443
,
443
,
"tcp"
,
""
),
HostPort
:
8080
,
portMapping
(
444
,
444
,
"udp"
,
""
),
HostIP
:
"127.0.0.1"
,
portMapping
(
445
,
445
,
"foobar"
,
""
),
},
portMapping
(
443
,
446
,
"tcp"
,
""
),
{
portMapping
(
443
,
446
,
"udp"
,
""
),
ContainerPort
:
443
,
HostPort
:
443
,
Protocol
:
"tcp"
,
},
{
ContainerPort
:
444
,
HostPort
:
444
,
Protocol
:
"udp"
,
},
{
ContainerPort
:
445
,
HostPort
:
445
,
Protocol
:
"foobar"
,
},
{
ContainerPort
:
443
,
HostPort
:
446
,
Protocol
:
"tcp"
,
},
{
ContainerPort
:
443
,
HostPort
:
446
,
Protocol
:
"udp"
,
},
}
}
exposedPorts
,
bindings
:=
makePortsAndBindings
(
ports
)
exposedPorts
,
bindings
:=
makePortsAndBindings
(
ports
)
...
@@ -725,38 +717,20 @@ func TestMakePortsAndBindings(t *testing.T) {
...
@@ -725,38 +717,20 @@ func TestMakePortsAndBindings(t *testing.T) {
// Construct expected bindings
// Construct expected bindings
expectPortBindings
:=
map
[
string
][]
dockernat
.
PortBinding
{
expectPortBindings
:=
map
[
string
][]
dockernat
.
PortBinding
{
"80/tcp"
:
{
"80/tcp"
:
{
dockernat
.
PortBinding
{
portBinding
(
"8080"
,
"127.0.0.1"
),
HostPort
:
"8080"
,
HostIP
:
"127.0.0.1"
,
},
},
},
"443/tcp"
:
{
"443/tcp"
:
{
dockernat
.
PortBinding
{
portBinding
(
"443"
,
""
),
HostPort
:
"443"
,
portBinding
(
"446"
,
""
),
HostIP
:
""
,
},
dockernat
.
PortBinding
{
HostPort
:
"446"
,
HostIP
:
""
,
},
},
},
"443/udp"
:
{
"443/udp"
:
{
dockernat
.
PortBinding
{
portBinding
(
"446"
,
""
),
HostPort
:
"446"
,
HostIP
:
""
,
},
},
},
"444/udp"
:
{
"444/udp"
:
{
dockernat
.
PortBinding
{
portBinding
(
"444"
,
""
),
HostPort
:
"444"
,
HostIP
:
""
,
},
},
},
"445/tcp"
:
{
"445/tcp"
:
{
dockernat
.
PortBinding
{
portBinding
(
"445"
,
""
),
HostPort
:
"445"
,
HostIP
:
""
,
},
},
},
}
}
...
...
pkg/kubelet/kubelet_test.go
View file @
25f37007
...
@@ -284,18 +284,11 @@ func TestSyncPodsStartPod(t *testing.T) {
...
@@ -284,18 +284,11 @@ func TestSyncPodsStartPod(t *testing.T) {
kubelet
:=
testKubelet
.
kubelet
kubelet
:=
testKubelet
.
kubelet
fakeRuntime
:=
testKubelet
.
fakeRuntime
fakeRuntime
:=
testKubelet
.
fakeRuntime
pods
:=
[]
*
api
.
Pod
{
pods
:=
[]
*
api
.
Pod
{
{
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Containers
:
[]
api
.
Container
{
UID
:
"12345678"
,
{
Name
:
"bar"
},
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"bar"
},
},
},
},
},
}
)
,
}
}
kubelet
.
podManager
.
SetPods
(
pods
)
kubelet
.
podManager
.
SetPods
(
pods
)
kubelet
.
HandlePodSyncs
(
pods
)
kubelet
.
HandlePodSyncs
(
pods
)
...
@@ -315,8 +308,9 @@ func TestSyncPodsDeletesWhenSourcesAreReady(t *testing.T) {
...
@@ -315,8 +308,9 @@ func TestSyncPodsDeletesWhenSourcesAreReady(t *testing.T) {
fakeRuntime
.
PodList
=
[]
*
kubecontainer
.
Pod
{
fakeRuntime
.
PodList
=
[]
*
kubecontainer
.
Pod
{
{
{
ID
:
"12345678"
,
ID
:
"12345678"
,
Name
:
"foo"
,
Namespace
:
"new"
,
Name
:
"foo"
,
Namespace
:
"new"
,
Containers
:
[]
*
kubecontainer
.
Container
{
Containers
:
[]
*
kubecontainer
.
Container
{
{
Name
:
"bar"
},
{
Name
:
"bar"
},
},
},
...
@@ -339,22 +333,16 @@ func TestMountExternalVolumes(t *testing.T) {
...
@@ -339,22 +333,16 @@ func TestMountExternalVolumes(t *testing.T) {
plug
:=
&
volumetest
.
FakeVolumePlugin
{
PluginName
:
"fake"
,
Host
:
nil
}
plug
:=
&
volumetest
.
FakeVolumePlugin
{
PluginName
:
"fake"
,
Host
:
nil
}
kubelet
.
volumePluginMgr
.
InitPlugins
([]
volume
.
VolumePlugin
{
plug
},
&
volumeHost
{
kubelet
})
kubelet
.
volumePluginMgr
.
InitPlugins
([]
volume
.
VolumePlugin
{
plug
},
&
volumeHost
{
kubelet
})
pod
:=
api
.
Pod
{
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"test"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Volumes
:
[]
api
.
Volume
{
UID
:
"12345678"
,
{
Name
:
"foo"
,
Name
:
"vol1"
,
Namespace
:
"test"
,
VolumeSource
:
api
.
VolumeSource
{},
},
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
{
Name
:
"vol1"
,
VolumeSource
:
api
.
VolumeSource
{},
},
},
},
},
},
}
})
podVolumes
,
err
:=
kubelet
.
mountExternalVolumes
(
&
pod
)
podVolumes
,
err
:=
kubelet
.
mountExternalVolumes
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Expected success: %v"
,
err
)
t
.
Errorf
(
"Expected success: %v"
,
err
)
}
}
...
@@ -473,30 +461,23 @@ func TestCleanupOrphanedVolumes(t *testing.T) {
...
@@ -473,30 +461,23 @@ func TestCleanupOrphanedVolumes(t *testing.T) {
}})
.
ReactionChain
}})
.
ReactionChain
// Create a pod referencing the volume via a PersistentVolumeClaim
// Create a pod referencing the volume via a PersistentVolumeClaim
pod
:=
api
.
Pod
{
pod
:=
podWithUidNameNsSpec
(
"podUID"
,
"pod"
,
"test"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Volumes
:
[]
api
.
Volume
{
UID
:
"podUID"
,
{
Name
:
"pod"
,
Name
:
"myvolumeclaim"
,
Namespace
:
"test"
,
VolumeSource
:
api
.
VolumeSource
{
},
PersistentVolumeClaim
:
&
api
.
PersistentVolumeClaimVolumeSource
{
Spec
:
api
.
PodSpec
{
ClaimName
:
"myclaim"
,
Volumes
:
[]
api
.
Volume
{
{
Name
:
"myvolumeclaim"
,
VolumeSource
:
api
.
VolumeSource
{
PersistentVolumeClaim
:
&
api
.
PersistentVolumeClaimVolumeSource
{
ClaimName
:
"myclaim"
,
},
},
},
},
},
},
},
},
},
}
}
)
// The pod is pending and not running yet. Test that cleanupOrphanedVolumes
// The pod is pending and not running yet. Test that cleanupOrphanedVolumes
// won't remove the volume from disk if the volume is referenced only
// won't remove the volume from disk if the volume is referenced only
// indirectly by a claim.
// indirectly by a claim.
err
:=
kubelet
.
cleanupOrphanedVolumes
([]
*
api
.
Pod
{
&
pod
},
[]
*
kubecontainer
.
Pod
{})
err
:=
kubelet
.
cleanupOrphanedVolumes
([]
*
api
.
Pod
{
pod
},
[]
*
kubecontainer
.
Pod
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"cleanupOrphanedVolumes failed: %v"
,
err
)
t
.
Errorf
(
"cleanupOrphanedVolumes failed: %v"
,
err
)
}
}
...
@@ -1836,11 +1817,7 @@ func TestExecInContainer(t *testing.T) {
...
@@ -1836,11 +1817,7 @@ func TestExecInContainer(t *testing.T) {
}
}
err
:=
kubelet
.
ExecInContainer
(
err
:=
kubelet
.
ExecInContainer
(
kubecontainer
.
GetPodFullName
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
kubecontainer
.
GetPodFullName
(
podWithUidNameNs
(
"12345678"
,
podName
,
podNamespace
)),
UID
:
"12345678"
,
Name
:
podName
,
Namespace
:
podNamespace
,
}}),
""
,
""
,
containerID
,
containerID
,
[]
string
{
"ls"
},
[]
string
{
"ls"
},
...
@@ -2002,22 +1979,8 @@ func TestHandlePortConflicts(t *testing.T) {
...
@@ -2002,22 +1979,8 @@ func TestHandlePortConflicts(t *testing.T) {
spec
:=
api
.
PodSpec
{
NodeName
:
kl
.
nodeName
,
Containers
:
[]
api
.
Container
{{
Ports
:
[]
api
.
ContainerPort
{{
HostPort
:
80
}}}}}
spec
:=
api
.
PodSpec
{
NodeName
:
kl
.
nodeName
,
Containers
:
[]
api
.
Container
{{
Ports
:
[]
api
.
ContainerPort
{{
HostPort
:
80
}}}}}
pods
:=
[]
*
api
.
Pod
{
pods
:=
[]
*
api
.
Pod
{
{
podWithUidNameNsSpec
(
"123456789"
,
"newpod"
,
"foo"
,
spec
),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNsSpec
(
"987654321"
,
"oldpod"
,
"foo"
,
spec
),
UID
:
"123456789"
,
Name
:
"newpod"
,
Namespace
:
"foo"
,
},
Spec
:
spec
,
},
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"987654321"
,
Name
:
"oldpod"
,
Namespace
:
"foo"
,
},
Spec
:
spec
,
},
}
}
// Make sure the Pods are in the reverse order of creation time.
// Make sure the Pods are in the reverse order of creation time.
pods
[
1
]
.
CreationTimestamp
=
unversioned
.
NewTime
(
time
.
Now
())
pods
[
1
]
.
CreationTimestamp
=
unversioned
.
NewTime
(
time
.
Now
())
...
@@ -2075,29 +2038,10 @@ func TestHandleHostNameConflicts(t *testing.T) {
...
@@ -2075,29 +2038,10 @@ func TestHandleHostNameConflicts(t *testing.T) {
},
},
}}
}}
// default NodeName in test is 127.0.0.1
pods
:=
[]
*
api
.
Pod
{
pods
:=
[]
*
api
.
Pod
{
{
podWithUidNameNsSpec
(
"123456789"
,
"notfittingpod"
,
"foo"
,
api
.
PodSpec
{
NodeName
:
"127.0.0.2"
}),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNsSpec
(
"987654321"
,
"fittingpod"
,
"foo"
,
api
.
PodSpec
{
NodeName
:
"127.0.0.1"
}),
UID
:
"123456789"
,
Name
:
"notfittingpod"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
PodSpec
{
// default NodeName in test is 127.0.0.1
NodeName
:
"127.0.0.2"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"987654321"
,
Name
:
"fittingpod"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
PodSpec
{
// default NodeName in test is 127.0.0.1
NodeName
:
"127.0.0.1"
,
},
},
}
}
notfittingPod
:=
pods
[
0
]
notfittingPod
:=
pods
[
0
]
...
@@ -2143,22 +2087,8 @@ func TestHandleNodeSelector(t *testing.T) {
...
@@ -2143,22 +2087,8 @@ func TestHandleNodeSelector(t *testing.T) {
testKubelet
.
fakeCadvisor
.
On
(
"DockerImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"DockerImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
pods
:=
[]
*
api
.
Pod
{
pods
:=
[]
*
api
.
Pod
{
{
podWithUidNameNsSpec
(
"123456789"
,
"podA"
,
"foo"
,
api
.
PodSpec
{
NodeSelector
:
map
[
string
]
string
{
"key"
:
"A"
}}),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNsSpec
(
"987654321"
,
"podB"
,
"foo"
,
api
.
PodSpec
{
NodeSelector
:
map
[
string
]
string
{
"key"
:
"B"
}}),
UID
:
"123456789"
,
Name
:
"podA"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
PodSpec
{
NodeSelector
:
map
[
string
]
string
{
"key"
:
"A"
}},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"987654321"
,
Name
:
"podB"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
PodSpec
{
NodeSelector
:
map
[
string
]
string
{
"key"
:
"B"
}},
},
}
}
// The first pod should be rejected.
// The first pod should be rejected.
notfittingPod
:=
pods
[
0
]
notfittingPod
:=
pods
[
0
]
...
@@ -2209,22 +2139,8 @@ func TestHandleMemExceeded(t *testing.T) {
...
@@ -2209,22 +2139,8 @@ func TestHandleMemExceeded(t *testing.T) {
},
},
}}}}
}}}}
pods
:=
[]
*
api
.
Pod
{
pods
:=
[]
*
api
.
Pod
{
{
podWithUidNameNsSpec
(
"123456789"
,
"newpod"
,
"foo"
,
spec
),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNsSpec
(
"987654321"
,
"oldpod"
,
"foo"
,
spec
),
UID
:
"123456789"
,
Name
:
"newpod"
,
Namespace
:
"foo"
,
},
Spec
:
spec
,
},
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"987654321"
,
Name
:
"oldpod"
,
Namespace
:
"foo"
,
},
Spec
:
spec
,
},
}
}
// Make sure the Pods are in the reverse order of creation time.
// Make sure the Pods are in the reverse order of creation time.
pods
[
1
]
.
CreationTimestamp
=
unversioned
.
NewTime
(
time
.
Now
())
pods
[
1
]
.
CreationTimestamp
=
unversioned
.
NewTime
(
time
.
Now
())
...
@@ -3104,16 +3020,8 @@ func TestCreateMirrorPod(t *testing.T) {
...
@@ -3104,16 +3020,8 @@ func TestCreateMirrorPod(t *testing.T) {
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
kl
:=
testKubelet
.
kubelet
kl
:=
testKubelet
.
kubelet
manager
:=
testKubelet
.
fakeMirrorClient
manager
:=
testKubelet
.
fakeMirrorClient
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNs
(
"12345678"
,
"bar"
,
"foo"
)
ObjectMeta
:
api
.
ObjectMeta
{
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
"file"
UID
:
"12345678"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Annotations
:
map
[
string
]
string
{
kubetypes
.
ConfigSourceAnnotationKey
:
"file"
,
},
},
}
pods
:=
[]
*
api
.
Pod
{
pod
}
pods
:=
[]
*
api
.
Pod
{
pod
}
kl
.
podManager
.
SetPods
(
pods
)
kl
.
podManager
.
SetPods
(
pods
)
err
:=
kl
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
updateType
)
err
:=
kl
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
updateType
)
...
@@ -3139,38 +3047,21 @@ func TestDeleteOutdatedMirrorPod(t *testing.T) {
...
@@ -3139,38 +3047,21 @@ func TestDeleteOutdatedMirrorPod(t *testing.T) {
kl
:=
testKubelet
.
kubelet
kl
:=
testKubelet
.
kubelet
manager
:=
testKubelet
.
fakeMirrorClient
manager
:=
testKubelet
.
fakeMirrorClient
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"ns"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Containers
:
[]
api
.
Container
{
UID
:
"12345678"
,
{
Name
:
"1234"
,
Image
:
"foo"
},
Name
:
"foo"
,
Namespace
:
"ns"
,
Annotations
:
map
[
string
]
string
{
kubetypes
.
ConfigSourceAnnotationKey
:
"file"
,
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"1234"
,
Image
:
"foo"
},
},
},
},
}
})
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
"file"
// Mirror pod has an outdated spec.
// Mirror pod has an outdated spec.
mirrorPod
:=
&
api
.
Pod
{
mirrorPod
:=
podWithUidNameNsSpec
(
"11111111"
,
"foo"
,
"ns"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Containers
:
[]
api
.
Container
{
UID
:
"11111111"
,
{
Name
:
"1234"
,
Image
:
"bar"
},
Name
:
"foo"
,
Namespace
:
"ns"
,
Annotations
:
map
[
string
]
string
{
kubetypes
.
ConfigSourceAnnotationKey
:
"api"
,
kubetypes
.
ConfigMirrorAnnotationKey
:
"mirror"
,
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"1234"
,
Image
:
"bar"
},
},
},
},
}
})
mirrorPod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
"api"
mirrorPod
.
Annotations
[
kubetypes
.
ConfigMirrorAnnotationKey
]
=
"mirror"
pods
:=
[]
*
api
.
Pod
{
pod
,
mirrorPod
}
pods
:=
[]
*
api
.
Pod
{
pod
,
mirrorPod
}
kl
.
podManager
.
SetPods
(
pods
)
kl
.
podManager
.
SetPods
(
pods
)
...
@@ -3321,24 +3212,16 @@ func TestHostNetworkAllowed(t *testing.T) {
...
@@ -3321,24 +3212,16 @@ func TestHostNetworkAllowed(t *testing.T) {
HostNetworkSources
:
[]
string
{
kubetypes
.
ApiserverSource
,
kubetypes
.
FileSource
},
HostNetworkSources
:
[]
string
{
kubetypes
.
ApiserverSource
,
kubetypes
.
FileSource
},
},
},
})
})
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Containers
:
[]
api
.
Container
{
UID
:
"12345678"
,
{
Name
:
"foo"
},
Name
:
"foo"
,
Namespace
:
"new"
,
Annotations
:
map
[
string
]
string
{
kubetypes
.
ConfigSourceAnnotationKey
:
kubetypes
.
FileSource
,
},
},
},
Spec
:
api
.
PodSpec
{
SecurityContext
:
&
api
.
PodSecurityContext
{
Containers
:
[]
api
.
Container
{
HostNetwork
:
true
,
{
Name
:
"foo"
},
},
SecurityContext
:
&
api
.
PodSecurityContext
{
HostNetwork
:
true
,
},
},
},
}
})
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
kubetypes
.
FileSource
kubelet
.
podManager
.
SetPods
([]
*
api
.
Pod
{
pod
})
kubelet
.
podManager
.
SetPods
([]
*
api
.
Pod
{
pod
})
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -3355,24 +3238,16 @@ func TestHostNetworkDisallowed(t *testing.T) {
...
@@ -3355,24 +3238,16 @@ func TestHostNetworkDisallowed(t *testing.T) {
HostNetworkSources
:
[]
string
{},
HostNetworkSources
:
[]
string
{},
},
},
})
})
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Containers
:
[]
api
.
Container
{
UID
:
"12345678"
,
{
Name
:
"foo"
},
Name
:
"foo"
,
Namespace
:
"new"
,
Annotations
:
map
[
string
]
string
{
kubetypes
.
ConfigSourceAnnotationKey
:
kubetypes
.
FileSource
,
},
},
},
Spec
:
api
.
PodSpec
{
SecurityContext
:
&
api
.
PodSecurityContext
{
Containers
:
[]
api
.
Container
{
HostNetwork
:
true
,
{
Name
:
"foo"
},
},
SecurityContext
:
&
api
.
PodSecurityContext
{
HostNetwork
:
true
,
},
},
},
}
})
pod
.
Annotations
[
kubetypes
.
ConfigSourceAnnotationKey
]
=
kubetypes
.
FileSource
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"expected pod infra creation to fail"
)
t
.
Errorf
(
"expected pod infra creation to fail"
)
...
@@ -3387,18 +3262,12 @@ func TestPrivilegeContainerAllowed(t *testing.T) {
...
@@ -3387,18 +3262,12 @@ func TestPrivilegeContainerAllowed(t *testing.T) {
AllowPrivileged
:
true
,
AllowPrivileged
:
true
,
})
})
privileged
:=
true
privileged
:=
true
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Containers
:
[]
api
.
Container
{
UID
:
"12345678"
,
{
Name
:
"foo"
,
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privileged
}},
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"foo"
,
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privileged
}},
},
},
},
}
})
kubelet
.
podManager
.
SetPods
([]
*
api
.
Pod
{
pod
})
kubelet
.
podManager
.
SetPods
([]
*
api
.
Pod
{
pod
})
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -3414,18 +3283,12 @@ func TestPrivilegeContainerDisallowed(t *testing.T) {
...
@@ -3414,18 +3283,12 @@ func TestPrivilegeContainerDisallowed(t *testing.T) {
AllowPrivileged
:
false
,
AllowPrivileged
:
false
,
})
})
privileged
:=
true
privileged
:=
true
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNsSpec
(
"12345678"
,
"foo"
,
"new"
,
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Containers
:
[]
api
.
Container
{
UID
:
"12345678"
,
{
Name
:
"foo"
,
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privileged
}},
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"foo"
,
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privileged
}},
},
},
},
}
})
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
&
kubecontainer
.
PodStatus
{},
kubetypes
.
SyncPodUpdate
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"expected pod infra creation to fail"
)
t
.
Errorf
(
"expected pod infra creation to fail"
)
...
@@ -3508,6 +3371,25 @@ func TestRegisterExistingNodeWithApiserver(t *testing.T) {
...
@@ -3508,6 +3371,25 @@ func TestRegisterExistingNodeWithApiserver(t *testing.T) {
}
}
func
TestMakePortMappings
(
t
*
testing
.
T
)
{
func
TestMakePortMappings
(
t
*
testing
.
T
)
{
port
:=
func
(
name
string
,
protocol
api
.
Protocol
,
containerPort
,
hostPort
int32
,
ip
string
)
api
.
ContainerPort
{
return
api
.
ContainerPort
{
Name
:
name
,
Protocol
:
protocol
,
ContainerPort
:
containerPort
,
HostPort
:
hostPort
,
HostIP
:
ip
,
}
}
portMapping
:=
func
(
name
string
,
protocol
api
.
Protocol
,
containerPort
,
hostPort
int
,
ip
string
)
kubecontainer
.
PortMapping
{
return
kubecontainer
.
PortMapping
{
Name
:
name
,
Protocol
:
protocol
,
ContainerPort
:
containerPort
,
HostPort
:
hostPort
,
HostIP
:
ip
,
}
}
tests
:=
[]
struct
{
tests
:=
[]
struct
{
container
*
api
.
Container
container
*
api
.
Container
expectedPortMappings
[]
kubecontainer
.
PortMapping
expectedPortMappings
[]
kubecontainer
.
PortMapping
...
@@ -3516,59 +3398,19 @@ func TestMakePortMappings(t *testing.T) {
...
@@ -3516,59 +3398,19 @@ func TestMakePortMappings(t *testing.T) {
&
api
.
Container
{
&
api
.
Container
{
Name
:
"fooContainer"
,
Name
:
"fooContainer"
,
Ports
:
[]
api
.
ContainerPort
{
Ports
:
[]
api
.
ContainerPort
{
{
port
(
""
,
api
.
ProtocolTCP
,
80
,
8080
,
"127.0.0.1"
),
Protocol
:
api
.
ProtocolTCP
,
port
(
""
,
api
.
ProtocolTCP
,
443
,
4343
,
"192.168.0.1"
),
ContainerPort
:
80
,
port
(
"foo"
,
api
.
ProtocolUDP
,
555
,
5555
,
""
),
HostPort
:
8080
,
// Duplicated, should be ignored.
HostIP
:
"127.0.0.1"
,
port
(
"foo"
,
api
.
ProtocolUDP
,
888
,
8888
,
""
),
},
// Duplicated, should be ignored.
{
port
(
""
,
api
.
ProtocolTCP
,
80
,
8888
,
""
),
Protocol
:
api
.
ProtocolTCP
,
ContainerPort
:
443
,
HostPort
:
4343
,
HostIP
:
"192.168.0.1"
,
},
{
Name
:
"foo"
,
Protocol
:
api
.
ProtocolUDP
,
ContainerPort
:
555
,
HostPort
:
5555
,
},
{
Name
:
"foo"
,
// Duplicated, should be ignored.
Protocol
:
api
.
ProtocolUDP
,
ContainerPort
:
888
,
HostPort
:
8888
,
},
{
Protocol
:
api
.
ProtocolTCP
,
// Duplicated, should be ignored.
ContainerPort
:
80
,
HostPort
:
8888
,
},
},
},
},
},
[]
kubecontainer
.
PortMapping
{
[]
kubecontainer
.
PortMapping
{
{
portMapping
(
"fooContainer-TCP:80"
,
api
.
ProtocolTCP
,
80
,
8080
,
"127.0.0.1"
),
Name
:
"fooContainer-TCP:80"
,
portMapping
(
"fooContainer-TCP:443"
,
api
.
ProtocolTCP
,
443
,
4343
,
"192.168.0.1"
),
Protocol
:
api
.
ProtocolTCP
,
portMapping
(
"fooContainer-foo"
,
api
.
ProtocolUDP
,
555
,
5555
,
""
),
ContainerPort
:
80
,
HostPort
:
8080
,
HostIP
:
"127.0.0.1"
,
},
{
Name
:
"fooContainer-TCP:443"
,
Protocol
:
api
.
ProtocolTCP
,
ContainerPort
:
443
,
HostPort
:
4343
,
HostIP
:
"192.168.0.1"
,
},
{
Name
:
"fooContainer-foo"
,
Protocol
:
api
.
ProtocolUDP
,
ContainerPort
:
555
,
HostPort
:
5555
,
HostIP
:
""
,
},
},
},
},
},
}
}
...
@@ -3710,6 +3552,23 @@ func TestSyncPodsDoesNotSetPodsThatDidNotRunTooLongToFailed(t *testing.T) {
...
@@ -3710,6 +3552,23 @@ func TestSyncPodsDoesNotSetPodsThatDidNotRunTooLongToFailed(t *testing.T) {
}
}
}
}
func
podWithUidNameNs
(
uid
types
.
UID
,
name
,
namespace
string
)
*
api
.
Pod
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
uid
,
Name
:
name
,
Namespace
:
namespace
,
Annotations
:
map
[
string
]
string
{},
},
}
}
func
podWithUidNameNsSpec
(
uid
types
.
UID
,
name
,
namespace
string
,
spec
api
.
PodSpec
)
*
api
.
Pod
{
pod
:=
podWithUidNameNs
(
uid
,
name
,
namespace
)
pod
.
Spec
=
spec
return
pod
}
func
TestDeletePodDirsForDeletedPods
(
t
*
testing
.
T
)
{
func
TestDeletePodDirsForDeletedPods
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
...
@@ -3717,20 +3576,8 @@ func TestDeletePodDirsForDeletedPods(t *testing.T) {
...
@@ -3717,20 +3576,8 @@ func TestDeletePodDirsForDeletedPods(t *testing.T) {
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
kl
:=
testKubelet
.
kubelet
kl
:=
testKubelet
.
kubelet
pods
:=
[]
*
api
.
Pod
{
pods
:=
[]
*
api
.
Pod
{
{
podWithUidNameNs
(
"12345678"
,
"pod1"
,
"ns"
),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNs
(
"12345679"
,
"pod2"
,
"ns"
),
UID
:
"12345678"
,
Name
:
"pod1"
,
Namespace
:
"ns"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345679"
,
Name
:
"pod2"
,
Namespace
:
"ns"
,
},
},
}
}
kl
.
podManager
.
SetPods
(
pods
)
kl
.
podManager
.
SetPods
(
pods
)
...
@@ -3776,27 +3623,9 @@ func TestDoesNotDeletePodDirsForTerminatedPods(t *testing.T) {
...
@@ -3776,27 +3623,9 @@ func TestDoesNotDeletePodDirsForTerminatedPods(t *testing.T) {
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
kl
:=
testKubelet
.
kubelet
kl
:=
testKubelet
.
kubelet
pods
:=
[]
*
api
.
Pod
{
pods
:=
[]
*
api
.
Pod
{
{
podWithUidNameNs
(
"12345678"
,
"pod1"
,
"ns"
),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNs
(
"12345679"
,
"pod2"
,
"ns"
),
UID
:
"12345678"
,
podWithUidNameNs
(
"12345680"
,
"pod3"
,
"ns"
),
Name
:
"pod1"
,
Namespace
:
"ns"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345679"
,
Name
:
"pod2"
,
Namespace
:
"ns"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345680"
,
Name
:
"pod3"
,
Namespace
:
"ns"
,
},
},
}
}
syncAndVerifyPodDir
(
t
,
testKubelet
,
pods
,
pods
,
true
)
syncAndVerifyPodDir
(
t
,
testKubelet
,
pods
,
pods
,
true
)
...
@@ -3817,13 +3646,8 @@ func TestDoesNotDeletePodDirsIfContainerIsRunning(t *testing.T) {
...
@@ -3817,13 +3646,8 @@ func TestDoesNotDeletePodDirsIfContainerIsRunning(t *testing.T) {
Name
:
"pod1"
,
Name
:
"pod1"
,
Namespace
:
"ns"
,
Namespace
:
"ns"
,
}
}
apiPod
:=
&
api
.
Pod
{
apiPod
:=
podWithUidNameNs
(
runningPod
.
ID
,
runningPod
.
Name
,
runningPod
.
Namespace
)
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
runningPod
.
ID
,
Name
:
runningPod
.
Name
,
Namespace
:
runningPod
.
Namespace
,
},
}
// Sync once to create pod directory; confirm that the pod directory has
// Sync once to create pod directory; confirm that the pod directory has
// already been created.
// already been created.
pods
:=
[]
*
api
.
Pod
{
apiPod
}
pods
:=
[]
*
api
.
Pod
{
apiPod
}
...
@@ -3843,6 +3667,16 @@ func TestDoesNotDeletePodDirsIfContainerIsRunning(t *testing.T) {
...
@@ -3843,6 +3667,16 @@ func TestDoesNotDeletePodDirsIfContainerIsRunning(t *testing.T) {
}
}
func
TestCleanupBandwidthLimits
(
t
*
testing
.
T
)
{
func
TestCleanupBandwidthLimits
(
t
*
testing
.
T
)
{
testPod
:=
func
(
name
,
ingress
string
)
*
api
.
Pod
{
pod
:=
podWithUidNameNs
(
""
,
name
,
""
)
if
len
(
ingress
)
!=
0
{
pod
.
Annotations
[
"kubernetes.io/ingress-bandwidth"
]
=
ingress
}
return
pod
}
// TODO(random-liu): We removed the test case for pod status not cached here. We should add a higher
// TODO(random-liu): We removed the test case for pod status not cached here. We should add a higher
// layer status getter function and test that function instead.
// layer status getter function and test that function instead.
tests
:=
[]
struct
{
tests
:=
[]
struct
{
...
@@ -3858,19 +3692,8 @@ func TestCleanupBandwidthLimits(t *testing.T) {
...
@@ -3858,19 +3692,8 @@ func TestCleanupBandwidthLimits(t *testing.T) {
Phase
:
api
.
PodRunning
,
Phase
:
api
.
PodRunning
,
},
},
pods
:
[]
*
api
.
Pod
{
pods
:
[]
*
api
.
Pod
{
{
testPod
(
"foo"
,
"10M"
),
ObjectMeta
:
api
.
ObjectMeta
{
testPod
(
"bar"
,
""
),
Name
:
"foo"
,
Annotations
:
map
[
string
]
string
{
"kubernetes.io/ingress-bandwidth"
:
"10M"
,
},
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
},
},
},
},
inputCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
inputCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
expectResetCIDRs
:
[]
string
{
"2.3.4.5/32"
,
"5.6.7.8/32"
},
expectResetCIDRs
:
[]
string
{
"2.3.4.5/32"
,
"5.6.7.8/32"
},
...
@@ -3882,19 +3705,8 @@ func TestCleanupBandwidthLimits(t *testing.T) {
...
@@ -3882,19 +3705,8 @@ func TestCleanupBandwidthLimits(t *testing.T) {
Phase
:
api
.
PodFailed
,
Phase
:
api
.
PodFailed
,
},
},
pods
:
[]
*
api
.
Pod
{
pods
:
[]
*
api
.
Pod
{
{
testPod
(
"foo"
,
"10M"
),
ObjectMeta
:
api
.
ObjectMeta
{
testPod
(
"bar"
,
""
),
Name
:
"foo"
,
Annotations
:
map
[
string
]
string
{
"kubernetes.io/ingress-bandwidth"
:
"10M"
,
},
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
},
},
},
},
inputCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
inputCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
expectResetCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
expectResetCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
...
@@ -3906,16 +3718,8 @@ func TestCleanupBandwidthLimits(t *testing.T) {
...
@@ -3906,16 +3718,8 @@ func TestCleanupBandwidthLimits(t *testing.T) {
Phase
:
api
.
PodFailed
,
Phase
:
api
.
PodFailed
,
},
},
pods
:
[]
*
api
.
Pod
{
pods
:
[]
*
api
.
Pod
{
{
testPod
(
"foo"
,
""
),
ObjectMeta
:
api
.
ObjectMeta
{
testPod
(
"bar"
,
""
),
Name
:
"foo"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
},
},
},
},
inputCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
inputCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
expectResetCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
expectResetCIDRs
:
[]
string
{
"1.2.3.4/32"
,
"2.3.4.5/32"
,
"5.6.7.8/32"
},
...
@@ -3948,6 +3752,18 @@ func TestExtractBandwidthResources(t *testing.T) {
...
@@ -3948,6 +3752,18 @@ func TestExtractBandwidthResources(t *testing.T) {
four
,
_
:=
resource
.
ParseQuantity
(
"4M"
)
four
,
_
:=
resource
.
ParseQuantity
(
"4M"
)
ten
,
_
:=
resource
.
ParseQuantity
(
"10M"
)
ten
,
_
:=
resource
.
ParseQuantity
(
"10M"
)
twenty
,
_
:=
resource
.
ParseQuantity
(
"20M"
)
twenty
,
_
:=
resource
.
ParseQuantity
(
"20M"
)
testPod
:=
func
(
ingress
,
egress
string
)
*
api
.
Pod
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{}}}
if
len
(
ingress
)
!=
0
{
pod
.
Annotations
[
"kubernetes.io/ingress-bandwidth"
]
=
ingress
}
if
len
(
egress
)
!=
0
{
pod
.
Annotations
[
"kubernetes.io/egress-bandwidth"
]
=
egress
}
return
pod
}
tests
:=
[]
struct
{
tests
:=
[]
struct
{
pod
*
api
.
Pod
pod
*
api
.
Pod
expectedIngress
*
resource
.
Quantity
expectedIngress
*
resource
.
Quantity
...
@@ -3958,45 +3774,20 @@ func TestExtractBandwidthResources(t *testing.T) {
...
@@ -3958,45 +3774,20 @@ func TestExtractBandwidthResources(t *testing.T) {
pod
:
&
api
.
Pod
{},
pod
:
&
api
.
Pod
{},
},
},
{
{
pod
:
&
api
.
Pod
{
pod
:
testPod
(
"10M"
,
""
),
ObjectMeta
:
api
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"kubernetes.io/ingress-bandwidth"
:
"10M"
,
},
},
},
expectedIngress
:
ten
,
expectedIngress
:
ten
,
},
},
{
{
pod
:
&
api
.
Pod
{
pod
:
testPod
(
""
,
"10M"
),
ObjectMeta
:
api
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"kubernetes.io/egress-bandwidth"
:
"10M"
,
},
},
},
expectedEgress
:
ten
,
expectedEgress
:
ten
,
},
},
{
{
pod
:
&
api
.
Pod
{
pod
:
testPod
(
"4M"
,
"20M"
),
ObjectMeta
:
api
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"kubernetes.io/ingress-bandwidth"
:
"4M"
,
"kubernetes.io/egress-bandwidth"
:
"20M"
,
},
},
},
expectedIngress
:
four
,
expectedIngress
:
four
,
expectedEgress
:
twenty
,
expectedEgress
:
twenty
,
},
},
{
{
pod
:
&
api
.
Pod
{
pod
:
testPod
(
"foo"
,
""
),
ObjectMeta
:
api
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"kubernetes.io/ingress-bandwidth"
:
"foo"
,
},
},
},
expectError
:
true
,
expectError
:
true
,
},
},
}
}
...
@@ -4089,16 +3880,11 @@ func TestGenerateAPIPodStatusWithSortedContainers(t *testing.T) {
...
@@ -4089,16 +3880,11 @@ func TestGenerateAPIPodStatusWithSortedContainers(t *testing.T) {
}
}
specContainerList
=
append
(
specContainerList
,
api
.
Container
{
Name
:
containerName
})
specContainerList
=
append
(
specContainerList
,
api
.
Container
{
Name
:
containerName
})
}
}
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNs
(
"uid1"
,
"foo"
,
"test"
)
ObjectMeta
:
api
.
ObjectMeta
{
pod
.
Spec
=
api
.
PodSpec
{
UID
:
types
.
UID
(
"uid1"
),
Containers
:
specContainerList
,
Name
:
"foo"
,
Namespace
:
"test"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
specContainerList
,
},
}
}
status
:=
&
kubecontainer
.
PodStatus
{
status
:=
&
kubecontainer
.
PodStatus
{
ID
:
pod
.
UID
,
ID
:
pod
.
UID
,
Name
:
pod
.
Name
,
Name
:
pod
.
Name
,
...
@@ -4135,14 +3921,9 @@ func TestGenerateAPIPodStatusWithReasonCache(t *testing.T) {
...
@@ -4135,14 +3921,9 @@ func TestGenerateAPIPodStatusWithReasonCache(t *testing.T) {
}
}
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
kubelet
:=
testKubelet
.
kubelet
kubelet
:=
testKubelet
.
kubelet
pod
:=
&
api
.
Pod
{
pod
:=
podWithUidNameNs
(
"12345678"
,
"foo"
,
"new"
)
ObjectMeta
:
api
.
ObjectMeta
{
pod
.
Spec
=
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyOnFailure
}
UID
:
"12345678"
,
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyOnFailure
},
}
podStatus
:=
&
kubecontainer
.
PodStatus
{
podStatus
:=
&
kubecontainer
.
PodStatus
{
ID
:
pod
.
UID
,
ID
:
pod
.
UID
,
Name
:
pod
.
Name
,
Name
:
pod
.
Name
,
...
...
pkg/kubelet/pod_workers_test.go
View file @
25f37007
...
@@ -229,36 +229,12 @@ func TestFakePodWorkers(t *testing.T) {
...
@@ -229,36 +229,12 @@ func TestFakePodWorkers(t *testing.T) {
&
api
.
Pod
{},
&
api
.
Pod
{},
},
},
{
{
&
api
.
Pod
{
podWithUidNameNs
(
"12345678"
,
"foo"
,
"new"
),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNs
(
"12345678"
,
"fooMirror"
,
"new"
),
UID
:
"12345678"
,
Name
:
"foo"
,
Namespace
:
"new"
,
},
},
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345678"
,
Name
:
"fooMirror"
,
Namespace
:
"new"
,
},
},
},
},
{
{
&
api
.
Pod
{
podWithUidNameNs
(
"98765"
,
"bar"
,
"new"
),
ObjectMeta
:
api
.
ObjectMeta
{
podWithUidNameNs
(
"98765"
,
"barMirror"
,
"new"
),
UID
:
"98765"
,
Name
:
"bar"
,
Namespace
:
"new"
,
},
},
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"98765"
,
Name
:
"barMirror"
,
Namespace
:
"new"
,
},
},
},
},
}
}
...
...
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