diff --git a/hack/versions b/hack/versions index 191829955..66ff2ad34 100644 --- a/hack/versions +++ b/hack/versions @@ -1,4 +1,4 @@ RUNC_VERSION=639454475cb9c8b861cc599f8bcd5c8c790ae402 CNI_VERSION=v0.4.0 CONTAINERD_VERSION=8ed1e24ae925b5c6d8195858ee89dddb0507d65f -CRITEST_VERSION=v0.1 +CRITEST_VERSION=74bbd4e142f752f13c648d9dde23defed3e472a2 diff --git a/pkg/metadata/container.go b/pkg/metadata/container.go index 5567d91d7..4fba290d7 100644 --- a/pkg/metadata/container.go +++ b/pkg/metadata/container.go @@ -19,7 +19,6 @@ package metadata import ( "encoding/json" - runtimespec "github.com/opencontainers/runtime-spec/specs-go" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store" @@ -74,11 +73,6 @@ type ContainerMetadata struct { // into the store directly. // TODO(random-liu): Reset this field to false during state recovery. Removing bool - // TODO(random-liu): Remove following field after switching to new containerd - // client. - // Not including them in unit test now because they will be removed soon. - // Spec is the oci runtime spec used to run the container. - Spec *runtimespec.Spec } // State returns current state of the container based on the metadata. diff --git a/pkg/server/container_create.go b/pkg/server/container_create.go index 9467311bb..81f3d636b 100644 --- a/pkg/server/container_create.go +++ b/pkg/server/container_create.go @@ -160,7 +160,6 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C // Update container CreatedAt. meta.CreatedAt = time.Now().UnixNano() - meta.Spec = spec // Add container into container store. if err := c.containerStore.Create(meta); err != nil { return nil, fmt.Errorf("failed to add container metadata %+v into store: %v", diff --git a/pkg/server/container_create_test.go b/pkg/server/container_create_test.go index 85a0cdd6a..be25b255b 100644 --- a/pkg/server/container_create_test.go +++ b/pkg/server/container_create_test.go @@ -592,7 +592,6 @@ func TestCreateContainer(t *testing.T) { test.expectMeta.ID = id // TODO(random-liu): Use fake clock to test CreatedAt. test.expectMeta.CreatedAt = meta.CreatedAt - test.expectMeta.Spec = spec assert.Equal(t, test.expectMeta, meta, "container metadata should be created") } } diff --git a/pkg/server/container_execsync.go b/pkg/server/container_execsync.go index 009768dde..dcdf9fc8a 100644 --- a/pkg/server/container_execsync.go +++ b/pkg/server/container_execsync.go @@ -23,6 +23,7 @@ import ( "io" "io/ioutil" + "github.com/containerd/containerd/api/services/containers" "github.com/containerd/containerd/api/services/execution" "github.com/containerd/containerd/api/types/task" prototypes "github.com/gogo/protobuf/types" @@ -44,7 +45,7 @@ func (c *criContainerdService) ExecSync(ctx context.Context, r *runtime.ExecSync } }() - // Get container config from container store. + // Get container metadata from our container store. meta, err := c.containerStore.Get(r.GetContainerId()) if err != nil { return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err) @@ -55,6 +56,22 @@ func (c *criContainerdService) ExecSync(ctx context.Context, r *runtime.ExecSync return nil, fmt.Errorf("container %q is in %s state", id, criContainerStateToString(meta.State())) } + // Get exec process spec. + cntrResp, err := c.containerService.Get(ctx, &containers.GetContainerRequest{ID: id}) + if err != nil { + return nil, fmt.Errorf("failed to get container %q from containerd: %v", id, err) + } + var spec runtimespec.Spec + if err := json.Unmarshal(cntrResp.Container.Spec.Value, &spec); err != nil { + return nil, fmt.Errorf("failed to unmarshal container spec: %v", err) + } + pspec := &spec.Process + pspec.Args = r.GetCmd() + rawSpec, err := json.Marshal(pspec) + if err != nil { + return nil, fmt.Errorf("failed to marshal oci process spec %+v: %v", pspec, err) + } + // TODO(random-liu): Replace the following logic with containerd client and add unit test. // Prepare streaming pipes. execDir, err := ioutil.TempDir(getContainerRootDir(c.rootDir, id), "exec") @@ -88,13 +105,6 @@ func (c *criContainerdService) ExecSync(ctx context.Context, r *runtime.ExecSync return nil, fmt.Errorf("failed to get containerd event: %v", err) } - spec := &meta.Spec.Process - spec.Args = r.GetCmd() - rawSpec, err := json.Marshal(spec) - if err != nil { - return nil, fmt.Errorf("failed to marshal oci spec %+v: %v", spec, err) - } - resp, err := c.taskService.Exec(ctx, &execution.ExecRequest{ ContainerID: id, Terminal: false,