Rename more container
to task
.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
bad279e0f6
commit
6ca9c65578
@ -103,7 +103,7 @@ func (c *criContainerdService) startContainer(ctx context.Context, id string, me
|
|||||||
sandboxConfig := sandboxMeta.Config
|
sandboxConfig := sandboxMeta.Config
|
||||||
sandboxID := meta.SandboxID
|
sandboxID := meta.SandboxID
|
||||||
// Make sure sandbox is running.
|
// Make sure sandbox is running.
|
||||||
sandboxInfo, err := c.containerService.Info(ctx, &execution.InfoRequest{ContainerID: sandboxID})
|
sandboxInfo, err := c.taskService.Info(ctx, &execution.InfoRequest{ContainerID: sandboxID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get sandbox container %q info: %v", sandboxID, err)
|
return fmt.Errorf("failed to get sandbox container %q info: %v", sandboxID, err)
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func (c *criContainerdService) startContainer(ctx context.Context, id string, me
|
|||||||
sandboxPid := sandboxInfo.Task.Pid
|
sandboxPid := sandboxInfo.Task.Pid
|
||||||
glog.V(2).Infof("Sandbox container %q is running with pid %d", sandboxID, sandboxPid)
|
glog.V(2).Infof("Sandbox container %q is running with pid %d", sandboxID, sandboxPid)
|
||||||
|
|
||||||
// Generate containerd container create options.
|
// Generate containerd task create options.
|
||||||
imageMeta, err := c.imageMetadataStore.Get(meta.ImageRef)
|
imageMeta, err := c.imageMetadataStore.Get(meta.ImageRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get container image %q: %v", meta.ImageRef, err)
|
return fmt.Errorf("failed to get container image %q: %v", meta.ImageRef, err)
|
||||||
@ -189,7 +189,7 @@ func (c *criContainerdService) startContainer(ctx context.Context, id string, me
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create containerd container.
|
// Create containerd task.
|
||||||
createOpts := &execution.CreateRequest{
|
createOpts := &execution.CreateRequest{
|
||||||
ContainerID: id,
|
ContainerID: id,
|
||||||
Rootfs: rootfs,
|
Rootfs: rootfs,
|
||||||
@ -198,24 +198,24 @@ func (c *criContainerdService) startContainer(ctx context.Context, id string, me
|
|||||||
Stderr: stderr,
|
Stderr: stderr,
|
||||||
Terminal: config.GetTty(),
|
Terminal: config.GetTty(),
|
||||||
}
|
}
|
||||||
glog.V(5).Infof("Create containerd container (id=%q, name=%q) with options %+v.",
|
glog.V(5).Infof("Create containerd task (id=%q, name=%q) with options %+v.",
|
||||||
id, meta.Name, createOpts)
|
id, meta.Name, createOpts)
|
||||||
createResp, err := c.containerService.Create(ctx, createOpts)
|
createResp, err := c.taskService.Create(ctx, createOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create containerd container: %v", err)
|
return fmt.Errorf("failed to create containerd task: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Cleanup the containerd container if an error is returned.
|
// Cleanup the containerd task if an error is returned.
|
||||||
if _, err := c.containerService.Delete(ctx, &execution.DeleteRequest{ContainerID: id}); err != nil {
|
if _, err := c.taskService.Delete(ctx, &execution.DeleteRequest{ContainerID: id}); err != nil {
|
||||||
glog.Errorf("Failed to delete containerd container %q: %v", id, err)
|
glog.Errorf("Failed to delete containerd task %q: %v", id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Start containerd container.
|
// Start containerd task.
|
||||||
if _, err := c.containerService.Start(ctx, &execution.StartRequest{ContainerID: id}); err != nil {
|
if _, err := c.taskService.Start(ctx, &execution.StartRequest{ContainerID: id}); err != nil {
|
||||||
return fmt.Errorf("failed to start containerd container %q: %v", id, err)
|
return fmt.Errorf("failed to start containerd task %q: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update container start timestamp.
|
// Update container start timestamp.
|
||||||
|
@ -573,7 +573,7 @@ func TestStartContainer(t *testing.T) {
|
|||||||
sandboxContainerdContainer: testSandboxContainer,
|
sandboxContainerdContainer: testSandboxContainer,
|
||||||
startContainerErr: errors.New("start error"),
|
startContainerErr: errors.New("start error"),
|
||||||
expectStateChange: true,
|
expectStateChange: true,
|
||||||
// cleanup the containerd container.
|
// cleanup the containerd task.
|
||||||
expectCalls: []string{"info", "create", "start", "delete"},
|
expectCalls: []string{"info", "create", "start", "delete"},
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
@ -588,7 +588,7 @@ func TestStartContainer(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
fake := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
fakeOS := c.os.(*ostesting.FakeOS)
|
fakeOS := c.os.(*ostesting.FakeOS)
|
||||||
fakeSnapshotClient := WithFakeSnapshotClient(c)
|
fakeSnapshotClient := WithFakeSnapshotClient(c)
|
||||||
if test.containerMetadata != nil {
|
if test.containerMetadata != nil {
|
||||||
@ -598,7 +598,7 @@ func TestStartContainer(t *testing.T) {
|
|||||||
assert.NoError(t, c.sandboxStore.Create(*test.sandboxMetadata))
|
assert.NoError(t, c.sandboxStore.Create(*test.sandboxMetadata))
|
||||||
}
|
}
|
||||||
if test.sandboxContainerdContainer != nil {
|
if test.sandboxContainerdContainer != nil {
|
||||||
fake.SetFakeContainers([]task.Task{*test.sandboxContainerdContainer})
|
fake.SetFakeTasks([]task.Task{*test.sandboxContainerdContainer})
|
||||||
}
|
}
|
||||||
if !test.imageMetadataErr {
|
if !test.imageMetadataErr {
|
||||||
assert.NoError(t, c.imageMetadataStore.Create(metadata.ImageMetadata{
|
assert.NoError(t, c.imageMetadataStore.Create(metadata.ImageMetadata{
|
||||||
@ -650,8 +650,8 @@ func TestStartContainer(t *testing.T) {
|
|||||||
assert.Equal(t, errorStartReason, meta.Reason)
|
assert.Equal(t, errorStartReason, meta.Reason)
|
||||||
assert.NotEmpty(t, meta.Message)
|
assert.NotEmpty(t, meta.Message)
|
||||||
_, err := fake.Info(context.Background(), &execution.InfoRequest{ContainerID: testID})
|
_, err := fake.Info(context.Background(), &execution.InfoRequest{ContainerID: testID})
|
||||||
assert.True(t, isContainerdContainerNotExistError(err),
|
assert.True(t, isContainerdGRPCNotFoundError(err),
|
||||||
"containerd container should be cleaned up after when fail to start")
|
"containerd task should be cleaned up after when fail to start")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t.Logf("container state should be running when start successfully")
|
t.Logf("container state should be running when start successfully")
|
||||||
|
@ -69,9 +69,9 @@ func (c *criContainerdService) StopContainer(ctx context.Context, r *runtime.Sto
|
|||||||
// TODO(random-liu): [P1] Get stop signal from image config.
|
// TODO(random-liu): [P1] Get stop signal from image config.
|
||||||
stopSignal := unix.SIGTERM
|
stopSignal := unix.SIGTERM
|
||||||
glog.V(2).Infof("Stop container %q with signal %v", id, stopSignal)
|
glog.V(2).Infof("Stop container %q with signal %v", id, stopSignal)
|
||||||
_, err = c.containerService.Kill(ctx, &execution.KillRequest{ContainerID: id, Signal: uint32(stopSignal)})
|
_, err = c.taskService.Kill(ctx, &execution.KillRequest{ContainerID: id, Signal: uint32(stopSignal)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !isContainerdContainerNotExistError(err) && !isRuncProcessAlreadyFinishedError(err) {
|
if !isContainerdGRPCNotFoundError(err) && !isRuncProcessAlreadyFinishedError(err) {
|
||||||
return nil, fmt.Errorf("failed to stop container %q: %v", id, err)
|
return nil, fmt.Errorf("failed to stop container %q: %v", id, err)
|
||||||
}
|
}
|
||||||
// Move on to make sure container status is updated.
|
// Move on to make sure container status is updated.
|
||||||
@ -86,9 +86,9 @@ func (c *criContainerdService) StopContainer(ctx context.Context, r *runtime.Sto
|
|||||||
|
|
||||||
// Event handler will Delete the container from containerd after it handles the Exited event.
|
// Event handler will Delete the container from containerd after it handles the Exited event.
|
||||||
glog.V(2).Infof("Kill container %q", id)
|
glog.V(2).Infof("Kill container %q", id)
|
||||||
_, err = c.containerService.Kill(ctx, &execution.KillRequest{ContainerID: id, Signal: uint32(unix.SIGKILL)})
|
_, err = c.taskService.Kill(ctx, &execution.KillRequest{ContainerID: id, Signal: uint32(unix.SIGKILL)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !isContainerdContainerNotExistError(err) && !isRuncProcessAlreadyFinishedError(err) {
|
if !isContainerdGRPCNotFoundError(err) && !isRuncProcessAlreadyFinishedError(err) {
|
||||||
return nil, fmt.Errorf("failed to kill container %q: %v", id, err)
|
return nil, fmt.Errorf("failed to kill container %q: %v", id, err)
|
||||||
}
|
}
|
||||||
// Move on to make sure container status is updated.
|
// Move on to make sure container status is updated.
|
||||||
|
@ -125,7 +125,7 @@ func TestStopContainer(t *testing.T) {
|
|||||||
expectErr: false,
|
expectErr: false,
|
||||||
expectCalls: []servertesting.CalledDetail{},
|
expectCalls: []servertesting.CalledDetail{},
|
||||||
},
|
},
|
||||||
"should not return error if containerd container does not exist": {
|
"should not return error if containerd task does not exist": {
|
||||||
metadata: &testMetadata,
|
metadata: &testMetadata,
|
||||||
containerdContainer: &testContainer,
|
containerdContainer: &testContainer,
|
||||||
// Since it's hard to inject event during `StopContainer` is running,
|
// Since it's hard to inject event during `StopContainer` is running,
|
||||||
@ -133,7 +133,7 @@ func TestStopContainer(t *testing.T) {
|
|||||||
// status is not updated yet.
|
// status is not updated yet.
|
||||||
// We also leverage this behavior to test that when graceful
|
// We also leverage this behavior to test that when graceful
|
||||||
// stop doesn't take effect, container should be SIGKILL-ed.
|
// stop doesn't take effect, container should be SIGKILL-ed.
|
||||||
stopErr: servertesting.ContainerNotExistError,
|
stopErr: servertesting.TaskNotExistError,
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
expectCalls: []servertesting.CalledDetail{
|
expectCalls: []servertesting.CalledDetail{
|
||||||
{
|
{
|
||||||
@ -150,7 +150,7 @@ func TestStopContainer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"should not return error if containerd container process already finished": {
|
"should not return error if containerd task process already finished": {
|
||||||
metadata: &testMetadata,
|
metadata: &testMetadata,
|
||||||
containerdContainer: &testContainer,
|
containerdContainer: &testContainer,
|
||||||
stopErr: errors.New("os: process already finished"),
|
stopErr: errors.New("os: process already finished"),
|
||||||
@ -182,7 +182,7 @@ func TestStopContainer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"should not return error if containerd container is gracefully stopped": {
|
"should not return error if containerd task is gracefully stopped": {
|
||||||
metadata: &testMetadata,
|
metadata: &testMetadata,
|
||||||
containerdContainer: &testContainer,
|
containerdContainer: &testContainer,
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
@ -221,15 +221,15 @@ func TestStopContainer(t *testing.T) {
|
|||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fake := servertesting.NewFakeExecutionClient().WithEvents()
|
fake := servertesting.NewFakeExecutionClient().WithEvents()
|
||||||
defer fake.Stop()
|
defer fake.Stop()
|
||||||
c.containerService = fake
|
c.taskService = fake
|
||||||
|
|
||||||
// Inject metadata.
|
// Inject metadata.
|
||||||
if test.metadata != nil {
|
if test.metadata != nil {
|
||||||
assert.NoError(t, c.containerStore.Create(*test.metadata))
|
assert.NoError(t, c.containerStore.Create(*test.metadata))
|
||||||
}
|
}
|
||||||
// Inject containerd container.
|
// Inject containerd task.
|
||||||
if test.containerdContainer != nil {
|
if test.containerdContainer != nil {
|
||||||
fake.SetFakeContainers([]task.Task{*test.containerdContainer})
|
fake.SetFakeTasks([]task.Task{*test.containerdContainer})
|
||||||
}
|
}
|
||||||
if test.stopErr != nil {
|
if test.stopErr != nil {
|
||||||
fake.InjectError("kill", test.stopErr)
|
fake.InjectError("kill", test.stopErr)
|
||||||
|
@ -48,7 +48,7 @@ func (c *criContainerdService) startEventMonitor() {
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
events, err := c.containerService.Events(context.Background(), &execution.EventsRequest{})
|
events, err := c.taskService.Events(context.Background(), &execution.EventsRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to connect to containerd event stream: %v", err)
|
glog.Errorf("Failed to connect to containerd event stream: %v", err)
|
||||||
time.Sleep(b.Duration())
|
time.Sleep(b.Duration())
|
||||||
@ -97,8 +97,8 @@ func (c *criContainerdService) handleEvent(e *task.Event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Delete the container from containerd.
|
// Delete the container from containerd.
|
||||||
_, err = c.containerService.Delete(context.Background(), &execution.DeleteRequest{ContainerID: e.ID})
|
_, err = c.taskService.Delete(context.Background(), &execution.DeleteRequest{ContainerID: e.ID})
|
||||||
if err != nil && !isContainerdContainerNotExistError(err) {
|
if err != nil && !isContainerdGRPCNotFoundError(err) {
|
||||||
// TODO(random-liu): [P0] Enqueue the event and retry.
|
// TODO(random-liu): [P0] Enqueue the event and retry.
|
||||||
glog.Errorf("Failed to delete container %q: %v", e.ID, err)
|
glog.Errorf("Failed to delete container %q: %v", e.ID, err)
|
||||||
return
|
return
|
||||||
|
@ -93,7 +93,7 @@ func TestHandleEvent(t *testing.T) {
|
|||||||
containerdContainer: &testContainerdContainer,
|
containerdContainer: &testContainerdContainer,
|
||||||
expected: &testMetadata,
|
expected: &testMetadata,
|
||||||
},
|
},
|
||||||
"should not update state when fail to delete containerd container": {
|
"should not update state when fail to delete containerd task": {
|
||||||
event: &testExitEvent,
|
event: &testExitEvent,
|
||||||
metadata: &testMetadata,
|
metadata: &testMetadata,
|
||||||
containerdContainer: &testContainerdContainer,
|
containerdContainer: &testContainerdContainer,
|
||||||
@ -112,12 +112,12 @@ func TestHandleEvent(t *testing.T) {
|
|||||||
containerdContainer: &testContainerdContainer,
|
containerdContainer: &testContainerdContainer,
|
||||||
expected: &testMetadata,
|
expected: &testMetadata,
|
||||||
},
|
},
|
||||||
"should update state when containerd container is already deleted": {
|
"should update state when containerd task is already deleted": {
|
||||||
event: &testExitEvent,
|
event: &testExitEvent,
|
||||||
metadata: &testMetadata,
|
metadata: &testMetadata,
|
||||||
expected: &testFinishedMetadata,
|
expected: &testFinishedMetadata,
|
||||||
},
|
},
|
||||||
"should update state when delete containerd container successfully": {
|
"should update state when delete containerd task successfully": {
|
||||||
event: &testExitEvent,
|
event: &testExitEvent,
|
||||||
metadata: &testMetadata,
|
metadata: &testMetadata,
|
||||||
containerdContainer: &testContainerdContainer,
|
containerdContainer: &testContainerdContainer,
|
||||||
@ -126,7 +126,7 @@ func TestHandleEvent(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
fake := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
e, err := fake.Events(context.Background(), &execution.EventsRequest{})
|
e, err := fake.Events(context.Background(), &execution.EventsRequest{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
fakeEvents := e.(*servertesting.EventClient)
|
fakeEvents := e.(*servertesting.EventClient)
|
||||||
@ -139,9 +139,9 @@ func TestHandleEvent(t *testing.T) {
|
|||||||
// Make sure that original data will not be changed.
|
// Make sure that original data will not be changed.
|
||||||
assert.NoError(t, c.containerStore.Create(*test.metadata))
|
assert.NoError(t, c.containerStore.Create(*test.metadata))
|
||||||
}
|
}
|
||||||
// Inject containerd container.
|
// Inject containerd task.
|
||||||
if test.containerdContainer != nil {
|
if test.containerdContainer != nil {
|
||||||
fake.SetFakeContainers([]task.Task{*test.containerdContainer})
|
fake.SetFakeTasks([]task.Task{*test.containerdContainer})
|
||||||
}
|
}
|
||||||
// Inject containerd delete error.
|
// Inject containerd delete error.
|
||||||
if test.containerdErr != nil {
|
if test.containerdErr != nil {
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
containerdmetadata "github.com/containerd/containerd/metadata"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/truncindex"
|
"github.com/docker/docker/pkg/truncindex"
|
||||||
@ -33,13 +34,10 @@ import (
|
|||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
containerdmetadata "github.com/containerd/containerd/metadata"
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
||||||
"github.com/containerd/containerd/plugin"
|
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
||||||
|
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -219,11 +217,9 @@ func getPIDNamespace(pid uint32) string {
|
|||||||
return fmt.Sprintf(pidNSFormat, pid)
|
return fmt.Sprintf(pidNSFormat, pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// isContainerdContainerNotExistError checks whether a grpc error is containerd
|
// isContainerdGRPCNotFoundError checks whether a grpc error is not found error.
|
||||||
// ErrContainerNotExist error.
|
func isContainerdGRPCNotFoundError(grpcError error) bool {
|
||||||
// TODO(random-liu): Containerd should expose error better through api.
|
return grpc.Code(grpcError) == codes.NotFound
|
||||||
func isContainerdContainerNotExistError(grpcError error) bool {
|
|
||||||
return grpc.ErrorDesc(grpcError) == plugin.ErrContainerNotExist.Error()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// isRuncProcessAlreadyFinishedError checks whether a grpc error is a process already
|
// isRuncProcessAlreadyFinishedError checks whether a grpc error is a process already
|
||||||
|
@ -45,7 +45,7 @@ func (c *criContainerdService) ListPodSandbox(ctx context.Context, r *runtime.Li
|
|||||||
return nil, fmt.Errorf("failed to list metadata from sandbox store: %v", err)
|
return nil, fmt.Errorf("failed to list metadata from sandbox store: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := c.containerService.List(ctx, &execution.ListRequest{})
|
resp, err := c.taskService.List(ctx, &execution.ListRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to list sandbox containers: %v", err)
|
return nil, fmt.Errorf("failed to list sandbox containers: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ func TestFilterSandboxes(t *testing.T) {
|
|||||||
func TestListPodSandbox(t *testing.T) {
|
func TestListPodSandbox(t *testing.T) {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
|
|
||||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
fake := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
|
|
||||||
sandboxesInStore := []metadata.SandboxMetadata{
|
sandboxesInStore := []metadata.SandboxMetadata{
|
||||||
{
|
{
|
||||||
@ -197,8 +197,8 @@ func TestListPodSandbox(t *testing.T) {
|
|||||||
c.sandboxStore.Create(s)
|
c.sandboxStore.Create(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject fake containerd containers
|
// Inject fake containerd tasks
|
||||||
fake.SetFakeContainers(sandboxesInContainerd)
|
fake.SetFakeTasks(sandboxesInContainerd)
|
||||||
|
|
||||||
resp, err := c.ListPodSandbox(context.Background(), &runtime.ListPodSandboxRequest{})
|
resp, err := c.ListPodSandbox(context.Background(), &runtime.ListPodSandboxRequest{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -56,8 +56,8 @@ func (c *criContainerdService) RemovePodSandbox(ctx context.Context, r *runtime.
|
|||||||
|
|
||||||
// Return error if sandbox container is not fully stopped.
|
// Return error if sandbox container is not fully stopped.
|
||||||
// TODO(random-liu): [P0] Make sure network is torn down, may need to introduce a state.
|
// TODO(random-liu): [P0] Make sure network is torn down, may need to introduce a state.
|
||||||
_, err = c.containerService.Info(ctx, &execution.InfoRequest{ContainerID: id})
|
_, err = c.taskService.Info(ctx, &execution.InfoRequest{ContainerID: id})
|
||||||
if err != nil && !isContainerdContainerNotExistError(err) {
|
if err != nil && !isContainerdGRPCNotFoundError(err) {
|
||||||
return nil, fmt.Errorf("failed to get sandbox container info for %q: %v", id, err)
|
return nil, fmt.Errorf("failed to get sandbox container info for %q: %v", id, err)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -38,7 +38,7 @@ func TestRemovePodSandbox(t *testing.T) {
|
|||||||
Name: testName,
|
Name: testName,
|
||||||
}
|
}
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
sandboxContainers []task.Task
|
sandboxTasks []task.Task
|
||||||
injectMetadata bool
|
injectMetadata bool
|
||||||
removeSnapshotErr error
|
removeSnapshotErr error
|
||||||
injectContainerdErr error
|
injectContainerdErr error
|
||||||
@ -66,10 +66,10 @@ func TestRemovePodSandbox(t *testing.T) {
|
|||||||
expectCalls: []string{"info"},
|
expectCalls: []string{"info"},
|
||||||
},
|
},
|
||||||
"should return error when sandbox container is not deleted": {
|
"should return error when sandbox container is not deleted": {
|
||||||
injectMetadata: true,
|
injectMetadata: true,
|
||||||
sandboxContainers: []task.Task{{ID: testID}},
|
sandboxTasks: []task.Task{{ID: testID}},
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
expectCalls: []string{"info"},
|
expectCalls: []string{"info"},
|
||||||
},
|
},
|
||||||
"should return error when arbitrary containerd error is injected": {
|
"should return error when arbitrary containerd error is injected": {
|
||||||
injectMetadata: true,
|
injectMetadata: true,
|
||||||
@ -92,10 +92,10 @@ func TestRemovePodSandbox(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
fake := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
fakeOS := c.os.(*ostesting.FakeOS)
|
fakeOS := c.os.(*ostesting.FakeOS)
|
||||||
fakeSnapshotClient := WithFakeSnapshotClient(c)
|
fakeSnapshotClient := WithFakeSnapshotClient(c)
|
||||||
fake.SetFakeContainers(test.sandboxContainers)
|
fake.SetFakeTasks(test.sandboxTasks)
|
||||||
if test.injectMetadata {
|
if test.injectMetadata {
|
||||||
c.sandboxNameIndex.Reserve(testName, testID)
|
c.sandboxNameIndex.Reserve(testName, testID)
|
||||||
c.sandboxIDIndex.Add(testID)
|
c.sandboxIDIndex.Add(testID)
|
||||||
|
@ -172,7 +172,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
|
|||||||
// Create sandbox container in containerd.
|
// Create sandbox container in containerd.
|
||||||
glog.V(5).Infof("Create sandbox container (id=%q, name=%q) with options %+v.",
|
glog.V(5).Infof("Create sandbox container (id=%q, name=%q) with options %+v.",
|
||||||
id, name, createOpts)
|
id, name, createOpts)
|
||||||
createResp, err := c.containerService.Create(ctx, createOpts)
|
createResp, err := c.taskService.Create(ctx, createOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create sandbox container %q: %v",
|
return nil, fmt.Errorf("failed to create sandbox container %q: %v",
|
||||||
id, err)
|
id, err)
|
||||||
@ -180,7 +180,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
|
|||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Cleanup the sandbox container if an error is returned.
|
// Cleanup the sandbox container if an error is returned.
|
||||||
if _, err = c.containerService.Delete(ctx, &execution.DeleteRequest{ContainerID: id}); err != nil {
|
if _, err = c.taskService.Delete(ctx, &execution.DeleteRequest{ContainerID: id}); err != nil {
|
||||||
glog.Errorf("Failed to delete sandbox container %q: %v",
|
glog.Errorf("Failed to delete sandbox container %q: %v",
|
||||||
id, err)
|
id, err)
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start sandbox container in containerd.
|
// Start sandbox container in containerd.
|
||||||
if _, err := c.containerService.Start(ctx, &execution.StartRequest{ContainerID: id}); err != nil {
|
if _, err := c.taskService.Start(ctx, &execution.StartRequest{ContainerID: id}); err != nil {
|
||||||
return nil, fmt.Errorf("failed to start sandbox container %q: %v",
|
return nil, fmt.Errorf("failed to start sandbox container %q: %v",
|
||||||
id, err)
|
id, err)
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ func TestRunPodSandbox(t *testing.T) {
|
|||||||
config, imageConfig, _ := getRunPodSandboxTestData() // TODO: declare and test specCheck see below
|
config, imageConfig, _ := getRunPodSandboxTestData() // TODO: declare and test specCheck see below
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fakeSnapshotClient := WithFakeSnapshotClient(c)
|
fakeSnapshotClient := WithFakeSnapshotClient(c)
|
||||||
fakeExecutionClient := c.containerService.(*servertesting.FakeExecutionClient)
|
fakeExecutionClient := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
||||||
fakeOS := c.os.(*ostesting.FakeOS)
|
fakeOS := c.os.(*ostesting.FakeOS)
|
||||||
var dirs []string
|
var dirs []string
|
||||||
|
@ -47,8 +47,8 @@ func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime.
|
|||||||
// Use the full sandbox id.
|
// Use the full sandbox id.
|
||||||
id := sandbox.ID
|
id := sandbox.ID
|
||||||
|
|
||||||
info, err := c.containerService.Info(ctx, &execution.InfoRequest{ContainerID: id})
|
info, err := c.taskService.Info(ctx, &execution.InfoRequest{ContainerID: id})
|
||||||
if err != nil && !isContainerdContainerNotExistError(err) {
|
if err != nil && !isContainerdGRPCNotFoundError(err) {
|
||||||
return nil, fmt.Errorf("failed to get sandbox container info for %q: %v", id, err)
|
return nil, fmt.Errorf("failed to get sandbox container info for %q: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,15 +95,15 @@ func getSandboxStatusTestData() (*metadata.SandboxMetadata, *runtime.PodSandboxS
|
|||||||
|
|
||||||
func TestPodSandboxStatus(t *testing.T) {
|
func TestPodSandboxStatus(t *testing.T) {
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
sandboxContainers []task.Task
|
sandboxTasks []task.Task
|
||||||
injectMetadata bool
|
injectMetadata bool
|
||||||
injectErr error
|
injectErr error
|
||||||
injectIP bool
|
injectIP bool
|
||||||
injectCNIErr error
|
injectCNIErr error
|
||||||
expectState runtime.PodSandboxState
|
expectState runtime.PodSandboxState
|
||||||
expectErr bool
|
expectErr bool
|
||||||
expectCalls []string
|
expectCalls []string
|
||||||
expectedCNICalls []string
|
expectedCNICalls []string
|
||||||
}{
|
}{
|
||||||
"sandbox status without metadata": {
|
"sandbox status without metadata": {
|
||||||
injectMetadata: false,
|
injectMetadata: false,
|
||||||
@ -112,7 +112,7 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
expectedCNICalls: []string{},
|
expectedCNICalls: []string{},
|
||||||
},
|
},
|
||||||
"sandbox status with running sandbox container": {
|
"sandbox status with running sandbox container": {
|
||||||
sandboxContainers: []task.Task{{
|
sandboxTasks: []task.Task{{
|
||||||
ID: sandboxStatusTestID,
|
ID: sandboxStatusTestID,
|
||||||
Pid: 1,
|
Pid: 1,
|
||||||
Status: task.StatusRunning,
|
Status: task.StatusRunning,
|
||||||
@ -123,7 +123,7 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
||||||
},
|
},
|
||||||
"sandbox status with stopped sandbox container": {
|
"sandbox status with stopped sandbox container": {
|
||||||
sandboxContainers: []task.Task{{
|
sandboxTasks: []task.Task{{
|
||||||
ID: sandboxStatusTestID,
|
ID: sandboxStatusTestID,
|
||||||
Pid: 1,
|
Pid: 1,
|
||||||
Status: task.StatusStopped,
|
Status: task.StatusStopped,
|
||||||
@ -134,14 +134,14 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
||||||
},
|
},
|
||||||
"sandbox status with non-existing sandbox container": {
|
"sandbox status with non-existing sandbox container": {
|
||||||
sandboxContainers: []task.Task{},
|
sandboxTasks: []task.Task{},
|
||||||
injectMetadata: true,
|
injectMetadata: true,
|
||||||
expectState: runtime.PodSandboxState_SANDBOX_NOTREADY,
|
expectState: runtime.PodSandboxState_SANDBOX_NOTREADY,
|
||||||
expectCalls: []string{"info"},
|
expectCalls: []string{"info"},
|
||||||
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
||||||
},
|
},
|
||||||
"sandbox status with arbitrary error": {
|
"sandbox status with arbitrary error": {
|
||||||
sandboxContainers: []task.Task{{
|
sandboxTasks: []task.Task{{
|
||||||
ID: sandboxStatusTestID,
|
ID: sandboxStatusTestID,
|
||||||
Pid: 1,
|
Pid: 1,
|
||||||
Status: task.StatusRunning,
|
Status: task.StatusRunning,
|
||||||
@ -154,7 +154,7 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
expectedCNICalls: []string{},
|
expectedCNICalls: []string{},
|
||||||
},
|
},
|
||||||
"sandbox status with IP address": {
|
"sandbox status with IP address": {
|
||||||
sandboxContainers: []task.Task{{
|
sandboxTasks: []task.Task{{
|
||||||
ID: sandboxStatusTestID,
|
ID: sandboxStatusTestID,
|
||||||
Pid: 1,
|
Pid: 1,
|
||||||
Status: task.StatusRunning,
|
Status: task.StatusRunning,
|
||||||
@ -166,7 +166,7 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
expectedCNICalls: []string{"GetContainerNetworkStatus"},
|
||||||
},
|
},
|
||||||
"sandbox status with GetContainerNetworkStatus returns error": {
|
"sandbox status with GetContainerNetworkStatus returns error": {
|
||||||
sandboxContainers: []task.Task{{
|
sandboxTasks: []task.Task{{
|
||||||
ID: sandboxStatusTestID,
|
ID: sandboxStatusTestID,
|
||||||
Pid: 1,
|
Pid: 1,
|
||||||
Status: task.StatusRunning,
|
Status: task.StatusRunning,
|
||||||
@ -182,9 +182,9 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
metadata, expect := getSandboxStatusTestData()
|
metadata, expect := getSandboxStatusTestData()
|
||||||
expect.Network.Ip = ""
|
expect.Network.Ip = ""
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
fake := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
||||||
fake.SetFakeContainers(test.sandboxContainers)
|
fake.SetFakeTasks(test.sandboxTasks)
|
||||||
if test.injectMetadata {
|
if test.injectMetadata {
|
||||||
assert.NoError(t, c.sandboxIDIndex.Add(metadata.ID))
|
assert.NoError(t, c.sandboxIDIndex.Add(metadata.ID))
|
||||||
assert.NoError(t, c.sandboxStore.Create(*metadata))
|
assert.NoError(t, c.sandboxStore.Create(*metadata))
|
||||||
|
@ -60,8 +60,8 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St
|
|||||||
|
|
||||||
// TODO(random-liu): [P1] Handle sandbox container graceful deletion.
|
// TODO(random-liu): [P1] Handle sandbox container graceful deletion.
|
||||||
// Delete the sandbox container from containerd.
|
// Delete the sandbox container from containerd.
|
||||||
_, err = c.containerService.Delete(ctx, &execution.DeleteRequest{ContainerID: id})
|
_, err = c.taskService.Delete(ctx, &execution.DeleteRequest{ContainerID: id})
|
||||||
if err != nil && !isContainerdContainerNotExistError(err) {
|
if err != nil && !isContainerdGRPCNotFoundError(err) {
|
||||||
return nil, fmt.Errorf("failed to delete sandbox container %q: %v", id, err)
|
return nil, fmt.Errorf("failed to delete sandbox container %q: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,14 +21,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"github.com/containerd/containerd/api/types/task"
|
|
||||||
"github.com/containerd/containerd/plugin"
|
|
||||||
|
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
||||||
@ -56,14 +53,14 @@ func TestStopPodSandbox(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
sandboxContainers []task.Task
|
sandboxTasks []task.Task
|
||||||
injectSandbox bool
|
injectSandbox bool
|
||||||
injectErr error
|
injectErr error
|
||||||
injectStatErr error
|
injectStatErr error
|
||||||
injectCNIErr error
|
injectCNIErr error
|
||||||
expectErr bool
|
expectErr bool
|
||||||
expectCalls []string
|
expectCalls []string
|
||||||
expectedCNICalls []string
|
expectedCNICalls []string
|
||||||
}{
|
}{
|
||||||
"stop non-existing sandbox": {
|
"stop non-existing sandbox": {
|
||||||
injectSandbox: false,
|
injectSandbox: false,
|
||||||
@ -72,17 +69,17 @@ func TestStopPodSandbox(t *testing.T) {
|
|||||||
expectedCNICalls: []string{},
|
expectedCNICalls: []string{},
|
||||||
},
|
},
|
||||||
"stop sandbox with sandbox container": {
|
"stop sandbox with sandbox container": {
|
||||||
sandboxContainers: []task.Task{testContainer},
|
sandboxTasks: []task.Task{testContainer},
|
||||||
injectSandbox: true,
|
injectSandbox: true,
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
expectCalls: []string{"delete"},
|
expectCalls: []string{"delete"},
|
||||||
expectedCNICalls: []string{"TearDownPod"},
|
expectedCNICalls: []string{"TearDownPod"},
|
||||||
},
|
},
|
||||||
"stop sandbox with sandbox container not exist error": {
|
"stop sandbox with sandbox container not exist error": {
|
||||||
sandboxContainers: []task.Task{},
|
sandboxTasks: []task.Task{},
|
||||||
injectSandbox: true,
|
injectSandbox: true,
|
||||||
// Inject error to make sure fake execution client returns error.
|
// Inject error to make sure fake execution client returns error.
|
||||||
injectErr: grpc.Errorf(codes.Unknown, plugin.ErrContainerNotExist.Error()),
|
injectErr: servertesting.TaskNotExistError,
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
expectCalls: []string{"delete"},
|
expectCalls: []string{"delete"},
|
||||||
expectedCNICalls: []string{"TearDownPod"},
|
expectedCNICalls: []string{"TearDownPod"},
|
||||||
@ -95,36 +92,36 @@ func TestStopPodSandbox(t *testing.T) {
|
|||||||
expectedCNICalls: []string{"TearDownPod"},
|
expectedCNICalls: []string{"TearDownPod"},
|
||||||
},
|
},
|
||||||
"stop sandbox with Stat returns arbitrary error": {
|
"stop sandbox with Stat returns arbitrary error": {
|
||||||
sandboxContainers: []task.Task{testContainer},
|
sandboxTasks: []task.Task{testContainer},
|
||||||
injectSandbox: true,
|
injectSandbox: true,
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
injectStatErr: errors.New("arbitrary error"),
|
injectStatErr: errors.New("arbitrary error"),
|
||||||
expectCalls: []string{},
|
expectCalls: []string{},
|
||||||
expectedCNICalls: []string{},
|
expectedCNICalls: []string{},
|
||||||
},
|
},
|
||||||
"stop sandbox with Stat returns not exist error": {
|
"stop sandbox with Stat returns not exist error": {
|
||||||
sandboxContainers: []task.Task{testContainer},
|
sandboxTasks: []task.Task{testContainer},
|
||||||
injectSandbox: true,
|
injectSandbox: true,
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
expectCalls: []string{"delete"},
|
expectCalls: []string{"delete"},
|
||||||
injectStatErr: os.ErrNotExist,
|
injectStatErr: os.ErrNotExist,
|
||||||
expectedCNICalls: []string{},
|
expectedCNICalls: []string{},
|
||||||
},
|
},
|
||||||
"stop sandbox with TearDownPod fails": {
|
"stop sandbox with TearDownPod fails": {
|
||||||
sandboxContainers: []task.Task{testContainer},
|
sandboxTasks: []task.Task{testContainer},
|
||||||
injectSandbox: true,
|
injectSandbox: true,
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
expectedCNICalls: []string{"TearDownPod"},
|
expectedCNICalls: []string{"TearDownPod"},
|
||||||
injectCNIErr: errors.New("arbitrary error"),
|
injectCNIErr: errors.New("arbitrary error"),
|
||||||
expectCalls: []string{},
|
expectCalls: []string{},
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
fake := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
||||||
fakeOS := c.os.(*ostesting.FakeOS)
|
fakeOS := c.os.(*ostesting.FakeOS)
|
||||||
fake.SetFakeContainers(test.sandboxContainers)
|
fake.SetFakeTasks(test.sandboxTasks)
|
||||||
|
|
||||||
if test.injectSandbox {
|
if test.injectSandbox {
|
||||||
assert.NoError(t, c.sandboxStore.Create(testSandbox))
|
assert.NoError(t, c.sandboxStore.Create(testSandbox))
|
||||||
|
@ -77,8 +77,8 @@ type criContainerdService struct {
|
|||||||
// containerNameIndex stores all container names and make sure each
|
// containerNameIndex stores all container names and make sure each
|
||||||
// name is unique.
|
// name is unique.
|
||||||
containerNameIndex *registrar.Registrar
|
containerNameIndex *registrar.Registrar
|
||||||
// containerService is containerd tasks client.
|
// taskService is containerd tasks client.
|
||||||
containerService execution.TasksClient
|
taskService execution.TasksClient
|
||||||
// contentStoreService is the containerd content service client.
|
// contentStoreService is the containerd content service client.
|
||||||
contentStoreService content.Store
|
contentStoreService content.Store
|
||||||
// snapshotService is the containerd snapshot service client.
|
// snapshotService is the containerd snapshot service client.
|
||||||
@ -114,7 +114,7 @@ func NewCRIContainerdService(conn *grpc.ClientConn, rootDir, networkPluginBinDir
|
|||||||
sandboxIDIndex: truncindex.NewTruncIndex(nil),
|
sandboxIDIndex: truncindex.NewTruncIndex(nil),
|
||||||
// TODO(random-liu): Add container id index.
|
// TODO(random-liu): Add container id index.
|
||||||
containerNameIndex: registrar.NewRegistrar(),
|
containerNameIndex: registrar.NewRegistrar(),
|
||||||
containerService: execution.NewTasksClient(conn),
|
taskService: execution.NewTasksClient(conn),
|
||||||
imageStoreService: imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(conn)),
|
imageStoreService: imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(conn)),
|
||||||
contentStoreService: contentservice.NewStoreFromClient(contentapi.NewContentClient(conn)),
|
contentStoreService: contentservice.NewStoreFromClient(contentapi.NewContentClient(conn)),
|
||||||
snapshotService: snapshotservice.NewSnapshotterFromClient(snapshotapi.NewSnapshotClient(conn)),
|
snapshotService: snapshotservice.NewSnapshotterFromClient(snapshotapi.NewSnapshotClient(conn)),
|
||||||
|
@ -65,7 +65,7 @@ func newTestCRIContainerdService() *criContainerdService {
|
|||||||
sandboxIDIndex: truncindex.NewTruncIndex(nil),
|
sandboxIDIndex: truncindex.NewTruncIndex(nil),
|
||||||
containerStore: metadata.NewContainerStore(store.NewMetadataStore()),
|
containerStore: metadata.NewContainerStore(store.NewMetadataStore()),
|
||||||
containerNameIndex: registrar.NewRegistrar(),
|
containerNameIndex: registrar.NewRegistrar(),
|
||||||
containerService: servertesting.NewFakeExecutionClient(),
|
taskService: servertesting.NewFakeExecutionClient(),
|
||||||
netPlugin: servertesting.NewFakeCNIPlugin(),
|
netPlugin: servertesting.NewFakeCNIPlugin(),
|
||||||
agentFactory: agentstesting.NewFakeAgentFactory(),
|
agentFactory: agentstesting.NewFakeAgentFactory(),
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func WithFakeSnapshotClient(c *criContainerdService) *servertesting.FakeSnapshot
|
|||||||
// Test all sandbox operations.
|
// Test all sandbox operations.
|
||||||
func TestSandboxOperations(t *testing.T) {
|
func TestSandboxOperations(t *testing.T) {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIContainerdService()
|
||||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
fake := c.taskService.(*servertesting.FakeExecutionClient)
|
||||||
fakeOS := c.os.(*ostesting.FakeOS)
|
fakeOS := c.os.(*ostesting.FakeOS)
|
||||||
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
||||||
WithFakeSnapshotClient(c)
|
WithFakeSnapshotClient(c)
|
||||||
|
@ -24,15 +24,14 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd/api/services/execution"
|
"github.com/containerd/containerd/api/services/execution"
|
||||||
"github.com/containerd/containerd/api/types/task"
|
"github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/containerd/containerd/plugin"
|
|
||||||
googleprotobuf "github.com/golang/protobuf/ptypes/empty"
|
googleprotobuf "github.com/golang/protobuf/ptypes/empty"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerNotExistError is the fake error returned when container does not exist.
|
// TaskNotExistError is the fake error returned when task does not exist.
|
||||||
var ContainerNotExistError = grpc.Errorf(codes.Unknown, plugin.ErrContainerNotExist.Error())
|
var TaskNotExistError = grpc.Errorf(codes.NotFound, "task does not exist")
|
||||||
|
|
||||||
// CalledDetail is the struct contains called function name and arguments.
|
// CalledDetail is the struct contains called function name and arguments.
|
||||||
type CalledDetail struct {
|
type CalledDetail struct {
|
||||||
@ -44,7 +43,7 @@ type CalledDetail struct {
|
|||||||
|
|
||||||
var _ execution.Tasks_EventsClient = &EventClient{}
|
var _ execution.Tasks_EventsClient = &EventClient{}
|
||||||
|
|
||||||
// EventClient is a test implementation of execution.ContainerService_EventsClient
|
// EventClient is a test implementation of execution.Tasks_EventsClient
|
||||||
type EventClient struct {
|
type EventClient struct {
|
||||||
Events chan *task.Event
|
Events chan *task.Event
|
||||||
grpc.ClientStream
|
grpc.ClientStream
|
||||||
@ -63,11 +62,11 @@ func (cli *EventClient) Recv() (*task.Event, error) {
|
|||||||
// can be run for testing without requiring a real containerd setup.
|
// can be run for testing without requiring a real containerd setup.
|
||||||
type FakeExecutionClient struct {
|
type FakeExecutionClient struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
called []CalledDetail
|
called []CalledDetail
|
||||||
errors map[string]error
|
errors map[string]error
|
||||||
ContainerList map[string]task.Task
|
TaskList map[string]task.Task
|
||||||
eventsQueue chan *task.Event
|
eventsQueue chan *task.Event
|
||||||
eventClients []*EventClient
|
eventClients []*EventClient
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ execution.TasksClient = &FakeExecutionClient{}
|
var _ execution.TasksClient = &FakeExecutionClient{}
|
||||||
@ -75,8 +74,8 @@ var _ execution.TasksClient = &FakeExecutionClient{}
|
|||||||
// NewFakeExecutionClient creates a FakeExecutionClient
|
// NewFakeExecutionClient creates a FakeExecutionClient
|
||||||
func NewFakeExecutionClient() *FakeExecutionClient {
|
func NewFakeExecutionClient() *FakeExecutionClient {
|
||||||
return &FakeExecutionClient{
|
return &FakeExecutionClient{
|
||||||
errors: make(map[string]error),
|
errors: make(map[string]error),
|
||||||
ContainerList: make(map[string]task.Task),
|
TaskList: make(map[string]task.Task),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,12 +182,12 @@ func (f *FakeExecutionClient) GetCalledDetails() []CalledDetail {
|
|||||||
return append([]CalledDetail{}, f.called...)
|
return append([]CalledDetail{}, f.called...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFakeContainers injects fake containers.
|
// SetFakeTasks injects fake tasks.
|
||||||
func (f *FakeExecutionClient) SetFakeContainers(containers []task.Task) {
|
func (f *FakeExecutionClient) SetFakeTasks(tasks []task.Task) {
|
||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
for _, c := range containers {
|
for _, t := range tasks {
|
||||||
f.ContainerList[c.ID] = c
|
f.TaskList[t.ID] = t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,12 +199,12 @@ func (f *FakeExecutionClient) Create(ctx context.Context, createOpts *execution.
|
|||||||
if err := f.getError("create"); err != nil {
|
if err := f.getError("create"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_, ok := f.ContainerList[createOpts.ContainerID]
|
_, ok := f.TaskList[createOpts.ContainerID]
|
||||||
if ok {
|
if ok {
|
||||||
return nil, plugin.ErrContainerExists
|
return nil, fmt.Errorf("task already exists")
|
||||||
}
|
}
|
||||||
pid := generatePid()
|
pid := generatePid()
|
||||||
f.ContainerList[createOpts.ContainerID] = task.Task{
|
f.TaskList[createOpts.ContainerID] = task.Task{
|
||||||
ContainerID: createOpts.ContainerID,
|
ContainerID: createOpts.ContainerID,
|
||||||
Pid: pid,
|
Pid: pid,
|
||||||
Status: task.StatusCreated,
|
Status: task.StatusCreated,
|
||||||
@ -229,9 +228,9 @@ func (f *FakeExecutionClient) Start(ctx context.Context, startOpts *execution.St
|
|||||||
if err := f.getError("start"); err != nil {
|
if err := f.getError("start"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c, ok := f.ContainerList[startOpts.ContainerID]
|
c, ok := f.TaskList[startOpts.ContainerID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ContainerNotExistError
|
return nil, TaskNotExistError
|
||||||
}
|
}
|
||||||
f.sendEvent(&task.Event{
|
f.sendEvent(&task.Event{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
@ -241,7 +240,7 @@ func (f *FakeExecutionClient) Start(ctx context.Context, startOpts *execution.St
|
|||||||
switch c.Status {
|
switch c.Status {
|
||||||
case task.StatusCreated:
|
case task.StatusCreated:
|
||||||
c.Status = task.StatusRunning
|
c.Status = task.StatusRunning
|
||||||
f.ContainerList[startOpts.ContainerID] = c
|
f.TaskList[startOpts.ContainerID] = c
|
||||||
return &googleprotobuf.Empty{}, nil
|
return &googleprotobuf.Empty{}, nil
|
||||||
case task.StatusStopped:
|
case task.StatusStopped:
|
||||||
return &googleprotobuf.Empty{}, fmt.Errorf("cannot start a container that has stopped")
|
return &googleprotobuf.Empty{}, fmt.Errorf("cannot start a container that has stopped")
|
||||||
@ -260,11 +259,11 @@ func (f *FakeExecutionClient) Delete(ctx context.Context, deleteOpts *execution.
|
|||||||
if err := f.getError("delete"); err != nil {
|
if err := f.getError("delete"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c, ok := f.ContainerList[deleteOpts.ContainerID]
|
c, ok := f.TaskList[deleteOpts.ContainerID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ContainerNotExistError
|
return nil, TaskNotExistError
|
||||||
}
|
}
|
||||||
delete(f.ContainerList, deleteOpts.ContainerID)
|
delete(f.TaskList, deleteOpts.ContainerID)
|
||||||
f.sendEvent(&task.Event{
|
f.sendEvent(&task.Event{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
Type: task.Event_EXIT,
|
Type: task.Event_EXIT,
|
||||||
@ -281,9 +280,9 @@ func (f *FakeExecutionClient) Info(ctx context.Context, infoOpts *execution.Info
|
|||||||
if err := f.getError("info"); err != nil {
|
if err := f.getError("info"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c, ok := f.ContainerList[infoOpts.ContainerID]
|
c, ok := f.TaskList[infoOpts.ContainerID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ContainerNotExistError
|
return nil, TaskNotExistError
|
||||||
}
|
}
|
||||||
return &execution.InfoResponse{Task: &c}, nil
|
return &execution.InfoResponse{Task: &c}, nil
|
||||||
}
|
}
|
||||||
@ -297,7 +296,7 @@ func (f *FakeExecutionClient) List(ctx context.Context, listOpts *execution.List
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := &execution.ListResponse{}
|
resp := &execution.ListResponse{}
|
||||||
for _, c := range f.ContainerList {
|
for _, c := range f.TaskList {
|
||||||
resp.Tasks = append(resp.Tasks, &task.Task{
|
resp.Tasks = append(resp.Tasks, &task.Task{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
Pid: c.Pid,
|
Pid: c.Pid,
|
||||||
@ -315,12 +314,12 @@ func (f *FakeExecutionClient) Kill(ctx context.Context, killOpts *execution.Kill
|
|||||||
if err := f.getError("kill"); err != nil {
|
if err := f.getError("kill"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c, ok := f.ContainerList[killOpts.ContainerID]
|
c, ok := f.TaskList[killOpts.ContainerID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ContainerNotExistError
|
return nil, TaskNotExistError
|
||||||
}
|
}
|
||||||
c.Status = task.StatusStopped
|
c.Status = task.StatusStopped
|
||||||
f.ContainerList[killOpts.ContainerID] = c
|
f.TaskList[killOpts.ContainerID] = c
|
||||||
f.sendEvent(&task.Event{
|
f.sendEvent(&task.Event{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
Type: task.Event_EXIT,
|
Type: task.Event_EXIT,
|
||||||
|
Loading…
Reference in New Issue
Block a user