oci

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBundleDir

func GetBundleDir(args []string) (string, error)

GetBundleDir returns the bundle directory or default depending on the supplied command line arguments.

func GetBundleDirFromArgs

func GetBundleDirFromArgs(args []string) (string, error)

GetBundleDirFromArgs checks the specified slice of strings (argv) for a 'bundle' flag as allowed by runc. The following are supported: --bundle{{SEP}}BUNDLE_PATH -bundle{{SEP}}BUNDLE_PATH -b{{SEP}}BUNDLE_PATH where {{SEP}} is either ' ' or '='

func GetSpecFilePath

func GetSpecFilePath(bundleDir string) string

GetSpecFilePath returns the expected path to the OCI specification file for the given bundle directory.

func HasCreateSubcommand

func HasCreateSubcommand(args []string) bool

HasCreateSubcommand checks the supplied arguments for a 'create' subcommand

func IsBundleFlag

func IsBundleFlag(arg string) bool

IsBundleFlag is a helper function that checks wither the specified argument represents a bundle flag (--bundle or -b)

func LoadFrom added in v1.10.0

func LoadFrom(reader io.Reader) (*specs.Spec, error)

LoadFrom reads the contents of the OCI spec from the specified io.Reader.

Types

type Runtime

type Runtime interface {
	Exec([]string) error
}

Runtime is an interface for a runtime shim. The Exec method accepts a list of command line arguments, and returns an error / nil.

func NewLowLevelRuntime

func NewLowLevelRuntime(logger logger.Interface, candidates []string) (Runtime, error)

NewLowLevelRuntime creates a Runtime that wraps a low-level runtime executable. The executable specified is taken from the list of supplied candidates, with the first match present in the PATH being selected. A logger is also specified.

func NewModifyingRuntimeWrapper added in v1.13.0

func NewModifyingRuntimeWrapper(logger logger.Interface, runtime Runtime, spec Spec, modifier SpecModifier) Runtime

NewModifyingRuntimeWrapper creates a runtime wrapper that applies the specified modifier to the OCI specification before invoking the wrapped runtime. If the modifier is nil, the input runtime is returned.

func NewRuntimeForPath

func NewRuntimeForPath(logger logger.Interface, path string) (Runtime, error)

NewRuntimeForPath creates a Runtime for the specified logger and path

type RuntimeMock

type RuntimeMock struct {
	// ExecFunc mocks the Exec method.
	ExecFunc func(strings []string) error
	// contains filtered or unexported fields
}

RuntimeMock is a mock implementation of Runtime.

func TestSomethingThatUsesRuntime(t *testing.T) {

	// make and configure a mocked Runtime
	mockedRuntime := &RuntimeMock{
		ExecFunc: func(strings []string) error {
			panic("mock out the Exec method")
		},
	}

	// use mockedRuntime in code that requires Runtime
	// and then make assertions.

}

func (*RuntimeMock) Exec

func (mock *RuntimeMock) Exec(strings []string) error

Exec calls ExecFunc.

func (*RuntimeMock) ExecCalls

func (mock *RuntimeMock) ExecCalls() []struct {
	Strings []string
}

ExecCalls gets all the calls that were made to Exec. Check the length with:

len(mockedRuntime.ExecCalls())

type Spec

type Spec interface {
	Load() (*specs.Spec, error)
	Flush() error
	Modify(SpecModifier) error
	LookupEnv(string) (string, bool)
}

Spec defines the operations to be performed on an OCI specification

func NewFileSpec added in v1.10.0

func NewFileSpec(filepath string) Spec

NewFileSpec creates an object that encapsulates a file-backed OCI spec. This can be used to read from the file, modify the spec, and write to the same file.

func NewMemorySpec added in v1.10.0

func NewMemorySpec(spec *specs.Spec) Spec

NewMemorySpec creates a Spec instance from the specified OCI spec

func NewSpec added in v1.10.0

