From 60d8430ac1002fb54adf6eb208a782877fb6f0e7 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Fri, 25 Aug 2017 01:37:55 +0000 Subject: [PATCH] Do not checkpoint sandbox pid. Signed-off-by: Lantao Liu --- pkg/server/container_create.go | 7 ++++++- pkg/server/sandbox_portforward.go | 8 ++++++-- pkg/server/sandbox_run.go | 6 ------ pkg/store/sandbox/metadata.go | 2 -- pkg/store/sandbox/sandbox_test.go | 3 --- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pkg/server/container_create.go b/pkg/server/container_create.go index 8cc74b5c5..0bc8857fc 100644 --- a/pkg/server/container_create.go +++ b/pkg/server/container_create.go @@ -44,6 +44,11 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C return nil, fmt.Errorf("failed to find sandbox id %q: %v", r.GetPodSandboxId(), err) } sandboxID := sandbox.ID + s, err := sandbox.Container.Task(ctx, nil) + if err != nil { + return nil, fmt.Errorf("failed to get sandbox container task: %v", err) + } + sandboxPid := s.Pid() // Generate unique id and name for the container and reserve the name. // Reserve the container name to avoid concurrent `CreateContainer` request creating @@ -81,7 +86,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C // Generate container runtime spec. mounts := c.generateContainerMounts(getSandboxRootDir(c.rootDir, sandboxID), config) - spec, err := c.generateContainerSpec(id, sandbox.Pid, config, sandboxConfig, image.Config, mounts) + spec, err := c.generateContainerSpec(id, sandboxPid, config, sandboxConfig, image.Config, mounts) if err != nil { return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err) } diff --git a/pkg/server/sandbox_portforward.go b/pkg/server/sandbox_portforward.go index 331093bba..0a3e5b975 100644 --- a/pkg/server/sandbox_portforward.go +++ b/pkg/server/sandbox_portforward.go @@ -40,7 +40,7 @@ func (c *criContainerdService) PortForward(ctx context.Context, r *runtime.PortF t, err := sandbox.Container.Task(ctx, nil) if err != nil { - return nil, fmt.Errorf("failed to get sandbox container: %v", err) + return nil, fmt.Errorf("failed to get sandbox container task: %v", err) } status, err := t.Status(ctx) if err != nil { @@ -61,7 +61,11 @@ func (c *criContainerdService) portForward(id string, port int32, stream io.Read if err != nil { return fmt.Errorf("failed to find sandbox in store: %v", err) } - pid := s.Pid + t, err := s.Container.Task(context.Background(), nil) + if err != nil { + return fmt.Errorf("failed to get sandbox container task: %v", err) + } + pid := t.Pid() socat, err := exec.LookPath("socat") if err != nil { diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go index f01be8458..de16cf23c 100644 --- a/pkg/server/sandbox_run.go +++ b/pkg/server/sandbox_run.go @@ -118,11 +118,6 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run glog.V(4).Infof("Sandbox container spec: %+v", spec) // Checkpoint metadata into container - // TODO(random-liu): Switch to extensions(after merge containerd #1378). - // Actually the Pid, NetNS and CreatedAt underlying are not included here. - // I'm fine with this for now. After this PR is merged, we could: - // 1.Get Pid from containerd, so that we don't need to checkpoint it ourselves; - // 2.Use permanent NetNS after #138 is merged, so that we'll have network namespace here. metaBytes, err := sandbox.Metadata.Encode() if err != nil { return nil, fmt.Errorf("failed to convert sandbox metadata: %+v, %v", sandbox.Metadata, err) @@ -194,7 +189,6 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run } }() - sandbox.Pid = task.Pid() if err = task.Start(ctx); err != nil { return nil, fmt.Errorf("failed to start sandbox container task %q: %v", id, err) diff --git a/pkg/store/sandbox/metadata.go b/pkg/store/sandbox/metadata.go index 3051f3d4e..764742aef 100644 --- a/pkg/store/sandbox/metadata.go +++ b/pkg/store/sandbox/metadata.go @@ -46,8 +46,6 @@ type Metadata struct { Name string // Config is the CRI sandbox config. Config *runtime.PodSandboxConfig - // Pid is the process id of the sandbox. - Pid uint32 // NetNSPath is the network namespace used by the sandbox. NetNSPath string } diff --git a/pkg/store/sandbox/sandbox_test.go b/pkg/store/sandbox/sandbox_test.go index 089273f02..4d1e25d82 100644 --- a/pkg/store/sandbox/sandbox_test.go +++ b/pkg/store/sandbox/sandbox_test.go @@ -39,7 +39,6 @@ func TestSandboxStore(t *testing.T) { Attempt: 1, }, }, - Pid: 1001, NetNSPath: "TestNetNS-1", }, "2": { @@ -53,7 +52,6 @@ func TestSandboxStore(t *testing.T) { Attempt: 2, }, }, - Pid: 1002, NetNSPath: "TestNetNS-2", }, "3": { @@ -67,7 +65,6 @@ func TestSandboxStore(t *testing.T) { Attempt: 3, }, }, - Pid: 1003, NetNSPath: "TestNetNS-3", }, }