Skip to content

Commit 0f2559e

Browse files
committed
ctr: Sync code with containerd v1.6.20 ctr
Signed-off-by: Stefan Berger <[email protected]>
1 parent c48dd78 commit 0f2559e

52 files changed

Lines changed: 7013 additions & 67 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/ctr/commands/commands.go

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ var (
3737
},
3838
}
3939

40+
// SnapshotterLabels are cli flags specifying labels which will be add to the new snapshot for container.
41+
SnapshotterLabels = cli.StringSliceFlag{
42+
Name: "snapshotter-label",
43+
Usage: "labels added to the new snapshot for this container.",
44+
}
45+
4046
// LabelFlag is a cli flag specifying labels
4147
LabelFlag = cli.StringSliceFlag{
4248
Name: "label",
@@ -78,6 +84,14 @@ var (
7884
Name: "tlskey",
7985
Usage: "path to TLS client key",
8086
},
87+
cli.BoolFlag{
88+
Name: "http-dump",
89+
Usage: "dump all HTTP request/responses when interacting with container registry",
90+
},
91+
cli.BoolFlag{
92+
Name: "http-trace",
93+
Usage: "enable HTTP tracing for registry interactions",
94+
},
8195
}
8296

8397
// ContainerFlags are cli flags specifying container options
@@ -92,19 +106,23 @@ var (
92106
},
93107
cli.StringSliceFlag{
94108
Name: "env",
95-
Usage: "specify additional container environment variables (i.e. FOO=bar)",
109+
Usage: "specify additional container environment variables (e.g. FOO=bar)",
96110
},
97111
cli.StringFlag{
98112
Name: "env-file",
99-
Usage: "specify additional container environment variables in a file(i.e. FOO=bar, one per line)",
113+
Usage: "specify additional container environment variables in a file(e.g. FOO=bar, one per line)",
100114
},
101115
cli.StringSliceFlag{
102116
Name: "label",
103-
Usage: "specify additional labels (i.e. foo=bar)",
117+
Usage: "specify additional labels (e.g. foo=bar)",
118+
},
119+
cli.StringSliceFlag{
120+
Name: "annotation",
121+
Usage: "specify additional OCI annotations (e.g. foo=bar)",
104122
},
105123
cli.StringSliceFlag{
106124
Name: "mount",
107-
Usage: "specify additional container mount (ex: type=bind,src=/tmp,dst=/host,options=rbind:ro)",
125+
Usage: "specify additional container mount (e.g. type=bind,src=/tmp,dst=/host,options=rbind:ro)",
108126
},
109127
cli.BoolFlag{
110128
Name: "net-host",
@@ -139,7 +157,7 @@ var (
139157
Name: "pid-file",
140158
Usage: "file path to write the task's pid",
141159
},
142-
cli.IntFlag{
160+
cli.IntSliceFlag{
143161
Name: "gpus",
144162
Usage: "add gpus to the container",
145163
},
@@ -153,7 +171,15 @@ var (
153171
},
154172
cli.StringSliceFlag{
155173
Name: "device",
156-
Usage: "add a device to a container",
174+
Usage: "file path to a device to add to the container; or a path to a directory tree of devices to add to the container",
175+
},
176+
cli.StringSliceFlag{
177+
Name: "cap-add",
178+
Usage: "add Linux capabilities (Set capabilities with 'CAP_' prefix)",
179+
},
180+
cli.StringSliceFlag{
181+
Name: "cap-drop",
182+
Usage: "drop Linux capabilities (Set capabilities with 'CAP_' prefix)",
157183
},
158184
cli.BoolFlag{
159185
Name: "seccomp",
@@ -171,6 +197,10 @@ var (
171197
Name: "apparmor-profile",
172198
Usage: "enable AppArmor with an existing custom profile",
173199
},
200+
cli.StringFlag{
201+
Name: "rdt-class",
202+
Usage: "name of the RDT class to associate the container with. Specifies a Class of Service (CLOS) for cache and memory bandwidth management.",
203+
},
174204
}
175205
// ImageDecryptionFlags are cli flags needed when decrypting an image
176206
ImageDecryptionFlags = []cli.Flag{
@@ -217,6 +247,19 @@ func LabelArgs(labelStrings []string) map[string]string {
217247
return labels
218248
}
219249

250+
// AnnotationArgs returns a map of annotation key,value pairs.
251+
func AnnotationArgs(annoStrings []string) (map[string]string, error) {
252+
annotations := make(map[string]string, len(annoStrings))
253+
for _, anno := range annoStrings {
254+
parts := strings.SplitN(anno, "=", 2)
255+
if len(parts) != 2 {
256+
return nil, fmt.Errorf("invalid key=value format annotation: %v", anno)
257+
}
258+
annotations[parts[0]] = parts[1]
259+
}
260+
return annotations, nil
261+
}
262+
220263
// PrintAsJSON prints input in JSON format
221264
func PrintAsJSON(x interface{}) {
222265
b, err := json.MarshalIndent(x, "", " ")

cmd/ctr/commands/containers/checkpoint.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/containerd/containerd"
2424
"github.com/containerd/containerd/cmd/ctr/commands"
2525
"github.com/containerd/containerd/errdefs"
26-
2726
"github.com/urfave/cli"
2827
)
2928

cmd/ctr/commands/containers/containers.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/containerd/imgcrypt/cmd/ctr/commands/flags"
3333
"github.com/containerd/imgcrypt/cmd/ctr/commands/run"
3434
"github.com/containerd/typeurl"
35-
3635
"github.com/urfave/cli"
3736
)
3837

@@ -150,7 +149,7 @@ var deleteCommand = cli.Command{
150149
Name: "delete",
151150
Usage: "delete one or more existing containers",
152151
ArgsUsage: "[flags] CONTAINER [CONTAINER, ...]",
153-
Aliases: []string{"del", "rm"},
152+
Aliases: []string{"del", "remove", "rm"},
154153
Flags: []cli.Flag{
155154
cli.BoolFlag{
156155
Name: "keep-snapshot",
@@ -282,7 +281,7 @@ var infoCommand = cli.Command{
282281
return nil
283282
}
284283

285-
if info.Spec != nil && info.Spec.GetValue() != nil {
284+
if info.Spec != nil && info.Spec.Value != nil {
286285
v, err := typeurl.UnmarshalAny(info.Spec)
287286
if err != nil {
288287
return err

cmd/ctr/commands/containers/restore.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/containerd/containerd/cio"
2424
"github.com/containerd/containerd/cmd/ctr/commands"
2525
"github.com/containerd/containerd/errdefs"
26-
2726
"github.com/urfave/cli"
2827
)
2928

cmd/ctr/commands/images/export.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/containerd/containerd/cmd/ctr/commands"
2626
"github.com/containerd/containerd/images/archive"
2727
"github.com/containerd/containerd/platforms"
28-
2928
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3029
"github.com/urfave/cli"
3130
)
@@ -81,7 +80,7 @@ When '--all-platforms' is given all images in a manifest list must be available.
8180
}
8281
exportOpts = append(exportOpts, archive.WithPlatform(platforms.Ordered(all...)))
8382
} else {
84-
exportOpts = append(exportOpts, archive.WithPlatform(platforms.Default()))
83+
exportOpts = append(exportOpts, archive.WithPlatform(platforms.DefaultStrict()))
8584
}
8685

8786
if context.Bool("all-platforms") {

cmd/ctr/commands/images/images.go

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/containerd/containerd/log"
3131
"github.com/containerd/containerd/pkg/progress"
3232
"github.com/containerd/containerd/platforms"
33-
3433
"github.com/urfave/cli"
3534
)
3635

@@ -202,37 +201,50 @@ var setLabelsCommand = cli.Command{
202201

203202
var checkCommand = cli.Command{
204203
Name: "check",
205-
Usage: "check that an image has all content available locally",
204+
Usage: "check existing images to ensure all content is available locally",
206205
ArgsUsage: "[flags] [<filter>, ...]",
207-
Description: "check that an image has all content available locally",
208-
Flags: commands.SnapshotterFlags,
206+
Description: "check existing images to ensure all content is available locally",
207+
Flags: append([]cli.Flag{
208+
cli.BoolFlag{
209+
Name: "quiet, q",
210+
Usage: "print only the ready image refs (fully downloaded and unpacked)",
211+
},
212+
}, commands.SnapshotterFlags...),
209213
Action: func(context *cli.Context) error {
210214
var (
211215
exitErr error
216+
quiet = context.Bool("quiet")
212217
)
213218
client, ctx, cancel, err := commands.NewClient(context)
214219
if err != nil {
215220
return err
216221
}
217222
defer cancel()
218-
var (
219-
contentStore = client.ContentStore()
220-
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
221-
)
222-
fmt.Fprintln(tw, "REF\tTYPE\tDIGEST\tSTATUS\tSIZE\tUNPACKED\t")
223+
224+
var contentStore = client.ContentStore()
223225

224226
args := []string(context.Args())
225227
imageList, err := client.ListImages(ctx, args...)
226228
if err != nil {
227229
return fmt.Errorf("failed listing images: %w", err)
228230
}
231+
if len(imageList) == 0 {
232+
log.G(ctx).Debugf("no images found")
233+
return exitErr
234+
}
235+
236+
var tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
237+
if !quiet {
238+
fmt.Fprintln(tw, "REF\tTYPE\tDIGEST\tSTATUS\tSIZE\tUNPACKED\t")
239+
}
229240

230241
for _, image := range imageList {
231242
var (
232243
status string = "complete"
233244
size string
234245
requiredSize int64
235246
presentSize int64
247+
complete bool = true
236248
)
237249

238250
available, required, present, missing, err := images.Check(ctx, contentStore, image.Target(), platforms.Default())
@@ -242,6 +254,7 @@ var checkCommand = cli.Command{
242254
}
243255
log.G(ctx).WithError(err).Errorf("unable to check %v", image.Name())
244256
status = "error"
257+
complete = false
245258
}
246259

247260
if status != "error" {
@@ -255,6 +268,7 @@ var checkCommand = cli.Command{
255268

256269
if len(missing) > 0 {
257270
status = "incomplete"
271+
complete = false
258272
}
259273

260274
if available {
@@ -263,6 +277,7 @@ var checkCommand = cli.Command{
263277
} else {
264278
status = fmt.Sprintf("unavailable (%v/?)", len(present))
265279
size = fmt.Sprintf("%v/?", progress.Bytes(presentSize))
280+
complete = false
266281
}
267282
} else {
268283
size = "-"
@@ -276,23 +291,30 @@ var checkCommand = cli.Command{
276291
log.G(ctx).WithError(err).Errorf("unable to check unpack for %v", image.Name())
277292
}
278293

279-
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\t%v\t%t\n",
280-
image.Name(),
281-
image.Target().MediaType,
282-
image.Target().Digest,
283-
status,
284-
size,
285-
unpacked)
294+
if !quiet {
295+
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\t%v\t%t\n",
296+
image.Name(),
297+
image.Target().MediaType,
298+
image.Target().Digest,
299+
status,
300+
size,
301+
unpacked)
302+
} else {
303+
if complete {
304+
fmt.Println(image.Name())
305+
}
306+
}
307+
}
308+
if !quiet {
309+
tw.Flush()
286310
}
287-
tw.Flush()
288-
289311
return exitErr
290312
},
291313
}
292314

293315
var removeCommand = cli.Command{
294-
Name: "remove",
295-
Aliases: []string{"rm"},
316+
Name: "delete",
317+
Aliases: []string{"del", "remove", "rm"},
296318
Usage: "remove one or more images by reference",
297319
ArgsUsage: "[flags] <ref> [<ref>, ...]",
298320
Description: "remove one or more images by reference",

cmd/ctr/commands/images/import.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ decrypting the image later on.
9797

9898
Action: func(context *cli.Context) error {
9999
var (
100-
in = context.Args().First()
101-
opts []containerd.ImportOpt
102-
platformMacher platforms.MatchComparer
100+
in = context.Args().First()
101+
opts []containerd.ImportOpt
102+
platformMatcher platforms.MatchComparer
103103
)
104104

105105
prefix := context.String("base-name")
@@ -134,8 +134,8 @@ decrypting the image later on.
134134
if err != nil {
135135
return err
136136
}
137-
platformMacher = platforms.Only(platSpec)
138-
opts = append(opts, containerd.WithImportPlatform(platformMacher))
137+
platformMatcher = platforms.OnlyStrict(platSpec)
138+
opts = append(opts, containerd.WithImportPlatform(platformMatcher))
139139
}
140140

141141
opts = append(opts, containerd.WithAllPlatforms(context.Bool("all-platforms")))
@@ -177,10 +177,10 @@ decrypting the image later on.
177177
log.G(ctx).Debugf("unpacking %d images", len(imgs))
178178

179179
for _, img := range imgs {
180-
if platformMacher == nil { // if platform not specified use default.
181-
platformMacher = platforms.Default()
180+
if platformMatcher == nil { // if platform not specified use default.
181+
platformMatcher = platforms.Default()
182182
}
183-
image := containerd.NewImageWithPlatform(client, img, platformMacher)
183+
image := containerd.NewImageWithPlatform(client, img, platformMatcher)
184184

185185
// TODO: Show unpack status
186186
fmt.Printf("unpacking %s (%s)...", img.Name, img.Target.Digest)

cmd/ctr/commands/images/mount.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/containerd/containerd/leases"
2727
"github.com/containerd/containerd/mount"
2828
"github.com/containerd/containerd/platforms"
29-
3029
"github.com/opencontainers/image-spec/identity"
3130
"github.com/urfave/cli"
3231
)

cmd/ctr/commands/images/push.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import (
3535
"github.com/containerd/containerd/platforms"
3636
"github.com/containerd/containerd/remotes"
3737
"github.com/containerd/containerd/remotes/docker"
38-
39-
"github.com/opencontainers/go-digest"
38+
digest "github.com/opencontainers/go-digest"
4039
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
4140
"github.com/urfave/cli"
4241
"golang.org/x/sync/errgroup"
@@ -69,6 +68,9 @@ var pushCommand = cli.Command{
6968
}, cli.IntFlag{
7069
Name: "max-concurrent-uploaded-layers",
7170
Usage: "Set the max concurrent uploaded layers for each push",
71+
}, cli.BoolFlag{
72+
Name: "allow-non-distributable-blobs",
73+
Usage: "Allow pushing blobs that are marked as non-distributable",
7274
}),
7375
Action: func(context *cli.Context) error {
7476
var (
@@ -145,13 +147,21 @@ var pushCommand = cli.Command{
145147
log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing")
146148

147149
jobHandler := images.HandlerFunc(func(ctx gocontext.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
150+
if !context.Bool("allow-non-distributable-blobs") && images.IsNonDistributable(desc.MediaType) {
151+
return nil, nil
152+
}
148153
ongoing.add(remotes.MakeRefKey(ctx, desc))
149154
return nil, nil
150155
})
151156

157+
handler := jobHandler
158+
if !context.Bool("allow-non-distributable-blobs") {
159+
handler = remotes.SkipNonDistributableBlobs(handler)
160+
}
161+
152162
ropts := []containerd.RemoteOpt{
153163
containerd.WithResolver(resolver),
154-
containerd.WithImageHandler(jobHandler),
164+
containerd.WithImageHandler(handler),
155165
}
156166

157167
if context.IsSet("max-concurrent-uploaded-layers") {

0 commit comments

Comments
 (0)