Merge pull request #393 from abhi/labels

Adding kube pod and container labels to containerd
This commit is contained in:
Lantao Liu 2017-11-07 23:39:20 -08:00 committed by GitHub
commit 2433ae7539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -223,6 +223,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
if seccompSpecOpts != nil { if seccompSpecOpts != nil {
specOpts = append(specOpts, seccompSpecOpts) specOpts = append(specOpts, seccompSpecOpts)
} }
containerLabels := buildLabels(config.Labels, containerKindContainer)
opts = append(opts, opts = append(opts,
containerd.WithSpec(spec, specOpts...), containerd.WithSpec(spec, specOpts...),
@ -232,7 +233,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
Runtime: c.config.ContainerdConfig.RuntimeEngine, Runtime: c.config.ContainerdConfig.RuntimeEngine,
RuntimeRoot: c.config.ContainerdConfig.RuntimeRoot, RuntimeRoot: c.config.ContainerdConfig.RuntimeRoot,
SystemdCgroup: c.config.SystemdCgroup}), // TODO (mikebrow): add CriuPath when we add support for pause SystemdCgroup: c.config.SystemdCgroup}), // TODO (mikebrow): add CriuPath when we add support for pause
containerd.WithContainerLabels(map[string]string{containerKindLabel: containerKindContainer}), containerd.WithContainerLabels(containerLabels),
containerd.WithContainerExtension(containerMetadataExtension, &meta)) containerd.WithContainerExtension(containerMetadataExtension, &meta))
var cntr containerd.Container var cntr containerd.Container
if cntr, err = c.client.NewContainer(ctx, id, opts...); err != nil { if cntr, err = c.client.NewContainer(ctx, id, opts...); err != nil {

View File

@ -381,3 +381,13 @@ func isInCRIMounts(dst string, mounts []*runtime.Mount) bool {
func filterLabel(k, v string) string { func filterLabel(k, v string) string {
return fmt.Sprintf("labels.%q==%q", k, v) return fmt.Sprintf("labels.%q==%q", k, v)
} }
// buildLabel builds the labels from config to be passed to containerd
func buildLabels(configLabels map[string]string, containerType string) map[string]string {
labels := make(map[string]string)
for k, v := range configLabels {
labels[k] = v
}
labels[containerKindLabel] = containerType
return labels
}

View File

@ -143,12 +143,14 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
specOpts = append(specOpts, seccompSpecOpts) specOpts = append(specOpts, seccompSpecOpts)
} }
sandboxLabels := buildLabels(config.Labels, containerKindSandbox)
opts := []containerd.NewContainerOpts{ opts := []containerd.NewContainerOpts{
containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter), containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter),
customopts.WithImageUnpack(image.Image), customopts.WithImageUnpack(image.Image),
containerd.WithNewSnapshot(id, image.Image), containerd.WithNewSnapshot(id, image.Image),
containerd.WithSpec(spec, specOpts...), containerd.WithSpec(spec, specOpts...),
containerd.WithContainerLabels(map[string]string{containerKindLabel: containerKindSandbox}), containerd.WithContainerLabels(sandboxLabels),
containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata), containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata),
containerd.WithRuntime( containerd.WithRuntime(
c.config.ContainerdConfig.Runtime, c.config.ContainerdConfig.Runtime,