mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Return raw spec from Spec.Load
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
a672713dba
commit
5d7b3a4a96
@ -46,7 +46,8 @@ const (
|
||||
// NewExperimentalModifier creates a modifier that applies the experimental
|
||||
// modications to an OCI spec if required by the runtime wrapper.
|
||||
func NewExperimentalModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) {
|
||||
if err := ociSpec.Load(); err != nil {
|
||||
_, err := ociSpec.Load()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ type SpecModifier interface {
|
||||
//go:generate moq -stub -out spec_mock.go . Spec
|
||||
// Spec defines the operations to be performed on an OCI specification
|
||||
type Spec interface {
|
||||
Load() error
|
||||
Load() (*specs.Spec, error)
|
||||
Flush() error
|
||||
Modify(SpecModifier) error
|
||||
LookupEnv(string) (string, bool)
|
||||
|
@ -45,19 +45,19 @@ func NewFileSpec(filepath string) Spec {
|
||||
|
||||
// Load reads the contents of an OCI spec from file to be referenced internally.
|
||||
// The file is opened "read-only"
|
||||
func (s *fileSpec) Load() error {
|
||||
func (s *fileSpec) Load() (*specs.Spec, error) {
|
||||
specFile, err := os.Open(s.path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening OCI specification file: %v", err)
|
||||
return nil, fmt.Errorf("error opening OCI specification file: %v", err)
|
||||
}
|
||||
defer specFile.Close()
|
||||
|
||||
spec, err := LoadFrom(specFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading OCI specification from file: %v", err)
|
||||
return nil, fmt.Errorf("error loading OCI specification from file: %v", err)
|
||||
}
|
||||
s.Spec = spec
|
||||
return nil
|
||||
return s.Spec, nil
|
||||
}
|
||||
|
||||
// LoadFrom reads the contents of the OCI spec from the specified io.Reader.
|
||||
|
@ -37,8 +37,8 @@ func NewMemorySpec(spec *specs.Spec) Spec {
|
||||
}
|
||||
|
||||
// Load is a no-op for the memorySpec spec
|
||||
func (s *memorySpec) Load() error {
|
||||
return nil
|
||||
func (s *memorySpec) Load() (*specs.Spec, error) {
|
||||
return s.Spec, nil
|
||||
}
|
||||
|
||||
// Flush is a no-op for the memorySpec spec
|
||||
|
@ -4,6 +4,7 @@
|
||||
package oci
|
||||
|
||||
import (
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@ -20,7 +21,7 @@ var _ Spec = &SpecMock{}
|
||||
// FlushFunc: func() error {
|
||||
// panic("mock out the Flush method")
|
||||
// },
|
||||
// LoadFunc: func() error {
|
||||
// LoadFunc: func() (*specs.Spec, error) {
|
||||
// panic("mock out the Load method")
|
||||
// },
|
||||
// LookupEnvFunc: func(s string) (string, bool) {
|
||||
@ -40,7 +41,7 @@ type SpecMock struct {
|
||||
FlushFunc func() error
|
||||
|
||||
// LoadFunc mocks the Load method.
|
||||
LoadFunc func() error
|
||||
LoadFunc func() (*specs.Spec, error)
|
||||
|
||||
// LookupEnvFunc mocks the LookupEnv method.
|
||||
LookupEnvFunc func(s string) (string, bool)
|
||||
@ -103,7 +104,7 @@ func (mock *SpecMock) FlushCalls() []struct {
|
||||
}
|
||||
|
||||
// Load calls LoadFunc.
|
||||
func (mock *SpecMock) Load() error {
|
||||
func (mock *SpecMock) Load() (*specs.Spec, error) {
|
||||
callInfo := struct {
|
||||
}{}
|
||||
mock.lockLoad.Lock()
|
||||
@ -111,9 +112,10 @@ func (mock *SpecMock) Load() error {
|
||||
mock.lockLoad.Unlock()
|
||||
if mock.LoadFunc == nil {
|
||||
var (
|
||||
errOut error
|
||||
specOut *specs.Spec
|
||||
errOut error
|
||||
)
|
||||
return errOut
|
||||
return specOut, errOut
|
||||
}
|
||||
return mock.LoadFunc()
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func (r *modifyingRuntimeWrapper) Exec(args []string) error {
|
||||
|
||||
// modify loads, modifies, and flushes the OCI specification using the defined Modifier
|
||||
func (r *modifyingRuntimeWrapper) modify() error {
|
||||
err := r.ociSpec.Load()
|
||||
_, err := r.ociSpec.Load()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading OCI specification for modification: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user