add label flags to ctr import, add integration tests

Signed-off-by: roman-kiselenko <roman.kiselenko.dev@gmail.com>
This commit is contained in:
roman-kiselenko
2023-12-05 12:46:57 +03:00
committed by roman-kiselenko
parent 0bb7fd36ce
commit a3c62e698d
3 changed files with 51 additions and 2 deletions

View File

@@ -98,7 +98,7 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
Name: "discard-unpacked-layers",
Usage: "Allow the garbage collector to clean layers up from the content store after unpacking, cannot be used with --no-unpack, false by default",
},
}, commands.SnapshotterFlags...),
}, append(commands.SnapshotterFlags, commands.LabelFlag)...),
Action: func(context *cli.Context) error {
var (
@@ -123,6 +123,11 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
overwrite = true
}
labels := context.StringSlice("label")
if len(labels) > 0 {
opts = append(opts, image.WithImageLabels(commands.LabelArgs(labels)))
}
if context.Bool("digests") {
opts = append(opts, image.WithDigestRef(prefix, overwrite, !context.Bool("skip-digest-for-named")))
} else {
@@ -237,6 +242,11 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
opts = append(opts, containerd.WithDiscardUnpackedLayers())
}
labels := context.StringSlice("label")
if len(labels) > 0 {
opts = append(opts, containerd.WithImageLabels(commands.LabelArgs(labels)))
}
ctx, done, err := client.WithLease(ctx)
if err != nil {
return err