mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +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
|
// NewExperimentalModifier creates a modifier that applies the experimental
|
||||||
// modications to an OCI spec if required by the runtime wrapper.
|
// 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) {
|
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)
|
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
|
//go:generate moq -stub -out spec_mock.go . Spec
|
||||||
// Spec defines the operations to be performed on an OCI specification
|
// Spec defines the operations to be performed on an OCI specification
|
||||||
type Spec interface {
|
type Spec interface {
|
||||||
Load() error
|
Load() (*specs.Spec, error)
|
||||||
Flush() error
|
Flush() error
|
||||||
Modify(SpecModifier) error
|
Modify(SpecModifier) error
|
||||||
LookupEnv(string) (string, bool)
|
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.
|
// Load reads the contents of an OCI spec from file to be referenced internally.
|
||||||
// The file is opened "read-only"
|
// The file is opened "read-only"
|
||||||
func (s *fileSpec) Load() error {
|
func (s *fileSpec) Load() (*specs.Spec, error) {
|
||||||
specFile, err := os.Open(s.path)
|
specFile, err := os.Open(s.path)
|
||||||
if err != nil {
|
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()
|
defer specFile.Close()
|
||||||
|
|
||||||
spec, err := LoadFrom(specFile)
|
spec, err := LoadFrom(specFile)
|
||||||
if err != nil {
|
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
|
s.Spec = spec
|
||||||
return nil
|
return s.Spec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFrom reads the contents of the OCI spec from the specified io.Reader.
|
// 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
|
// Load is a no-op for the memorySpec spec
|
||||||
func (s *memorySpec) Load() error {
|
func (s *memorySpec) Load() (*specs.Spec, error) {
|
||||||
return nil
|
return s.Spec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush is a no-op for the memorySpec spec
|
// Flush is a no-op for the memorySpec spec
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package oci
|
package oci
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ var _ Spec = &SpecMock{}
|
|||||||
// FlushFunc: func() error {
|
// FlushFunc: func() error {
|
||||||
// panic("mock out the Flush method")
|
// panic("mock out the Flush method")
|
||||||
// },
|
// },
|
||||||
// LoadFunc: func() error {
|
// LoadFunc: func() (*specs.Spec, error) {
|
||||||
// panic("mock out the Load method")
|
// panic("mock out the Load method")
|
||||||
// },
|
// },
|
||||||
// LookupEnvFunc: func(s string) (string, bool) {
|
// LookupEnvFunc: func(s string) (string, bool) {
|
||||||
@ -40,7 +41,7 @@ type SpecMock struct {
|
|||||||
FlushFunc func() error
|
FlushFunc func() error
|
||||||
|
|
||||||
// LoadFunc mocks the Load method.
|
// LoadFunc mocks the Load method.
|
||||||
LoadFunc func() error
|
LoadFunc func() (*specs.Spec, error)
|
||||||
|
|
||||||
// LookupEnvFunc mocks the LookupEnv method.
|
// LookupEnvFunc mocks the LookupEnv method.
|
||||||
LookupEnvFunc func(s string) (string, bool)
|
LookupEnvFunc func(s string) (string, bool)
|
||||||
@ -103,7 +104,7 @@ func (mock *SpecMock) FlushCalls() []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load calls LoadFunc.
|
// Load calls LoadFunc.
|
||||||
func (mock *SpecMock) Load() error {
|
func (mock *SpecMock) Load() (*specs.Spec, error) {
|
||||||
callInfo := struct {
|
callInfo := struct {
|
||||||
}{}
|
}{}
|
||||||
mock.lockLoad.Lock()
|
mock.lockLoad.Lock()
|
||||||
@ -111,9 +112,10 @@ func (mock *SpecMock) Load() error {
|
|||||||
mock.lockLoad.Unlock()
|
mock.lockLoad.Unlock()
|
||||||
if mock.LoadFunc == nil {
|
if mock.LoadFunc == nil {
|
||||||
var (
|
var (
|
||||||
errOut error
|
specOut *specs.Spec
|
||||||
|
errOut error
|
||||||
)
|
)
|
||||||
return errOut
|
return specOut, errOut
|
||||||
}
|
}
|
||||||
return mock.LoadFunc()
|
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
|
// modify loads, modifies, and flushes the OCI specification using the defined Modifier
|
||||||
func (r *modifyingRuntimeWrapper) modify() error {
|
func (r *modifyingRuntimeWrapper) modify() error {
|
||||||
err := r.ociSpec.Load()
|
_, err := r.ociSpec.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error loading OCI specification for modification: %v", err)
|
return fmt.Errorf("error loading OCI specification for modification: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user