@@ -49,6 +49,7 @@ import (
4949
5050 "github.com/containerd/containerd/v2/client"
5151 "github.com/containerd/containerd/v2/core/content"
52+ "github.com/containerd/containerd/v2/core/leases"
5253 "github.com/containerd/containerd/v2/core/snapshots"
5354 "github.com/containerd/containerd/v2/core/snapshots/storage"
5455 "github.com/containerd/containerd/v2/pkg/namespaces"
@@ -1372,6 +1373,27 @@ func (o *snapshotter) Compare(ctx context.Context, lower, upper []mount.Mount, o
13721373 return ocispec.Descriptor {}, errdefs .ErrNotImplemented
13731374 }
13741375
1376+ // NOTE: containerd does not forward the namespace used by nerdctl over GRPC, so we must
1377+ // set it here (hardcoded).
1378+ ctx = namespaces .WithNamespace (ctx , "k8s.io" )
1379+
1380+ containerdClient , err := client .New ("/run/containerd/containerd.sock" )
1381+ if err != nil {
1382+ logrus .Errorln ("failed to create client to containerd:" , err )
1383+ return ocispec.Descriptor {}, err
1384+ }
1385+ defer containerdClient .Close ()
1386+
1387+ // NOTE: containerd does not forward the lease used by nerdctl over GRPC, so we must
1388+ // make our own lease here.
1389+ ls := containerdClient .LeasesService ()
1390+ lease , err := ls .Create (ctx , leases .WithRandomID (), leases .WithExpiration (1 * time .Hour ))
1391+ if err != nil {
1392+ logrus .Errorln ("failed to acquire lease from containerd:" , err )
1393+ return ocispec.Descriptor {}, err
1394+ }
1395+ ctx = leases .WithLease (ctx , lease .ID )
1396+
13751397 // Create a temp directory to store the results of overlaybd-commit.
13761398 tempDir , err := os .MkdirTemp ("" , fmt .Sprintf ("%s-*" , upperInfo .Id ))
13771399 if err != nil {
@@ -1394,18 +1416,8 @@ func (o *snapshotter) Compare(ctx context.Context, lower, upper []mount.Mount, o
13941416
13951417 // Write the commit file into containerd's content store.
13961418
1397- containerdClient , err := client .New ("/run/containerd/containerd.sock" )
1398- if err != nil {
1399- logrus .Errorln ("failed to create client to containerd:" , err )
1400- return ocispec.Descriptor {}, err
1401- }
1402- defer containerdClient .Close ()
1403-
14041419 cs := containerdClient .ContentStore ()
14051420
1406- // HACK: Hardcode the namespace, for some reason it is not propagated into our DiffService.
1407- ctx = namespaces .WithNamespace (ctx , "k8s.io" )
1408-
14091421 // Grab a new content store writer using a unique ref to ensure it is new.
14101422 writer , err := cs .Writer (ctx , content .WithRef (config .Reference ), content .WithDescriptor (ocispec.Descriptor {MediaType : config .MediaType }))
14111423 if err != nil {
0 commit comments