Do not checkpoint sandbox pid.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2017-08-25 01:37:55 +00:00
parent e559804b37
commit 60d8430ac1
5 changed files with 12 additions and 14 deletions

View File

@ -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) return nil, fmt.Errorf("failed to find sandbox id %q: %v", r.GetPodSandboxId(), err)
} }
sandboxID := sandbox.ID 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. // Generate unique id and name for the container and reserve the name.
// Reserve the container name to avoid concurrent `CreateContainer` request creating // 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. // Generate container runtime spec.
mounts := c.generateContainerMounts(getSandboxRootDir(c.rootDir, sandboxID), config) 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 { if err != nil {
return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err) return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err)
} }

View File

@ -40,7 +40,7 @@ func (c *criContainerdService) PortForward(ctx context.Context, r *runtime.PortF
t, err := sandbox.Container.Task(ctx, nil) t, err := sandbox.Container.Task(ctx, nil)
if err != 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) status, err := t.Status(ctx)
if err != nil { if err != nil {
@ -61,7 +61,11 @@ func (c *criContainerdService) portForward(id string, port int32, stream io.Read
if err != nil { if err != nil {
return fmt.Errorf("failed to find sandbox in store: %v", err) 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") socat, err := exec.LookPath("socat")
if err != nil { if err != nil {

View File

@ -118,11 +118,6 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
glog.V(4).Infof("Sandbox container spec: %+v", spec) glog.V(4).Infof("Sandbox container spec: %+v", spec)
// Checkpoint metadata into container // 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() metaBytes, err := sandbox.Metadata.Encode()
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to convert sandbox metadata: %+v, %v", sandbox.Metadata, err) 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 { if err = task.Start(ctx); err != nil {
return nil, fmt.Errorf("failed to start sandbox container task %q: %v", return nil, fmt.Errorf("failed to start sandbox container task %q: %v",
id, err) id, err)

View File

@ -46,8 +46,6 @@ type Metadata struct {
Name string Name string
// Config is the CRI sandbox config. // Config is the CRI sandbox config.
Config *runtime.PodSandboxConfig Config *runtime.PodSandboxConfig
// Pid is the process id of the sandbox.
Pid uint32
// NetNSPath is the network namespace used by the sandbox. // NetNSPath is the network namespace used by the sandbox.
NetNSPath string NetNSPath string
} }

View File

@ -39,7 +39,6 @@ func TestSandboxStore(t *testing.T) {
Attempt: 1, Attempt: 1,
}, },
}, },
Pid: 1001,
NetNSPath: "TestNetNS-1", NetNSPath: "TestNetNS-1",
}, },
"2": { "2": {
@ -53,7 +52,6 @@ func TestSandboxStore(t *testing.T) {
Attempt: 2, Attempt: 2,
}, },
}, },
Pid: 1002,
NetNSPath: "TestNetNS-2", NetNSPath: "TestNetNS-2",
}, },
"3": { "3": {
@ -67,7 +65,6 @@ func TestSandboxStore(t *testing.T) {
Attempt: 3, Attempt: 3,
}, },
}, },
Pid: 1003,
NetNSPath: "TestNetNS-3", NetNSPath: "TestNetNS-3",
}, },
} }