diff --git a/cmd/ctr/commands/content/fetch.go b/cmd/ctr/commands/content/fetch.go index 96933eb9a..01abb4cad 100644 --- a/cmd/ctr/commands/content/fetch.go +++ b/cmd/ctr/commands/content/fetch.go @@ -61,19 +61,19 @@ Most of this is experimental and there are few leaps to make this work.`, var ( ref = clicontext.Args().First() ) - _, err := Fetch(ref, clicontext) + client, ctx, cancel, err := commands.NewClient(clicontext) + if err != nil { + return err + } + defer cancel() + + _, err = Fetch(ctx, client, ref, clicontext) return err }, } // Fetch loads all resources into the content store and returns the image -func Fetch(ref string, cliContext *cli.Context) (containerd.Image, error) { - client, ctx, cancel, err := commands.NewClient(cliContext) - if err != nil { - return nil, err - } - defer cancel() - +func Fetch(ctx context.Context, client *containerd.Client, ref string, cliContext *cli.Context) (containerd.Image, error) { resolver, err := commands.GetResolver(ctx, cliContext) if err != nil { return nil, err diff --git a/cmd/ctr/commands/images/pull.go b/cmd/ctr/commands/images/pull.go index 4ea72b6bf..10e4f1d52 100644 --- a/cmd/ctr/commands/images/pull.go +++ b/cmd/ctr/commands/images/pull.go @@ -57,10 +57,20 @@ command. As part of this process, we do the following: if ref == "" { return fmt.Errorf("please provide an image reference to pull") } - ctx, cancel := commands.AppContext(context) + + client, ctx, cancel, err := commands.NewClient(context) + if err != nil { + return err + } defer cancel() - img, err := content.Fetch(ref, context) + ctx, done, err := client.WithLease(ctx) + if err != nil { + return err + } + defer done(ctx) + + img, err := content.Fetch(ctx, client, ref, context) if err != nil { return err }