Documentation
¶
Overview ¶
Package runner provides interfaces and implementations for managing service instances.
Index ¶
- type ExecOptions
- type ExecStream
- type FakeExecStream
- func (s *FakeExecStream) Close() error
- func (s *FakeExecStream) ExitCode() (int, error)
- func (s *FakeExecStream) Read(p []byte) (n int, err error)
- func (s *FakeExecStream) ResizeTerminal(width, height uint32) error
- func (s *FakeExecStream) Signal(sigName string) error
- func (s *FakeExecStream) Stderr() io.Reader
- func (s *FakeExecStream) Write(p []byte) (n int, err error)
- type InstanceStatus
- type LogOptions
- type LogReader
- type MockExecStream
- func (m *MockExecStream) Close() error
- func (m *MockExecStream) ExitCode() (int, error)
- func (m *MockExecStream) Read(p []byte) (n int, err error)
- func (m *MockExecStream) ResizeTerminal(width, height uint32) error
- func (m *MockExecStream) Signal(sigName string) error
- func (m *MockExecStream) Stderr() io.Reader
- func (m *MockExecStream) Write(p []byte) (n int, err error)
- type MockRunner
- func (m *MockRunner) Create(ctx context.Context, instance *types.Instance) error
- func (m *MockRunner) Exec(ctx context.Context, instance *types.Instance, options ExecOptions) (ExecStream, error)
- func (m *MockRunner) GetLogs(ctx context.Context, instance *types.Instance, options LogOptions) (io.ReadCloser, error)
- func (m *MockRunner) List(ctx context.Context, namespace string) ([]*types.Instance, error)
- func (m *MockRunner) Remove(ctx context.Context, instance *types.Instance, force bool) error
- func (m *MockRunner) Start(ctx context.Context, instance *types.Instance) error
- func (m *MockRunner) Status(ctx context.Context, instance *types.Instance) (types.InstanceStatus, error)
- func (m *MockRunner) Stop(ctx context.Context, instance *types.Instance, timeout time.Duration) error
- type Reader
- type Runner
- type RunnerProvider
- type TestExecStream
- func (s *TestExecStream) Close() error
- func (s *TestExecStream) ExitCode() (int, error)
- func (s *TestExecStream) Read(p []byte) (n int, err error)
- func (s *TestExecStream) ResizeTerminal(width, height uint32) error
- func (s *TestExecStream) Signal(sigName string) error
- func (s *TestExecStream) Stderr() io.Reader
- func (s *TestExecStream) Write(p []byte) (n int, err error)
- type TestRunner
- func (r *TestRunner) Create(ctx context.Context, instance *types.Instance) error
- func (r *TestRunner) Exec(ctx context.Context, instance *types.Instance, options ExecOptions) (ExecStream, error)
- func (r *TestRunner) GetLogs(ctx context.Context, instance *types.Instance, options LogOptions) (io.ReadCloser, error)
- func (r *TestRunner) List(ctx context.Context, namespace string) ([]*types.Instance, error)
- func (r *TestRunner) Remove(ctx context.Context, instance *types.Instance, force bool) error
- func (r *TestRunner) Start(ctx context.Context, instance *types.Instance) error
- func (r *TestRunner) Status(ctx context.Context, instance *types.Instance) (types.InstanceStatus, error)
- func (r *TestRunner) Stop(ctx context.Context, instance *types.Instance, timeout time.Duration) error
- func (r *TestRunner) Type() types.RunnerType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecOptions ¶
type ExecOptions struct {
// Command is the command to execute.
Command []string
// Env is a map of environment variables to set for the command.
Env map[string]string
// WorkingDir is the working directory for the command.
WorkingDir string
// TTY indicates whether to allocate a pseudo-TTY.
TTY bool
// TerminalWidth is the initial width of the terminal.
TerminalWidth uint32
// TerminalHeight is the initial height of the terminal.
TerminalHeight uint32
}
ExecOptions defines options for executing a command in a running instance.
func GetExecOptions ¶
func GetExecOptions(command []string, instance *types.Instance) ExecOptions
GetExecOptions returns ExecOptions using values from the instance
type ExecStream ¶
type ExecStream interface {
// Write writes data to the standard input of the process.
Write(p []byte) (n int, err error)
// Read reads data from the standard output of the process.
Read(p []byte) (n int, err error)
// Stderr provides access to the standard error stream of the process.
Stderr() io.Reader
// ResizeTerminal resizes the terminal (if TTY was enabled).
ResizeTerminal(width, height uint32) error
// Signal sends a signal to the process.
Signal(sigName string) error
// ExitCode returns the exit code after the process has completed.
// Returns an error if the process has not completed or if there was an error.
ExitCode() (int, error)
// Close terminates the exec session and releases resources.
Close() error
}
ExecStream provides bidirectional communication with an exec session.
type FakeExecStream ¶
type FakeExecStream struct {
StdoutContent []byte
StdoutPos int
StderrContent []byte
StderrReader io.Reader
ExitCodeVal int
SignalsSent []string
InputCapture []byte
Closed bool
// contains filtered or unexported fields
}
FakeExecStream implements ExecStream for testing
func NewFakeExecStream ¶
func NewFakeExecStream(stdout, stderr []byte, exitCode int) *FakeExecStream
NewFakeExecStream creates a new fake exec stream with predefined content
func (*FakeExecStream) Close ¶
func (s *FakeExecStream) Close() error
Close marks the stream as closed
func (*FakeExecStream) ExitCode ¶
func (s *FakeExecStream) ExitCode() (int, error)
ExitCode returns the predefined exit code
func (*FakeExecStream) Read ¶
func (s *FakeExecStream) Read(p []byte) (n int, err error)
Read returns predefined output content in chunks
func (*FakeExecStream) ResizeTerminal ¶
func (s *FakeExecStream) ResizeTerminal(width, height uint32) error
ResizeTerminal records terminal resize events
func (*FakeExecStream) Signal ¶
func (s *FakeExecStream) Signal(sigName string) error
Signal records signals sent to the process
func (*FakeExecStream) Stderr ¶
func (s *FakeExecStream) Stderr() io.Reader
Stderr returns an io.Reader for the stderr stream
type InstanceStatus ¶
type InstanceStatus struct {
// State is the current state of the instance.
State types.InstanceStatus
// ContainerID is the ID of the container (if applicable).
ContainerID string
// InstanceID is the ID of the Rune instance.
InstanceID string
// CreatedAt is when the instance was created.
CreatedAt time.Time
// StartedAt is when the instance was started.
StartedAt time.Time
// FinishedAt is when the instance finished or failed.
FinishedAt time.Time
// ExitCode is the exit code if the instance has stopped.
ExitCode int
// ErrorMessage contains any error information.
ErrorMessage string
}
InstanceStatus extends types.InstanceStatus with additional details needed by runners.
type LogOptions ¶
type LogOptions struct {
// Follow indicates whether to follow the log output (like tail -f).
Follow bool
// Tail indicates the number of lines to show from the end of the logs (0 for all).
Tail int
// Since shows logs since a specific timestamp.
Since time.Time
// Until shows logs until a specific timestamp.
Until time.Time
// Timestamps indicates whether to include timestamps.
Timestamps bool
}
LogOptions defines options for retrieving logs.
type LogReader ¶
type LogReader interface {
Reader
}
LogReader represents a readable stream of log data.
type MockExecStream ¶
MockExecStream is a mock implementation of the runner.ExecStream interface
func (*MockExecStream) Close ¶
func (m *MockExecStream) Close() error
func (*MockExecStream) ExitCode ¶
func (m *MockExecStream) ExitCode() (int, error)
func (*MockExecStream) ResizeTerminal ¶
func (m *MockExecStream) ResizeTerminal(width, height uint32) error
func (*MockExecStream) Signal ¶
func (m *MockExecStream) Signal(sigName string) error
func (*MockExecStream) Stderr ¶
func (m *MockExecStream) Stderr() io.Reader
type MockRunner ¶
MockRunner is a mock implementation of the runner.Runner interface for testing
func (*MockRunner) Exec ¶
func (m *MockRunner) Exec(ctx context.Context, instance *types.Instance, options ExecOptions) (ExecStream, error)
func (*MockRunner) GetLogs ¶
func (m *MockRunner) GetLogs(ctx context.Context, instance *types.Instance, options LogOptions) (io.ReadCloser, error)
func (*MockRunner) Status ¶
func (m *MockRunner) Status(ctx context.Context, instance *types.Instance) (types.InstanceStatus, error)
type Reader ¶
Reader is an interface that represents a readable stream. It extends the standard io.Reader interface.
type Runner ¶
type Runner interface {
// Type returns the type of runner.
Type() types.RunnerType
// Create creates a new service instance but does not start it.
Create(ctx context.Context, instance *types.Instance) error
// Start starts an existing service instance.
Start(ctx context.Context, instance *types.Instance) error
// Stop stops a running service instance.
Stop(ctx context.Context, instance *types.Instance, timeout time.Duration) error
// Remove removes a service instance.
Remove(ctx context.Context, instance *types.Instance, force bool) error
// GetLogs retrieves logs from a service instance.
GetLogs(ctx context.Context, instance *types.Instance, options LogOptions) (io.ReadCloser, error)
// Status retrieves the current status of a service instance.
Status(ctx context.Context, instance *types.Instance) (types.InstanceStatus, error)
// List lists all service instances managed by this runner.
List(ctx context.Context, namespace string) ([]*types.Instance, error)
// Exec creates an interactive exec session with a running instance.
// Returns an ExecStream for bidirectional communication.
Exec(ctx context.Context, instance *types.Instance, options ExecOptions) (ExecStream, error)
}
Runner defines the interface for service runners, which are responsible for managing the lifecycle of service instances (containers, processes, etc.).
type RunnerProvider ¶
type RunnerProvider interface {
// GetInstanceRunner returns the appropriate runner for an instance
GetInstanceRunner(instance *types.Instance) (Runner, error)
}
RunnerProvider defines a simplified interface for getting runners
type TestExecStream ¶
type TestExecStream struct {
StdoutContent []byte
StderrContent []byte
ExitCodeVal int
InputCapture []byte
SignalsSent []string
Resizes []struct{ Width, Height uint32 }
// contains filtered or unexported fields
}
TestExecStream is a predictable implementation of ExecStream for testing
func (*TestExecStream) Close ¶
func (s *TestExecStream) Close() error
Close marks the stream as closed
func (*TestExecStream) ExitCode ¶
func (s *TestExecStream) ExitCode() (int, error)
ExitCode returns the predefined exit code
func (*TestExecStream) Read ¶
func (s *TestExecStream) Read(p []byte) (n int, err error)
Read returns predefined output content in chunks
func (*TestExecStream) ResizeTerminal ¶
func (s *TestExecStream) ResizeTerminal(width, height uint32) error
ResizeTerminal records terminal resize events
func (*TestExecStream) Signal ¶
func (s *TestExecStream) Signal(sigName string) error
Signal records signals sent to the process
func (*TestExecStream) Stderr ¶
func (s *TestExecStream) Stderr() io.Reader
Stderr returns an io.Reader for the stderr stream
type TestRunner ¶
type TestRunner struct {
// Configurable test behavior
StatusResults map[string]types.InstanceStatus
Instances map[string]*types.Instance
ExecOutput []byte
ExecErrOutput []byte
ExitCodeVal int
LogOutput []byte
ErrorToReturn error
// Optional tracking for verification
CreatedInstances []*types.Instance
StartedInstances []string
StoppedInstances []string
RemovedInstances []string
ExecCalls []string
ExecOptions []ExecOptions
LogCalls []string
StatusCalls []string
// contains filtered or unexported fields
}
TestRunner is a simplified, predictable implementation of Runner for testing. Instead of requiring expectations to be set up, it returns predefined responses.
func NewTestRunner ¶
func NewTestRunner() *TestRunner
NewTestRunner creates a new TestRunner with default behavior
func (*TestRunner) Exec ¶
func (r *TestRunner) Exec(ctx context.Context, instance *types.Instance, options ExecOptions) (ExecStream, error)
Exec returns a predefined TestExecStream
func (*TestRunner) GetLogs ¶
func (r *TestRunner) GetLogs(ctx context.Context, instance *types.Instance, options LogOptions) (io.ReadCloser, error)
GetLogs returns predefined log output
func (*TestRunner) Status ¶
func (r *TestRunner) Status(ctx context.Context, instance *types.Instance) (types.InstanceStatus, error)
Status returns predefined status or Running as default
func (*TestRunner) Stop ¶
func (r *TestRunner) Stop(ctx context.Context, instance *types.Instance, timeout time.Duration) error
Stop tracks instance stopping
func (*TestRunner) Type ¶
func (r *TestRunner) Type() types.RunnerType
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package docker provides a Docker-based implementation of the runner interface.
|
Package docker provides a Docker-based implementation of the runner interface. |
|
Package process implements a Runner interface for local processes
|
Package process implements a Runner interface for local processes |
|
security
Package security provides security implementations for process runners
|
Package security provides security implementations for process runners |