Merge pull request #102 from Random-Liu/get-spec-from-metadata
Get spec from metadata
This commit is contained in:
commit
e5d69aa537
@ -1,4 +1,4 @@
|
|||||||
RUNC_VERSION=639454475cb9c8b861cc599f8bcd5c8c790ae402
|
RUNC_VERSION=639454475cb9c8b861cc599f8bcd5c8c790ae402
|
||||||
CNI_VERSION=v0.4.0
|
CNI_VERSION=v0.4.0
|
||||||
CONTAINERD_VERSION=8ed1e24ae925b5c6d8195858ee89dddb0507d65f
|
CONTAINERD_VERSION=8ed1e24ae925b5c6d8195858ee89dddb0507d65f
|
||||||
CRITEST_VERSION=v0.1
|
CRITEST_VERSION=74bbd4e142f752f13c648d9dde23defed3e472a2
|
||||||
|
@ -19,7 +19,6 @@ package metadata
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
|
||||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store"
|
||||||
@ -74,11 +73,6 @@ type ContainerMetadata struct {
|
|||||||
// into the store directly.
|
// into the store directly.
|
||||||
// TODO(random-liu): Reset this field to false during state recovery.
|
// TODO(random-liu): Reset this field to false during state recovery.
|
||||||
Removing bool
|
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.
|
// State returns current state of the container based on the metadata.
|
||||||
|
@ -160,7 +160,6 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
|
|||||||
|
|
||||||
// Update container CreatedAt.
|
// Update container CreatedAt.
|
||||||
meta.CreatedAt = time.Now().UnixNano()
|
meta.CreatedAt = time.Now().UnixNano()
|
||||||
meta.Spec = spec
|
|
||||||
// Add container into container store.
|
// Add container into container store.
|
||||||
if err := c.containerStore.Create(meta); err != nil {
|
if err := c.containerStore.Create(meta); err != nil {
|
||||||
return nil, fmt.Errorf("failed to add container metadata %+v into store: %v",
|
return nil, fmt.Errorf("failed to add container metadata %+v into store: %v",
|
||||||
|
@ -592,7 +592,6 @@ func TestCreateContainer(t *testing.T) {
|
|||||||
test.expectMeta.ID = id
|
test.expectMeta.ID = id
|
||||||
// TODO(random-liu): Use fake clock to test CreatedAt.
|
// TODO(random-liu): Use fake clock to test CreatedAt.
|
||||||
test.expectMeta.CreatedAt = meta.CreatedAt
|
test.expectMeta.CreatedAt = meta.CreatedAt
|
||||||
test.expectMeta.Spec = spec
|
|
||||||
assert.Equal(t, test.expectMeta, meta, "container metadata should be created")
|
assert.Equal(t, test.expectMeta, meta, "container metadata should be created")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/api/services/containers"
|
||||||
"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"
|
||||||
prototypes "github.com/gogo/protobuf/types"
|
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())
|
meta, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err)
|
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()))
|
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.
|
// TODO(random-liu): Replace the following logic with containerd client and add unit test.
|
||||||
// Prepare streaming pipes.
|
// Prepare streaming pipes.
|
||||||
execDir, err := ioutil.TempDir(getContainerRootDir(c.rootDir, id), "exec")
|
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)
|
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{
|
resp, err := c.taskService.Exec(ctx, &execution.ExecRequest{
|
||||||
ContainerID: id,
|
ContainerID: id,
|
||||||
Terminal: false,
|
Terminal: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user