From 0b6cd7e90e09ce0e2cbdf17fb873f8f827e370f5 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 23 Nov 2022 16:25:11 +0100 Subject: [PATCH] Add FromDiscoverer function to generate container edits Signed-off-by: Evan Lezar --- internal/edits/edits.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/edits/edits.go b/internal/edits/edits.go index 14e79b7b..3d7560d5 100644 --- a/internal/edits/edits.go +++ b/internal/edits/edits.go @@ -34,6 +34,20 @@ type edits struct { // NewSpecEdits creates a SpecModifier that defines the required OCI spec edits (as CDI ContainerEdits) from the specified // discoverer. 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() if err != nil { 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()) } - e := edits{ - ContainerEdits: c, - logger: logger, - } - - return &e, nil + return &c, nil } // Modify applies the defined edits to the incoming OCI spec