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