func NewSpec(logger logger.Interface, args []string) (Spec, error)

NewSpec creates fileSpec based on the command line arguments passed to the application using the specified logger.

type SpecMock

type SpecMock struct {
	// FlushFunc mocks the Flush method.
	FlushFunc func() error

	// LoadFunc mocks the Load method.
	LoadFunc func() (*specs.Spec, error)

	// LookupEnvFunc mocks the LookupEnv method.
	LookupEnvFunc func(s string) (string, bool)

	// ModifyFunc mocks the Modify method.
	ModifyFunc func(specModifier SpecModifier) error
	// contains filtered or unexported fields
}

SpecMock is a mock implementation of Spec.

func TestSomethingThatUsesSpec(t *testing.T) {

	// make and configure a mocked Spec
	mockedSpec := &SpecMock{
		FlushFunc: func() error {
			panic("mock out the Flush method")
		},
		LoadFunc: func() (*specs.Spec, error) {
			panic("mock out the Load method")
		},
		LookupEnvFunc: func(s string) (string, bool) {
			panic("mock out the LookupEnv method")
		},
		ModifyFunc: func(specModifier SpecModifier) error {
			panic("mock out the Modify method")
		},
	}

	// use mockedSpec in code that requires Spec
	// and then make assertions.

}

func (*SpecMock) Flush

func (mock *SpecMock) Flush() error

Flush calls FlushFunc.

func (*SpecMock) FlushCalls

func (mock *SpecMock) FlushCalls() []struct {
}

FlushCalls gets all the calls that were made to Flush. Check the length with:

len(mockedSpec.FlushCalls())

func (*SpecMock) Load

func (mock *SpecMock) Load() (*specs.Spec, error)

Load calls LoadFunc.

func (*SpecMock) LoadCalls

func (mock *SpecMock) LoadCalls() []struct {
}

LoadCalls gets all the calls that were made to Load. Check the length with:

len(mockedSpec.LoadCalls())

func (*SpecMock) LookupEnv

func (mock *SpecMock) LookupEnv(s string) (string, bool)

LookupEnv calls LookupEnvFunc.

func (*SpecMock) LookupEnvCalls

func (mock *SpecMock) LookupEnvCalls() []struct {
	S string
}

LookupEnvCalls gets all the calls that were made to LookupEnv. Check the length with:

len(mockedSpec.LookupEnvCalls())

func (*SpecMock) Modify

func (mock *SpecMock) Modify(specModifier SpecModifier) error

Modify calls ModifyFunc.

func (*SpecMock) ModifyCalls

func (mock *SpecMock) ModifyCalls() []struct {
	SpecModifier SpecModifier
}

ModifyCalls gets all the calls that were made to Modify. Check the length with:

len(mockedSpec.ModifyCalls())

type SpecModifier

type SpecModifier interface {
	// Modify is a method that accepts a pointer to an OCI Srec and returns an
	// error. The intention is that the function would modify the spec in-place.
	Modify(*specs.Spec) error
}

SpecModifier defines an interface for modifying a (raw) OCI spec

type State added in v1.10.0

type State specs.State

State stores an OCI container state. This includes the spec path and the environment

func LoadContainerState added in v1.10.0

func LoadContainerState(filename string) (*State, error)

LoadContainerState loads the container state from the specified filename. If the filename is empty or '-' the state is loaded from STDIN

func ReadContainerState added in v1.10.0

func ReadContainerState(reader io.Reader) (*State, error)

ReadContainerState reads the container state from the specified reader

func (*State) GetContainerRoot added in v1.10.0

func (s *State) GetContainerRoot() (string, error)

GetContainerRoot returns the root for the container from the associated spec. If the spec is not yet loaded, it is loaded and cached.

func (*State) LoadSpec added in v1.10.0

func (s *State) LoadSpec() (*specs.Spec, error)

LoadSpec loads the OCI spec associated with the container state

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL