summary refs log tree commit diff
path: root/cmd
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2021-04-15 19:40:00 -0700
committerFranck Cuny <franck@fcuny.net>2021-04-15 19:40:00 -0700
commit67f8b21f0ad31b675e6a848bfce2e903c388c980 (patch)
tree499ab26abc1d17e27413ca4ec62dddbb196babd5 /cmd
parentpull a container into a namespace (diff)
downloadcontainerd-to-vm-67f8b21f0ad31b675e6a848bfce2e903c388c980.tar.gz
add a lease to the Go context
This will ensure that our container will not be deleted while we work on
it. In addition, a default expiry of 24 hours will be set on it once the
lease is released (once the program is completed).

See [1] for more details.

[1] https://github.com/containerd/containerd/blob/261c107ffc4ff681bc73988f64e3f60c32233b37/docs/garbage-collection.md

Signed-off-by: Franck Cuny <franck@fcuny.net>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/c2vm/main.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/cmd/c2vm/main.go b/cmd/c2vm/main.go
index 4d0968b..5e9fbb0 100644
--- a/cmd/c2vm/main.go
+++ b/cmd/c2vm/main.go
@@ -42,6 +42,12 @@ func main() {
 	defer client.Close()
 
 	ctx := namespaces.WithNamespace(context.Background(), defaultNamespace)
+	ctx, done, err := client.WithLease(ctx)
+	if err != nil {
+		log.Fatalf("failed to get a lease: %v", err)
+	}
+	defer done(ctx)
+
 	image, err := client.Pull(ctx, *containerName, containerd.WithPlatformMatcher(platform))
 	if err != nil {
 		log.Fatalf("failed to pull the container %s: %v\n", *containerName, err)