containerrun

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(
	runner Runner,
	conditionRunner Runner,
	commandChecker Checker,
	stdio Stdio,
	args []string,
	postStartCommandName string,
	postStartCommandArgs []string,
	postStartConditionCommandName string,
	postStartConditionCommandArgs []string,
) error

Run implements the logic for the container-run CLI command.

Types

type Checker

type Checker interface {
	Check(command string) bool
}

Checker is the interface that wraps the basic Check method.

type CmdRun

type CmdRun func(
	runner Runner,
	conditionRunner Runner,
	commandChecker Checker,
	stdio Stdio,
	args []string,
	postStartCommandName string,
	postStartCommandArgs []string,
	postStartConditionCommandName string,
	postStartConditionCommandArgs []string,
) error

CmdRun represents the signature for the top-level Run command.

type Command

type Command struct {
	Name string
	Arg  []string
}

Command represents a command to be run.

type CommandChecker

type CommandChecker struct {
	// contains filtered or unexported fields
}

CommandChecker satisfies the Checker interface.

func NewCommandChecker

func NewCommandChecker(
	osStat func(string) (os.FileInfo, error),
	execLookPath func(file string) (string, error),
) *CommandChecker

NewCommandChecker constructs a new CommandChecker.

func (*CommandChecker) Check

func (cc *CommandChecker) Check(command string) bool

Check checks if command exists as a file or in $PATH.

type ConditionRunner

type ConditionRunner struct {
	// contains filtered or unexported fields
}

ConditionRunner satisfies the Runner interface. It represents a runner for a post-start pre-condition.

func NewConditionRunner

func NewConditionRunner(
	sleep func(time.Duration),
	execCommandContext func(context.Context, string, ...string) *exec.Cmd,
) *ConditionRunner

NewConditionRunner constructs a new ConditionRunner.

func (*ConditionRunner) Run

func (cr *ConditionRunner) Run(
	command Command,
	stdio Stdio,
) (Process, error)

Run is not implemented.

func (*ConditionRunner) RunContext

func (cr *ConditionRunner) RunContext(
	ctx context.Context,
	command Command,
	_ Stdio,
) (Process, error)

RunContext runs a condition until it succeeds or the context times out. The process is never returned. A context timeout makes RunContext to return the error.

type ContainerProcess

type ContainerProcess struct {
	// contains filtered or unexported fields
}

ContainerProcess satisfies the Process interface.

func NewContainerProcess

func NewContainerProcess(process OSProcess) *ContainerProcess

NewContainerProcess constructs a new ContainerProcess.

func (*ContainerProcess) Signal

func (p *ContainerProcess) Signal(sig os.Signal) error

Signal sends a signal to the process. If the process is not running anymore, it's no-op.

func (*ContainerProcess) Wait

func (p *ContainerProcess) Wait() error

Wait waits for the process.

type ContainerRunner

type ContainerRunner struct {
}

ContainerRunner satisfies the Runner interface.

func NewContainerRunner

func NewContainerRunner() *ContainerRunner

NewContainerRunner constructs a new ContainerRunner.

func (*ContainerRunner) Run

func (cr *ContainerRunner) Run(
	command Command,
	stdio Stdio,
) (Process, error)

Run runs a command async.

func (*ContainerRunner) RunContext

func (cr *ContainerRunner) RunContext(
	ctx context.Context,
	command Command,
	stdio Stdio,
) (Process, error)

RunContext runs a command async with a context.

type ExecCommandContext

type ExecCommandContext interface {
	CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd
}

ExecCommandContext wraps exec.CommandContext.

type OSProcess

type OSProcess interface {
	Signal(os.Signal) error
	Wait() (*os.ProcessState, error)
}

OSProcess is the interface that wraps the methods for *os.Process.

type Process

type Process interface {
	Signal(os.Signal) error
	Wait() error
}

Process is the interface that wraps the Signal and Wait methods of a process.

type ProcessRegistry

type ProcessRegistry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ProcessRegistry handles all the processes.

func NewProcessRegistry

func NewProcessRegistry() *ProcessRegistry

NewProcessRegistry constructs a new ProcessRegistry.

func (*ProcessRegistry) HandleSignals

func (pr *ProcessRegistry) HandleSignals(sigs <-chan os.Signal, errors chan<- error)

HandleSignals handles the signals channel and forwards them to the registered processes.

func (*ProcessRegistry) Register

func (pr *ProcessRegistry) Register(p Process) int

Register registers a process in the registry and returns how many processes are registered.

func (*ProcessRegistry) SignalAll

func (pr *ProcessRegistry) SignalAll(sig os.Signal) []error

SignalAll sends a signal to all registered processes.

type Runner

type Runner interface {
	Run(command Command, stdio Stdio) (Process, error)
	RunContext(ctx context.Context, command Command, stdio Stdio) (Process, error)
}

Runner is the interface that wraps the Run methods.

type Stdio

type Stdio struct {
	Out io.Writer
	Err io.Writer
}

Stdio represents the STDOUT and STDERR to be used by a process.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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