mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 16:29:18 +00:00
Add FromDiscoverer function to generate container edits
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
029a04c37d
commit
0b6cd7e90e
@ -34,6 +34,20 @@ type edits struct {
|
|||||||
// NewSpecEdits creates a SpecModifier that defines the required OCI spec edits (as CDI ContainerEdits) from the specified
|
// NewSpecEdits creates a SpecModifier that defines the required OCI spec edits (as CDI ContainerEdits) from the specified
|
||||||
// discoverer.
|
// discoverer.
|
||||||
func NewSpecEdits(logger *logrus.Logger, d discover.Discover) (oci.SpecModifier, error) {
|
func NewSpecEdits(logger *logrus.Logger, d discover.Discover) (oci.SpecModifier, error) {
|
||||||
|
c, err := FromDiscoverer(d)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error constructing container edits: %v", err)
|
||||||
|
}
|
||||||
|
e := edits{
|
||||||
|
ContainerEdits: *c,
|
||||||
|
logger: logger,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &e, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromDiscoverer creates CDI container edits for the specified discoverer.
|
||||||
|
func FromDiscoverer(d discover.Discover) (*cdi.ContainerEdits, error) {
|
||||||
devices, err := d.Devices()
|
devices, err := d.Devices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to discover devices: %v", err)
|
return nil, fmt.Errorf("failed to discover devices: %v", err)
|
||||||
@ -66,12 +80,7 @@ func NewSpecEdits(logger *logrus.Logger, d discover.Discover) (oci.SpecModifier,
|
|||||||
c.Append(hook(h).toEdits())
|
c.Append(hook(h).toEdits())
|
||||||
}
|
}
|
||||||
|
|
||||||
e := edits{
|
return &c, nil
|
||||||
ContainerEdits: c,
|
|
||||||
logger: logger,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &e, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify applies the defined edits to the incoming OCI spec
|
// Modify applies the defined edits to the incoming OCI spec
|
||||||
|
Loading…
Reference in New Issue
Block a user