Merge pull request #156 from yanxuean/metalabel

Checkpoint and restart recovery
This commit is contained in:
Lantao Liu 2017-08-23 15:36:19 -07:00 committed by GitHub
commit dd6e9fb88d
3 changed files with 36 additions and 2 deletions

View File

@ -118,7 +118,18 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
}
}()
opts = append(opts, containerd.WithSpec(spec), containerd.WithRuntime(defaultRuntime))
metaBytes, err := meta.Encode()
if err != nil {
return nil, fmt.Errorf("failed to convert sandbox metadata: %+v, %v", meta, err)
}
labels := map[string]string{
containerMetadataLabel: string(metaBytes),
}
opts = append(opts,
containerd.WithSpec(spec),
containerd.WithRuntime(defaultRuntime),
containerd.WithContainerLabels(labels))
var cntr containerd.Container
if cntr, err = c.client.NewContainer(ctx, id, opts...); err != nil {
return nil, fmt.Errorf("failed to create containerd container: %v", err)

View File

@ -95,6 +95,13 @@ const (
resolvConfPath = "/etc/resolv.conf"
)
const (
// sandboxMetadataLabel is label name that identify metadata of sandbox in CreateContainerRequest
sandboxMetadataLabel = "io.cri-containerd.sandbox.metadata"
// sandboxMetadataLabel is label name that identify metadata of container in CreateContainerRequest
containerMetadataLabel = "io.cri-containerd.container.metadata"
)
// generateID generates a random unique id.
func generateID() string {
return stringid.GenerateNonCryptoID()

View File

@ -85,10 +85,26 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
return nil, fmt.Errorf("failed to generate sandbox container spec: %v", err)
}
glog.V(4).Infof("Sandbox container spec: %+v", spec)
// TODO(random-liu): Checkpoint metadata into container labels.
// 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;
// 3.Get CreatedAt from containerd, which have been checkpointed by containerd
// https://github.com/containerd/containerd/blob/master/containers/containers.go#L14.
metaBytes, err := sandbox.Metadata.Encode()
if err != nil {
return nil, fmt.Errorf("failed to convert sandbox metadata: %+v, %v", sandbox.Metadata, err)
}
labels := map[string]string{
sandboxMetadataLabel: string(metaBytes),
}
opts := []containerd.NewContainerOpts{
containerd.WithSpec(spec),
containerd.WithContainerLabels(labels),
containerd.WithRuntime(defaultRuntime),
containerd.WithNewSnapshotView(id, image.Image)}
container, err := c.client.NewContainer(ctx, id, opts...)