Commit dfd4e42e authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Wrap context with lease before importing images

parent 2069cdf4
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"github.com/containerd/containerd/leases" "github.com/containerd/containerd/leases"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/reference/docker" "github.com/containerd/containerd/reference/docker"
"github.com/containerd/cri/pkg/constants"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
"github.com/natefinch/lumberjack" "github.com/natefinch/lumberjack"
"github.com/pierrec/lz4" "github.com/pierrec/lz4"
...@@ -155,9 +156,9 @@ func preloadImages(ctx context.Context, cfg *config.Node) error { ...@@ -155,9 +156,9 @@ func preloadImages(ctx context.Context, cfg *config.Node) error {
} }
defer criConn.Close() defer criConn.Close()
// Ensure that nothing else can modify the image store while we're importing, // Ensure that our images are imported into the correct namespace
// and that our images are imported into the k8s.io namespace ctx = namespaces.WithNamespace(ctx, constants.K8sContainerdNamespace)
ctx = namespaces.WithNamespace(ctx, "k8s.io")
// At startup all leases from k3s are cleared // At startup all leases from k3s are cleared
ls := client.LeasesService() ls := client.LeasesService()
existingLeases, err := ls.List(ctx) existingLeases, err := ls.List(ctx)
...@@ -173,11 +174,14 @@ func preloadImages(ctx context.Context, cfg *config.Node) error { ...@@ -173,11 +174,14 @@ func preloadImages(ctx context.Context, cfg *config.Node) error {
} }
// Any images found on import are given a lease that never expires // Any images found on import are given a lease that never expires
_, err = ls.Create(ctx, leases.WithID(version.Program)) lease, err := ls.Create(ctx, leases.WithID(version.Program))
if err != nil { if err != nil {
return err return err
} }
// Ensure that our images are locked by the lease
ctx = leases.WithLease(ctx, lease.ID)
for _, fileInfo := range fileInfos { for _, fileInfo := range fileInfos {
if fileInfo.IsDir() { if fileInfo.IsDir() {
continue continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment