@@ -28,7 +28,6 @@ import (
2828 "github.com/containerd/containerd/cmd/ctr/commands"
2929 "github.com/containerd/containerd/cmd/ctr/commands/run"
3030 "github.com/containerd/containerd/containers"
31- "github.com/containerd/containerd/errdefs"
3231 "github.com/containerd/containerd/log"
3332 "github.com/containerd/typeurl"
3433 "github.com/pkg/errors"
@@ -125,7 +124,7 @@ var listCommand = cli.Command{
125124 w := tabwriter .NewWriter (os .Stdout , 4 , 8 , 4 , ' ' , 0 )
126125 fmt .Fprintln (w , "CONTAINER\t IMAGE\t RUNTIME\t " )
127126 for _ , c := range containers {
128- info , err := c .Info (ctx )
127+ info , err := c .Info (ctx , containerd . WithoutRefreshedMetadata )
129128 if err != nil {
130129 return err
131130 }
@@ -262,7 +261,7 @@ var infoCommand = cli.Command{
262261 if err != nil {
263262 return err
264263 }
265- info , err := container .Info (ctx )
264+ info , err := container .Info (ctx , containerd . WithoutRefreshedMetadata )
266265 if err != nil {
267266 return err
268267 }
@@ -285,148 +284,3 @@ var infoCommand = cli.Command{
285284 return nil
286285 },
287286}
288-
289- var checkpointCommand = cli.Command {
290- Name : "checkpoint" ,
291- Usage : "checkpoint a container" ,
292- ArgsUsage : "CONTAINER REF" ,
293- Flags : []cli.Flag {
294- cli.BoolFlag {
295- Name : "rw" ,
296- Usage : "include the rw layer in the checkpoint" ,
297- },
298- cli.BoolFlag {
299- Name : "image" ,
300- Usage : "include the image in the checkpoint" ,
301- },
302- cli.BoolFlag {
303- Name : "task" ,
304- Usage : "checkpoint container task" ,
305- },
306- },
307- Action : func (context * cli.Context ) error {
308- id := context .Args ().First ()
309- if id == "" {
310- return errors .New ("container id must be provided" )
311- }
312- ref := context .Args ().Get (1 )
313- if ref == "" {
314- return errors .New ("ref must be provided" )
315- }
316- client , ctx , cancel , err := commands .NewClient (context )
317- if err != nil {
318- return err
319- }
320- defer cancel ()
321- opts := []containerd.CheckpointOpts {
322- containerd .WithCheckpointRuntime ,
323- }
324-
325- if context .Bool ("image" ) {
326- opts = append (opts , containerd .WithCheckpointImage )
327- }
328- if context .Bool ("rw" ) {
329- opts = append (opts , containerd .WithCheckpointRW )
330- }
331- if context .Bool ("task" ) {
332- opts = append (opts , containerd .WithCheckpointTask )
333- }
334- container , err := client .LoadContainer (ctx , id )
335- if err != nil {
336- return err
337- }
338- task , err := container .Task (ctx , nil )
339- if err != nil {
340- if ! errdefs .IsNotFound (err ) {
341- return err
342- }
343- }
344- // pause if running
345- if task != nil {
346- if err := task .Pause (ctx ); err != nil {
347- return err
348- }
349- defer func () {
350- if err := task .Resume (ctx ); err != nil {
351- fmt .Println (errors .Wrap (err , "error resuming task" ))
352- }
353- }()
354- }
355-
356- if _ , err := container .Checkpoint (ctx , ref , opts ... ); err != nil {
357- return err
358- }
359-
360- return nil
361- },
362- }
363-
364- var restoreCommand = cli.Command {
365- Name : "restore" ,
366- Usage : "restore a container from checkpoint" ,
367- ArgsUsage : "CONTAINER REF" ,
368- Flags : []cli.Flag {
369- cli.BoolFlag {
370- Name : "rw" ,
371- Usage : "restore the rw layer from the checkpoint" ,
372- },
373- cli.BoolFlag {
374- Name : "live" ,
375- Usage : "restore the runtime and memory data from the checkpoint" ,
376- },
377- },
378- Action : func (context * cli.Context ) error {
379- id := context .Args ().First ()
380- if id == "" {
381- return errors .New ("container id must be provided" )
382- }
383- ref := context .Args ().Get (1 )
384- if ref == "" {
385- return errors .New ("ref must be provided" )
386- }
387- client , ctx , cancel , err := commands .NewClient (context )
388- if err != nil {
389- return err
390- }
391- defer cancel ()
392-
393- checkpoint , err := client .GetImage (ctx , ref )
394- if err != nil {
395- if ! errdefs .IsNotFound (err ) {
396- return err
397- }
398- // TODO (ehazlett): consider other options (always/never fetch)
399- ck , err := client .Fetch (ctx , ref )
400- if err != nil {
401- return err
402- }
403- checkpoint = containerd .NewImage (client , ck )
404- }
405-
406- opts := []containerd.RestoreOpts {
407- containerd .WithRestoreImage ,
408- containerd .WithRestoreSpec ,
409- containerd .WithRestoreRuntime ,
410- }
411- if context .Bool ("rw" ) {
412- opts = append (opts , containerd .WithRestoreRW )
413- }
414-
415- ctr , err := client .Restore (ctx , id , checkpoint , opts ... )
416- if err != nil {
417- return err
418- }
419-
420- topts := []containerd.NewTaskOpts {}
421- if context .Bool ("live" ) {
422- topts = append (topts , containerd .WithTaskCheckpoint (checkpoint ))
423- }
424-
425- task , err := ctr .NewTask (ctx , cio .NewCreator (cio .WithStdio ), topts ... )
426- if err != nil {
427- return err
428- }
429-
430- return task .Start (ctx )
431- },
432- }
0 commit comments