Enable image config labels in ctr and CRI container creation
Signed-off-by: Phil Estes <estesp@amazon.com>
This commit is contained in:
@@ -249,3 +249,16 @@ func fullID(ctx context.Context, c containerd.Container) string {
|
||||
}
|
||||
return fmt.Sprintf("%s-%s", ns, id)
|
||||
}
|
||||
|
||||
// buildLabel builds the labels from command line labels and the image labels
|
||||
func buildLabels(cmdLabels, imageLabels map[string]string) map[string]string {
|
||||
labels := make(map[string]string)
|
||||
for k, v := range imageLabels {
|
||||
labels[k] = v
|
||||
}
|
||||
// labels from the command line will override image and the initial image config labels
|
||||
for k, v := range cmdLabels {
|
||||
labels[k] = v
|
||||
}
|
||||
return labels
|
||||
}
|
||||
|
@@ -103,8 +103,8 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
spec containerd.NewContainerOpts
|
||||
)
|
||||
|
||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
|
||||
if config {
|
||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("labels"))))
|
||||
opts = append(opts, oci.WithSpecFromFile(context.String("config")))
|
||||
} else {
|
||||
var (
|
||||
@@ -125,6 +125,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
return nil, err
|
||||
}
|
||||
opts = append(opts, oci.WithRootFSPath(rootfs))
|
||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("labels"))))
|
||||
} else {
|
||||
snapshotter := context.String("snapshotter")
|
||||
var image containerd.Image
|
||||
@@ -151,9 +152,12 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
labels := buildLabels(commands.LabelArgs(context.StringSlice("label")), image.Labels())
|
||||
opts = append(opts, oci.WithImageConfig(image))
|
||||
cOpts = append(cOpts,
|
||||
containerd.WithImage(image),
|
||||
containerd.WithImageConfigLabels(image),
|
||||
containerd.WithAdditionalContainerLabels(labels),
|
||||
containerd.WithSnapshotter(snapshotter))
|
||||
if uidmap, gidmap := context.String("uidmap"), context.String("gidmap"); uidmap != "" && gidmap != "" {
|
||||
uidMap, err := parseIDMapping(uidmap)
|
||||
|
@@ -51,6 +51,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
if config {
|
||||
id = context.Args().First()
|
||||
opts = append(opts, oci.WithSpecFromFile(context.String("config")))
|
||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
|
||||
} else {
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
@@ -88,9 +89,13 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
}
|
||||
}
|
||||
opts = append(opts, oci.WithImageConfig(image))
|
||||
cOpts = append(cOpts, containerd.WithImage(image))
|
||||
cOpts = append(cOpts, containerd.WithSnapshotter(snapshotter))
|
||||
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image))
|
||||
labels := buildLabels(commands.LabelArgs(context.StringSlice("label")), image.Labels())
|
||||
cOpts = append(cOpts,
|
||||
containerd.WithImage(image),
|
||||
containerd.WithImageConfigLabels(image),
|
||||
containerd.WithSnapshotter(snapshotter),
|
||||
containerd.WithNewSnapshot(id, image),
|
||||
containerd.WithAdditionalContainerLabels(labels))
|
||||
|
||||
if len(args) > 0 {
|
||||
opts = append(opts, oci.WithProcessArgs(args...))
|
||||
@@ -124,7 +129,6 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
}
|
||||
}
|
||||
|
||||
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))
|
||||
runtime := context.String("runtime")
|
||||
var runtimeOpts interface{}
|
||||
if runtime == "io.containerd.runhcs.v1" {
|
||||
|
Reference in New Issue
Block a user