Skip to content

Commit

Permalink
cdi: use oci.WithCDIDevices since containerd v2
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Feb 3, 2025
1 parent 3f67452 commit 31ec2bc
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions executor/oci/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/containerd/containerd/v2/pkg/oci"
cdseccomp "github.com/containerd/containerd/v2/pkg/seccomp"
"github.com/containerd/continuity/fs"
"github.com/containerd/log"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/profiles/seccomp"
"github.com/moby/buildkit/snapshot"
Expand Down Expand Up @@ -191,31 +190,9 @@ func generateCDIOpts(ctx context.Context, devices []*pb.CDIDevice) ([]oci.SpecOp
}
}

// withCDIDevices injects the requested CDI devices into the OCI specification.
// FIXME: Use oci.WithCDIDevices once we switch to containerd 2.0.
withCDIDevices := func(devices ...string) oci.SpecOpts {
return func(ctx context.Context, _ oci.Client, c *containers.Container, s *specs.Spec) error {
if len(devices) == 0 {
return nil
}
if err := cdi.Refresh(); err != nil {
log.G(ctx).Warnf("CDI registry refresh failed: %v", err)
}
bklog.G(ctx).Debugf("Injecting CDI devices %v", devices)
if _, err := cdi.InjectDevices(s, devices...); err != nil {
return errors.Wrapf(err, "CDI device injection failed")
}
// One crucial thing to keep in mind is that CDI device injection
// might add OCI Spec environment variables, hooks, and mounts as
// well. Therefore, it is important that none of the corresponding
// OCI Spec fields are reset up in the call stack once we return.
return nil
}
}

return []oci.SpecOpts{
withStaticCDIRegistry(),
withCDIDevices(dd...),
oci.WithCDIDevices(dd...),
}, nil
}

Expand Down

0 comments on commit 31ec2bc

Please sign in to comment.