virtualceb

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package virtualceb is used to provide "virtual" CEB functionality. A virtual CEB acts like an entrypoint but doesn't represent a real physical instance of a deployment, hence the "virtual" labeling.

This functionality is used in situations where a real entrypoint either can't run or is impractical to run. Most commonly this is used for serverless type environments such as Lambda. In those scenarios, it is impractical to run the entrypoint for tasks such as exec and logs since the instances are so ephemeral.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// The deployment id that this virtual session is for. The server
	// will validate this value.
	DeploymentId string

	// The instance id for this virtual instance.
	InstanceId string

	// How to connect back to the server. Because Virtual is usually used in the context
	// of a Runner, this can be the same Client the Runner is using.
	Client pb.WaypointClient

	// Support Dynamic Config
	EnableDynamicConfig bool
}

Config is the configuration of the CEB Virtual value

type ExecHandler

type ExecHandler interface {
	CreateSession(ctx context.Context, sess *ExecInfo) (ExecSession, error)
}

ExecHandler represents the ability to spawn exec sessions. It is the abstraction layer Virtual uses for creating exec sessions.

type ExecInfo

type ExecInfo struct {
	Input  io.Reader // stdin
	Output io.Writer // stdout
	Error  io.Writer // stderr

	// Command line arguments
	Arguments []string

	// The environment variables to set in the exec context
	Environment []string

	// Specifies if we and how we should allocate a pty to handle
	// the command.
	PTY *pb.ExecStreamRequest_PTY
}

ExecInfo contains values to run an exec session.

type ExecSession

type ExecSession interface {
	// Called to start the session. Should block until the session is finished.
	Run(ctx context.Context) error

	// Close the running session down. Called concurrently to Run.
	Close() error

	// Resize the PTY according to the given window information.
	// Called concurrently to Run.
	PTYResize(*pb.ExecStreamRequest_WindowSize) error
}

ExecSession represents a running exec, spawned by ExecHandler.

type Virtual

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

Virtual represents a virtual CEB instance. It is used to manifest an instance that performs exec operations via a Go interface rather than just running a command.

func New

func New(log hclog.Logger, cfg Config) (*Virtual, error)

New creates a new Virtual value based on the logger and config.

func (*Virtual) RunExec

func (v *Virtual) RunExec(ctx context.Context, h ExecHandler, count int) error

RunExec connects to the server and handles any inbound Exec requests via the ExecHandler. The count parameter indicates how many exec sessions to handle before returning. If count is less than 0, it handles sessions forever.

func (*Virtual) RunLogs

func (v *Virtual) RunLogs(
	ctx context.Context,
	startTime time.Time,
	limit int,
	f func(ctx context.Context, lv *component.LogViewer) error,
) error

RunLogs connects to the server and streams logs from the function passed back to the server. The log entries will be associated with the Instance Id the virtual CEB is using.

Jump to

Keyboard shortcuts

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