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
20910289
Commit
20910289
authored
Jan 19, 2018
by
Yu-Ju Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix all the unit tests and update the bazel files
parent
e8da890a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
111 additions
and
90 deletions
+111
-90
.golint_failures
hack/.golint_failures
+0
-1
BUILD
pkg/kubelet/dockershim/BUILD
+3
-1
docker_container_test.go
pkg/kubelet/dockershim/docker_container_test.go
+52
-34
docker_image_test.go
pkg/kubelet/dockershim/docker_image_test.go
+5
-4
docker_sandbox_test.go
pkg/kubelet/dockershim/docker_sandbox_test.go
+43
-36
docker_service_test.go
pkg/kubelet/dockershim/docker_service_test.go
+7
-7
BUILD
pkg/kubelet/dockershim/remote/BUILD
+1
-7
No files found.
hack/.golint_failures
View file @
20910289
...
...
@@ -178,7 +178,6 @@ pkg/kubelet/custommetrics
pkg/kubelet/dockershim
pkg/kubelet/dockershim/cm
pkg/kubelet/dockershim/libdocker
pkg/kubelet/dockershim/remote
pkg/kubelet/dockershim/testing
pkg/kubelet/events
pkg/kubelet/gpu
...
...
pkg/kubelet/dockershim/BUILD
View file @
20910289
...
...
@@ -83,7 +83,6 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubelet/dockershim",
deps = [
"//pkg/credentialprovider:go_default_library",
"//pkg/kubelet/apis/cri:go_default_library",
"//pkg/kubelet/apis/cri/v1alpha1/runtime:go_default_library",
"//pkg/kubelet/apis/kubeletconfig:go_default_library",
"//pkg/kubelet/cm:go_default_library",
...
...
@@ -115,11 +114,13 @@ go_library(
"//vendor/github.com/docker/docker/pkg/jsonmessage:go_default_library",
"//vendor/github.com/docker/go-connections/nat:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/client-go/tools/remotecommand:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
],
)
...
...
@@ -165,6 +166,7 @@ go_test(
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
],
)
...
...
pkg/kubelet/dockershim/docker_container_test.go
View file @
20910289
...
...
@@ -26,6 +26,7 @@ import (
dockertypes
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
containertest
"k8s.io/kubernetes/pkg/kubelet/container/testing"
...
...
@@ -44,6 +45,10 @@ func makeContainerConfig(sConfig *runtimeapi.PodSandboxConfig, name, image strin
}
}
func
getTestCTX
()
context
.
Context
{
return
context
.
Background
()
}
// TestListContainers creates several containers and then list them to check
// whether the correct metadatas, states, and labels are returned.
func
TestListContainers
(
t
*
testing
.
T
)
{
...
...
@@ -70,10 +75,12 @@ func TestListContainers(t *testing.T) {
for
i
:=
range
configs
{
// We don't care about the sandbox id; pass a bogus one.
sandboxID
:=
fmt
.
Sprintf
(
"sandboxid%d"
,
i
)
id
,
err
:=
ds
.
CreateContainer
(
sandboxID
,
configs
[
i
],
sConfigs
[
i
])
assert
.
NoError
(
t
,
err
)
err
=
ds
.
StartContainer
(
id
)
assert
.
NoError
(
t
,
err
)
req
:=
&
runtimeapi
.
CreateContainerRequest
{
PodSandboxId
:
sandboxID
,
Config
:
configs
[
i
],
SandboxConfig
:
sConfigs
[
i
]}
createResp
,
err
:=
ds
.
CreateContainer
(
getTestCTX
(),
req
)
require
.
NoError
(
t
,
err
)
id
:=
createResp
.
ContainerId
_
,
err
=
ds
.
StartContainer
(
getTestCTX
(),
&
runtimeapi
.
StartContainerRequest
{
ContainerId
:
id
})
require
.
NoError
(
t
,
err
)
imageRef
:=
""
// FakeDockerClient doesn't populate ImageRef yet.
// Prepend to the expected list because ListContainers returns
...
...
@@ -90,10 +97,10 @@ func TestListContainers(t *testing.T) {
Annotations
:
configs
[
i
]
.
Annotations
,
}},
expected
...
)
}
containers
,
err
:=
ds
.
ListContainers
(
nil
)
assert
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
c
ontainers
,
len
(
expected
))
assert
.
Equal
(
t
,
expected
,
c
ontainers
)
listResp
,
err
:=
ds
.
ListContainers
(
getTestCTX
(),
&
runtimeapi
.
ListContainersRequest
{}
)
require
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
listResp
.
C
ontainers
,
len
(
expected
))
assert
.
Equal
(
t
,
expected
,
listResp
.
C
ontainers
)
}
// TestContainerStatus tests the basic lifecycle operations and verify that
...
...
@@ -137,31 +144,36 @@ func TestContainerStatus(t *testing.T) {
fClock
.
SetTime
(
time
.
Now
()
.
Add
(
-
1
*
time
.
Hour
))
expected
.
CreatedAt
=
fClock
.
Now
()
.
UnixNano
()
const
sandboxId
=
"sandboxid"
id
,
err
:=
ds
.
CreateContainer
(
sandboxId
,
config
,
sConfig
)
assert
.
NoError
(
t
,
err
)
req
:=
&
runtimeapi
.
CreateContainerRequest
{
PodSandboxId
:
sandboxId
,
Config
:
config
,
SandboxConfig
:
sConfig
}
createResp
,
err
:=
ds
.
CreateContainer
(
getTestCTX
(),
req
)
require
.
NoError
(
t
,
err
)
id
:=
createResp
.
ContainerId
// Check internal labels
c
,
err
:=
fDocker
.
InspectContainer
(
id
)
assert
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
c
.
Config
.
Labels
[
containerTypeLabelKey
],
containerTypeLabelContainer
)
assert
.
Equal
(
t
,
c
.
Config
.
Labels
[
sandboxIDLabelKey
],
sandboxId
)
// Set the id manually since we don't know the id until it's created.
expected
.
Id
=
id
assert
.
NoError
(
t
,
err
)
status
,
err
:=
ds
.
ContainerStatus
(
id
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
s
tatus
)
resp
,
err
:=
ds
.
ContainerStatus
(
getTestCTX
(),
&
runtimeapi
.
ContainerStatusRequest
{
ContainerId
:
id
}
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
resp
.
S
tatus
)
// Advance the clock and start the container.
fClock
.
SetTime
(
time
.
Now
())
expected
.
StartedAt
=
fClock
.
Now
()
.
UnixNano
()
expected
.
State
=
runtimeapi
.
ContainerState_CONTAINER_RUNNING
err
=
ds
.
StartContainer
(
id
)
assert
.
NoError
(
t
,
err
)
status
,
err
=
ds
.
ContainerStatus
(
id
)
assert
.
Equal
(
t
,
expected
,
status
)
_
,
err
=
ds
.
StartContainer
(
getTestCTX
(),
&
runtimeapi
.
StartContainerRequest
{
ContainerId
:
id
})
require
.
NoError
(
t
,
err
)
resp
,
err
=
ds
.
ContainerStatus
(
getTestCTX
(),
&
runtimeapi
.
ContainerStatusRequest
{
ContainerId
:
id
})
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
resp
.
Status
)
// Advance the clock and stop the container.
fClock
.
SetTime
(
time
.
Now
()
.
Add
(
1
*
time
.
Hour
))
...
...
@@ -169,16 +181,17 @@ func TestContainerStatus(t *testing.T) {
expected
.
State
=
runtimeapi
.
ContainerState_CONTAINER_EXITED
expected
.
Reason
=
"Completed"
err
=
ds
.
StopContainer
(
id
,
0
)
_
,
err
=
ds
.
StopContainer
(
getTestCTX
(),
&
runtimeapi
.
StopContainerRequest
{
ContainerId
:
id
,
Timeout
:
int64
(
0
)}
)
assert
.
NoError
(
t
,
err
)
status
,
err
=
ds
.
ContainerStatus
(
id
)
assert
.
Equal
(
t
,
expected
,
status
)
resp
,
err
=
ds
.
ContainerStatus
(
getTestCTX
(),
&
runtimeapi
.
ContainerStatusRequest
{
ContainerId
:
id
})
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
resp
.
Status
)
// Remove the container.
err
=
ds
.
RemoveContainer
(
id
)
assert
.
NoError
(
t
,
err
)
status
,
err
=
ds
.
ContainerStatus
(
id
)
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"status of container: %+v"
,
status
))
_
,
err
=
ds
.
RemoveContainer
(
getTestCTX
(),
&
runtimeapi
.
RemoveContainerRequest
{
ContainerId
:
id
}
)
require
.
NoError
(
t
,
err
)
resp
,
err
=
ds
.
ContainerStatus
(
getTestCTX
(),
&
runtimeapi
.
ContainerStatusRequest
{
ContainerId
:
id
}
)
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"status of container: %+v"
,
resp
))
}
// TestContainerLogPath tests the container log creation logic.
...
...
@@ -193,7 +206,10 @@ func TestContainerLogPath(t *testing.T) {
config
.
LogPath
=
containerLogPath
const
sandboxId
=
"sandboxid"
id
,
err
:=
ds
.
CreateContainer
(
sandboxId
,
config
,
sConfig
)
req
:=
&
runtimeapi
.
CreateContainerRequest
{
PodSandboxId
:
sandboxId
,
Config
:
config
,
SandboxConfig
:
sConfig
}
createResp
,
err
:=
ds
.
CreateContainer
(
getTestCTX
(),
req
)
require
.
NoError
(
t
,
err
)
id
:=
createResp
.
ContainerId
// Check internal container log label
c
,
err
:=
fDocker
.
InspectContainer
(
id
)
...
...
@@ -211,16 +227,16 @@ func TestContainerLogPath(t *testing.T) {
assert
.
Equal
(
t
,
kubeletContainerLogPath
,
newname
)
return
nil
}
err
=
ds
.
StartContainer
(
id
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
ds
.
StartContainer
(
getTestCTX
(),
&
runtimeapi
.
StartContainerRequest
{
ContainerId
:
id
}
)
require
.
NoError
(
t
,
err
)
err
=
ds
.
StopContainer
(
id
,
0
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
ds
.
StopContainer
(
getTestCTX
(),
&
runtimeapi
.
StopContainerRequest
{
ContainerId
:
id
,
Timeout
:
int64
(
0
)}
)
require
.
NoError
(
t
,
err
)
// Verify container log symlink deletion
// symlink is also tentatively deleted at startup
err
=
ds
.
RemoveContainer
(
id
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
ds
.
RemoveContainer
(
getTestCTX
(),
&
runtimeapi
.
RemoveContainerRequest
{
ContainerId
:
id
}
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
[]
string
{
kubeletContainerLogPath
,
kubeletContainerLogPath
},
fakeOS
.
Removes
)
}
...
...
@@ -280,11 +296,13 @@ func TestContainerCreationConflict(t *testing.T) {
if
test
.
removeError
!=
nil
{
fDocker
.
InjectError
(
"remove"
,
test
.
removeError
)
}
id
,
err
:=
ds
.
CreateContainer
(
sandboxId
,
config
,
sConfig
)
req
:=
&
runtimeapi
.
CreateContainerRequest
{
PodSandboxId
:
sandboxId
,
Config
:
config
,
SandboxConfig
:
sConfig
}
createResp
,
err
:=
ds
.
CreateContainer
(
getTestCTX
(),
req
)
require
.
Equal
(
t
,
test
.
expectError
,
err
)
assert
.
NoError
(
t
,
fDocker
.
AssertCalls
(
test
.
expectCalls
))
if
err
==
nil
{
c
,
err
:=
fDocker
.
InspectContainer
(
i
d
)
c
,
err
:=
fDocker
.
InspectContainer
(
createResp
.
ContainerI
d
)
assert
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
strings
.
Split
(
c
.
Name
,
nameDelimiter
),
test
.
expectFields
)
}
...
...
pkg/kubelet/dockershim/docker_image_test.go
View file @
20910289
...
...
@@ -23,6 +23,7 @@ import (
dockertypes
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/dockershim/libdocker"
...
...
@@ -32,7 +33,7 @@ func TestRemoveImage(t *testing.T) {
ds
,
fakeDocker
,
_
:=
newTestDockerService
()
id
:=
"1111"
fakeDocker
.
InjectImageInspects
([]
dockertypes
.
ImageInspect
{{
ID
:
id
,
RepoTags
:
[]
string
{
"foo"
}}})
ds
.
RemoveImage
(
&
runtimeapi
.
ImageSpec
{
Image
:
id
})
ds
.
RemoveImage
(
getTestCTX
(),
&
runtimeapi
.
RemoveImageRequest
{
Image
:
&
runtimeapi
.
ImageSpec
{
Image
:
id
}
})
fakeDocker
.
AssertCallDetails
(
libdocker
.
NewCalledDetail
(
"inspect_image"
,
nil
),
libdocker
.
NewCalledDetail
(
"remove_image"
,
[]
interface
{}{
id
,
dockertypes
.
ImageRemoveOptions
{
PruneChildren
:
true
}}))
}
...
...
@@ -41,7 +42,7 @@ func TestRemoveImageWithMultipleTags(t *testing.T) {
ds
,
fakeDocker
,
_
:=
newTestDockerService
()
id
:=
"1111"
fakeDocker
.
InjectImageInspects
([]
dockertypes
.
ImageInspect
{{
ID
:
id
,
RepoTags
:
[]
string
{
"foo"
,
"bar"
}}})
ds
.
RemoveImage
(
&
runtimeapi
.
ImageSpec
{
Image
:
id
})
ds
.
RemoveImage
(
getTestCTX
(),
&
runtimeapi
.
RemoveImageRequest
{
Image
:
&
runtimeapi
.
ImageSpec
{
Image
:
id
}
})
fakeDocker
.
AssertCallDetails
(
libdocker
.
NewCalledDetail
(
"inspect_image"
,
nil
),
libdocker
.
NewCalledDetail
(
"remove_image"
,
[]
interface
{}{
"foo"
,
dockertypes
.
ImageRemoveOptions
{
PruneChildren
:
true
}}),
libdocker
.
NewCalledDetail
(
"remove_image"
,
[]
interface
{}{
"bar"
,
dockertypes
.
ImageRemoveOptions
{
PruneChildren
:
true
}}))
...
...
@@ -67,8 +68,8 @@ func TestPullWithJSONError(t *testing.T) {
}
for
key
,
test
:=
range
tests
{
fakeDocker
.
InjectError
(
"pull"
,
test
.
err
)
_
,
err
:=
ds
.
PullImage
(
test
.
image
,
&
runtimeapi
.
AuthConfig
{
})
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"TestCase [%s]"
,
key
))
_
,
err
:=
ds
.
PullImage
(
getTestCTX
(),
&
runtimeapi
.
PullImageRequest
{
Image
:
test
.
image
,
Auth
:
&
runtimeapi
.
AuthConfig
{}
})
require
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"TestCase [%s]"
,
key
))
assert
.
Contains
(
t
,
err
.
Error
(),
test
.
expectedError
)
}
}
pkg/kubelet/dockershim/docker_sandbox_test.go
View file @
20910289
...
...
@@ -24,6 +24,7 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
...
...
@@ -69,23 +70,23 @@ func TestListSandboxes(t *testing.T) {
state
:=
runtimeapi
.
PodSandboxState_SANDBOX_READY
var
createdAt
int64
=
fakeClock
.
Now
()
.
UnixNano
()
for
i
:=
range
configs
{
id
,
err
:=
ds
.
RunPodSandbox
(
configs
[
i
]
)
assert
.
NoError
(
t
,
err
)
runResp
,
err
:=
ds
.
RunPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
RunPodSandboxRequest
{
Config
:
configs
[
i
]}
)
require
.
NoError
(
t
,
err
)
// Prepend to the expected list because ListPodSandbox returns
// the most recent sandbox first.
expected
=
append
([]
*
runtimeapi
.
PodSandbox
{{
Metadata
:
configs
[
i
]
.
Metadata
,
Id
:
i
d
,
Id
:
runResp
.
PodSandboxI
d
,
State
:
state
,
CreatedAt
:
createdAt
,
Labels
:
configs
[
i
]
.
Labels
,
Annotations
:
configs
[
i
]
.
Annotations
,
}},
expected
...
)
}
sandboxes
,
err
:=
ds
.
ListPodSandbox
(
nil
)
assert
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
sandboxe
s
,
len
(
expected
))
assert
.
Equal
(
t
,
expected
,
sandboxe
s
)
listResp
,
err
:=
ds
.
ListPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
ListPodSandboxRequest
{}
)
require
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
listResp
.
Item
s
,
len
(
expected
))
assert
.
Equal
(
t
,
expected
,
listResp
.
Item
s
)
}
// TestSandboxStatus tests the basic lifecycle operations and verify that
...
...
@@ -116,7 +117,9 @@ func TestSandboxStatus(t *testing.T) {
// Create the sandbox.
fClock
.
SetTime
(
time
.
Now
())
expected
.
CreatedAt
=
fClock
.
Now
()
.
UnixNano
()
id
,
err
:=
ds
.
RunPodSandbox
(
config
)
runResp
,
err
:=
ds
.
RunPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
RunPodSandboxRequest
{
Config
:
config
})
require
.
NoError
(
t
,
err
)
id
:=
runResp
.
PodSandboxId
// Check internal labels
c
,
err
:=
fDocker
.
InspectContainer
(
id
)
...
...
@@ -125,24 +128,25 @@ func TestSandboxStatus(t *testing.T) {
assert
.
Equal
(
t
,
c
.
Config
.
Labels
[
types
.
KubernetesContainerNameLabel
],
sandboxContainerName
)
expected
.
Id
=
id
// ID is only known after the creation.
status
,
err
:=
ds
.
PodSandboxStatus
(
id
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
status
)
status
Resp
,
err
:=
ds
.
PodSandboxStatus
(
getTestCTX
(),
&
runtimeapi
.
PodSandboxStatusRequest
{
PodSandboxId
:
id
}
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
status
Resp
.
Status
)
// Stop the sandbox.
expected
.
State
=
runtimeapi
.
PodSandboxState_SANDBOX_NOTREADY
err
=
ds
.
StopPodSandbox
(
id
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
ds
.
StopPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
StopPodSandboxRequest
{
PodSandboxId
:
id
}
)
require
.
NoError
(
t
,
err
)
// IP not valid after sandbox stop
expected
.
Network
.
Ip
=
""
status
,
err
=
ds
.
PodSandboxStatus
(
id
)
assert
.
Equal
(
t
,
expected
,
status
)
statusResp
,
err
=
ds
.
PodSandboxStatus
(
getTestCTX
(),
&
runtimeapi
.
PodSandboxStatusRequest
{
PodSandboxId
:
id
})
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
statusResp
.
Status
)
// Remove the container.
err
=
ds
.
RemovePodSandbox
(
id
)
assert
.
NoError
(
t
,
err
)
status
,
err
=
ds
.
PodSandboxStatus
(
id
)
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"status of sandbox: %+v"
,
status
))
_
,
err
=
ds
.
RemovePodSandbox
(
getTestCTX
(),
&
runtimeapi
.
RemovePodSandboxRequest
{
PodSandboxId
:
id
}
)
require
.
NoError
(
t
,
err
)
status
Resp
,
err
=
ds
.
PodSandboxStatus
(
getTestCTX
(),
&
runtimeapi
.
PodSandboxStatusRequest
{
PodSandboxId
:
id
}
)
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"status of sandbox: %+v"
,
status
Resp
))
}
// TestSandboxStatusAfterRestart tests that retrieving sandbox status returns
...
...
@@ -183,9 +187,10 @@ func TestSandboxStatusAfterRestart(t *testing.T) {
// Check status without RunPodSandbox() having set up networking
expected
.
Id
=
createResp
.
ID
// ID is only known after the creation.
status
,
err
:=
ds
.
PodSandboxStatus
(
createResp
.
ID
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
status
)
statusResp
,
err
:=
ds
.
PodSandboxStatus
(
getTestCTX
(),
&
runtimeapi
.
PodSandboxStatusRequest
{
PodSandboxId
:
createResp
.
ID
})
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
expected
,
statusResp
.
Status
)
}
// TestNetworkPluginInvocation checks that the right SetUpPod and TearDownPod
...
...
@@ -212,10 +217,10 @@ func TestNetworkPluginInvocation(t *testing.T) {
mockPlugin
.
EXPECT
()
.
GetPodNetworkStatus
(
ns
,
name
,
cID
)
mockPlugin
.
EXPECT
()
.
TearDownPod
(
ns
,
name
,
cID
)
.
After
(
setup
)
_
,
err
:=
ds
.
RunPodSandbox
(
c
)
assert
.
NoError
(
t
,
err
)
err
=
ds
.
StopPodSandbox
(
cID
.
ID
)
assert
.
NoError
(
t
,
err
)
_
,
err
:=
ds
.
RunPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
RunPodSandboxRequest
{
Config
:
c
}
)
require
.
NoError
(
t
,
err
)
_
,
err
=
ds
.
StopPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
StopPodSandboxRequest
{
PodSandboxId
:
cID
.
ID
}
)
require
.
NoError
(
t
,
err
)
}
// TestHostNetworkPluginInvocation checks that *no* SetUp/TearDown calls happen
...
...
@@ -244,9 +249,11 @@ func TestHostNetworkPluginInvocation(t *testing.T) {
cID
:=
kubecontainer
.
ContainerID
{
Type
:
runtimeName
,
ID
:
libdocker
.
GetFakeContainerID
(
fmt
.
Sprintf
(
"/%v"
,
makeSandboxName
(
c
)))}
// No calls to network plugin are expected
_
,
err
:=
ds
.
RunPodSandbox
(
c
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
ds
.
StopPodSandbox
(
cID
.
ID
))
_
,
err
:=
ds
.
RunPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
RunPodSandboxRequest
{
Config
:
c
})
require
.
NoError
(
t
,
err
)
_
,
err
=
ds
.
StopPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
StopPodSandboxRequest
{
PodSandboxId
:
cID
.
ID
})
require
.
NoError
(
t
,
err
)
}
// TestSetUpPodFailure checks that the sandbox should be not ready when it
...
...
@@ -271,19 +278,19 @@ func TestSetUpPodFailure(t *testing.T) {
mockPlugin
.
EXPECT
()
.
GetPodNetworkStatus
(
ns
,
name
,
cID
)
.
Return
(
&
network
.
PodNetworkStatus
{
IP
:
net
.
IP
(
"127.0.0.01"
)},
nil
)
.
AnyTimes
()
t
.
Logf
(
"RunPodSandbox should return error"
)
_
,
err
:=
ds
.
RunPodSandbox
(
c
)
_
,
err
:=
ds
.
RunPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
RunPodSandboxRequest
{
Config
:
c
}
)
assert
.
Error
(
t
,
err
)
t
.
Logf
(
"PodSandboxStatus should be not ready"
)
status
,
err
:=
ds
.
PodSandboxStatus
(
cID
.
ID
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
runtimeapi
.
PodSandboxState_SANDBOX_NOTREADY
,
status
.
State
)
status
Resp
,
err
:=
ds
.
PodSandboxStatus
(
getTestCTX
(),
&
runtimeapi
.
PodSandboxStatusRequest
{
PodSandboxId
:
cID
.
ID
}
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
runtimeapi
.
PodSandboxState_SANDBOX_NOTREADY
,
status
Resp
.
Status
.
State
)
t
.
Logf
(
"ListPodSandbox should also show not ready"
)
sandboxes
,
err
:=
ds
.
ListPodSandbox
(
nil
)
assert
.
NoError
(
t
,
err
)
listResp
,
err
:=
ds
.
ListPodSandbox
(
getTestCTX
(),
&
runtimeapi
.
ListPodSandboxRequest
{}
)
require
.
NoError
(
t
,
err
)
var
sandbox
*
runtimeapi
.
PodSandbox
for
_
,
s
:=
range
sandboxe
s
{
for
_
,
s
:=
range
listResp
.
Item
s
{
if
s
.
Id
==
cID
.
ID
{
sandbox
=
s
break
...
...
pkg/kubelet/dockershim/docker_service_test.go
View file @
20910289
...
...
@@ -83,33 +83,33 @@ func TestStatus(t *testing.T) {
}
// Should report ready status if version returns no error.
status
,
err
:=
ds
.
Status
(
)
assert
.
NoError
(
t
,
err
)
status
Resp
,
err
:=
ds
.
Status
(
getTestCTX
(),
&
runtimeapi
.
StatusRequest
{}
)
require
.
NoError
(
t
,
err
)
assertStatus
(
map
[
string
]
bool
{
runtimeapi
.
RuntimeReady
:
true
,
runtimeapi
.
NetworkReady
:
true
,
},
status
)
},
status
Resp
.
Status
)
// Should not report ready status if version returns error.
fDocker
.
InjectError
(
"version"
,
errors
.
New
(
"test error"
))
status
,
err
=
ds
.
Status
(
)
status
Resp
,
err
=
ds
.
Status
(
getTestCTX
(),
&
runtimeapi
.
StatusRequest
{}
)
assert
.
NoError
(
t
,
err
)
assertStatus
(
map
[
string
]
bool
{
runtimeapi
.
RuntimeReady
:
false
,
runtimeapi
.
NetworkReady
:
true
,
},
status
)
},
status
Resp
.
Status
)
// Should not report ready status is network plugin returns error.
mockPlugin
:=
newTestNetworkPlugin
(
t
)
ds
.
network
=
network
.
NewPluginManager
(
mockPlugin
)
defer
mockPlugin
.
Finish
()
mockPlugin
.
EXPECT
()
.
Status
()
.
Return
(
errors
.
New
(
"network error"
))
status
,
err
=
ds
.
Status
(
)
status
Resp
,
err
=
ds
.
Status
(
getTestCTX
(),
&
runtimeapi
.
StatusRequest
{}
)
assert
.
NoError
(
t
,
err
)
assertStatus
(
map
[
string
]
bool
{
runtimeapi
.
RuntimeReady
:
true
,
runtimeapi
.
NetworkReady
:
false
,
},
status
)
},
status
Resp
.
Status
)
}
func
TestVersion
(
t
*
testing
.
T
)
{
...
...
pkg/kubelet/dockershim/remote/BUILD
View file @
20910289
...
...
@@ -7,21 +7,15 @@ load(
go_library(
name = "go_default_library",
srcs = [
"docker_server.go",
"docker_service.go",
],
srcs = ["docker_server.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/dockershim/remote",
deps = [
"//pkg/kubelet/apis/cri:go_default_library",
"//pkg/kubelet/apis/cri/v1alpha1/runtime:go_default_library",
"//pkg/kubelet/dockershim:go_default_library",
"//pkg/kubelet/util:go_default_library",
"//pkg/util/interrupt:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
],
)
...
...
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