v1.0.0-beta.7 Latest Latest

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

Go to latest
Published: Sep 30, 2019 License: Apache-2.0 Imports: 20 Imported by: 0




View Source
const (
	// LogLevelEnv name for env on which client relies while selecting log level.

	// LogLevelDebug singularity client will be launched with -d flag.
	LogLevelDebug = "debug"


View Source
var ErrNotFound = fmt.Errorf("no instance found for provided name")

ErrNotFound us returned when Singularity OCI engine responds with corresponding error message and exit status 255


func ObserveState

func ObserveState(ctx context.Context, socket string) (<-chan State, error)

ObserveState listens on passed socket for container state changes and passes them to the channel. ObserveState creates socket if necessary. The returned channel is buffered to eliminate any goroutine leaks. The channel will be closed if either container has transmitted into StateExited or any error during networking occurred. ObserveState returns error only if it fails to start listener on the passed socket.


type BuildConfig

type BuildConfig struct {
	SingularityConfdir string

BuildConfig is Singularity's build configuration.

type CLIClient

type CLIClient struct {
	// contains filtered or unexported fields

CLIClient is a type for convenient interaction with singularity OCI runtime engine via CLI.

func NewCLIClient

func NewCLIClient() *CLIClient

NewCLIClient returns new CLIClient ready to use.

func (*CLIClient) BuildConfig

func (c *CLIClient) BuildConfig() (*BuildConfig, error)

BuildConfig returns configuration which was used to build current Singularity installation.

func (*CLIClient) Create

func (c *CLIClient) Create(id, bundle string, stdin, tty bool, flags ...string) (io.WriteCloser, error)

Create asks runtime to create a container with passed parameters. When stdin is false no stdin stream is allocated and all reads from stdin in the container will always result in EOF. When no tty is allocated by the runtime, Create returns master end of the allocated tty (need to allocate it to separate stderr) that can be used to propagate any input into container, if stdin was requested. Master end should be closed as soon as container is not running any more. For pod master end can be closed immediately.

func (*CLIClient) Delete

func (c *CLIClient) Delete(id string) error

Delete asks runtime to delete container with passed id. If runtime fails to find object with given id, ErrNotFound is returned.

func (*CLIClient) Exec

func (c *CLIClient) Exec(ctx context.Context, id string,
	stdin io.Reader, stdout, stderr io.Writer,
	args, envs []string) error

Exec executes passed command inside a container setting io streams to passed ones.

func (*CLIClient) ExecSync

func (c *CLIClient) ExecSync(ctx context.Context, id string, args, envs []string) (*ExecResponse, error)

ExecSync executes a command inside a container synchronously until context is done and returns the result.

func (*CLIClient) Kill

func (c *CLIClient) Kill(id string, force bool) error

Kill asks runtime to send SIGINT to container with passed id. If force is true that SIGKILL is sent instead.

func (*CLIClient) PrepareExec

func (c *CLIClient) PrepareExec(ctx context.Context, id string, args, envs []string) *exec.Cmd

PrepareExec simply prepares command to call to execute inside a given container. It makes sure singularity exec script is called.

func (*CLIClient) Signal

func (c *CLIClient) Signal(id, sig string) error

Signal asks runtime to send passed sig to container with passed id.

func (*CLIClient) Start

func (c *CLIClient) Start(id string) error

Start asks runtime to start container with passed id.

func (*CLIClient) State

func (c *CLIClient) State(id string) (*ociruntime.State, error)

State returns state of a container with passed id. If runtime fails to find object with given id, ErrNotFound is returned.

func (*CLIClient) UpdateContainerResources

func (c *CLIClient) UpdateContainerResources(id string, req *specs.LinuxResources) error

UpdateContainerResources asks runtime to update container resources according to the passed parameter.

type ExecResponse

type ExecResponse struct {
	// Captured command stdout output.
	Stdout []byte
	// Captured command stderr output.
	Stderr []byte
	// Exit code the command finished with.
	ExitCode int32

ExecResponse holds result of command execution inside a container.

type State

type State int

State represents an OCI container state.

const (
	// StateUnknown means current state is unknown (perhaps, something went wrong).
	StateUnknown State = iota
	// StateCreating means container is being created at the moment.
	// StateCreated means container is created without any errors.
	// StateRunning means container is running at the moment.
	// StateExited means container has finished possibly with errors.

func StatusToState

func StatusToState(status string) State

StatusToState is a helper func to convert container OCI status to State.

func (State) String

func (s State) String() string

String returns a human readable representation of a State.

Jump to

Keyboard shortcuts

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