agent

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package agent provides a daemon capable of running remote operations on behalf of a user.

Index

Constants

View Source
const (
	DefaultConcurrency = 5
)
View Source
const (
	DefaultID = "agent-001"
)
View Source
const HashicorpReleasesHost = "releases.hashicorp.com"
View Source
const SpoolerCapacity = 100

SpoolerCapacity is the max number of queued runs the spooler can store

Variables

View Source
var PluginCacheDir = filepath.Join(os.TempDir(), "plugin-cache")

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Spooler
	*Supervisor
}

Agent processes runs.

func NewAgent

func NewAgent(logger logr.Logger, app otf.Application, cfg Config) (*Agent, error)

NewAgent is the constructor for an Agent

func (*Agent) Start

func (a *Agent) Start(ctx context.Context) error

Start starts the agent daemon

type Cancelable

type Cancelable interface {
	Cancel(force bool)
}

Cancelable is something that is cancelable, either forcefully or gracefully.

type Cancelation added in v0.0.12

type Cancelation struct {
	Run      *otf.Run
	Forceful bool
}

type Config added in v0.0.12

type Config struct {
	// Organization if non-nil restricts the agent to processing runs belonging
	// to the specified organization.
	Organization *string
	// External indicates whether the agent is running as a separate process,
	// otf-agent, thus whether it handles runs for workspaces in remote mode
	// (external=false) or workspaces in agent mode (external=true).
	External bool
	// Sandbox determines whether terraform is invoked within an isolated
	// environment, restricting its access to various host resources
	Sandbox bool
	// Concurrency determines number of runs that can be handled concurrently
	Concurrency int
}

Config configures the agent.

func NewConfigFromFlags added in v0.0.12

func NewConfigFromFlags(flags *pflag.FlagSet) *Config

type Doer added in v0.0.12

type Doer interface {
	// TODO: environment is excessive; can we pass in something that exposes
	// fewer methods like an 'executor'?
	Do(otf.Environment) error
}

type Download added in v0.0.12

type Download struct {
	// for outputting progress updates
	io.Writer
	// contains filtered or unexported fields
}

Download represents a current download of a version of terraform

func (*Download) Download added in v0.0.12

func (d *Download) Download() error

type Environment added in v0.0.8

type Environment struct {
	otf.Application

	logr.Logger

	// Downloader for workers to download terraform cli on demand
	otf.Downloader
	// For looking up path to terraform cli
	Terraform
	// contains filtered or unexported fields
}

Environment provides an execution environment for a run, providing a working directory, services, capturing logs etc.

func NewEnvironment added in v0.0.8

func NewEnvironment(
	logger logr.Logger,
	app otf.Application,
	run *otf.Run,
	ctx context.Context,
	environmentVariables []string,
	downloader otf.Downloader,
	cfg Config,
) (*Environment, error)

func (*Environment) Cancel added in v0.0.8

func (e *Environment) Cancel(force bool)

Cancel terminates execution. Force controls whether termination is graceful or not. Performed on a best-effort basis - the func or process may have finished before they are cancelled, in which case only the next func or process will be stopped from executing.

func (*Environment) Close added in v0.0.12

func (e *Environment) Close() error

func (*Environment) Execute added in v0.0.8

func (e *Environment) Execute(phase Doer) (err error)

Execute executes a phase and regardless of whether it fails, it'll close the environment logs.

func (*Environment) Path added in v0.0.12

func (e *Environment) Path() string

func (*Environment) RunCLI added in v0.0.8

func (e *Environment) RunCLI(name string, args ...string) error

RunCLI executes a CLI process in the executor.

func (*Environment) RunFunc added in v0.0.8

func (e *Environment) RunFunc(fn otf.EnvironmentFunc) error

RunFunc invokes a func in the executor.

func (*Environment) RunTerraform added in v0.0.12

func (e *Environment) RunTerraform(cmd string, args ...string) error

RunTerraform runs a terraform command in the environment

func (*Environment) TerraformPath added in v0.0.12

func (e *Environment) TerraformPath() string

TerraformPath provides the path to the terraform bin

func (*Environment) Write added in v0.0.12

func (e *Environment) Write(p []byte) (int, error)

type Spooler

type Spooler interface {
	// Start the daemon
	Start(context.Context) error

	// GetRun receives spooled runs
	GetRun() <-chan *otf.Run

	// GetCancelation receives requests to cancel runs
	GetCancelation() <-chan Cancelation
}

Spooler is a daemon from which enqueued runs can be retrieved

type SpoolerDaemon

type SpoolerDaemon struct {

	// Application for retrieving queued runs
	otf.Application
	// Logger for logging various events
	logr.Logger
	Config
	// contains filtered or unexported fields
}

SpoolerDaemon implements Spooler, receiving runs with either a queued plan or apply, and converting them into spooled jobs.

func NewSpooler

func NewSpooler(app otf.Application, logger logr.Logger, cfg Config) *SpoolerDaemon

NewSpooler populates a Spooler with queued runs

func (*SpoolerDaemon) GetCancelation

func (s *SpoolerDaemon) GetCancelation() <-chan Cancelation

GetCancelation returns a channel of cancelation requests

func (*SpoolerDaemon) GetRun added in v0.0.8

func (s *SpoolerDaemon) GetRun() <-chan *otf.Run

GetRun returns a channel of queued runs

func (*SpoolerDaemon) Start

func (s *SpoolerDaemon) Start(ctx context.Context) error

Start starts the spooler

type Supervisor

type Supervisor struct {
	otf.Application
	Config
	logr.Logger
	Spooler
	*Terminator
	// Downloader for workers to download tf cli on demand
	otf.Downloader
	// contains filtered or unexported fields
}

Supervisor supervises concurrently running workers.

func NewSupervisor

func NewSupervisor(spooler Spooler, app otf.Application, logger logr.Logger, cfg Config) *Supervisor

NewSupervisor is the constructor for Supervisor

func (*Supervisor) Start

func (s *Supervisor) Start(ctx context.Context) error

Start starts the supervisor's workers.

type Terminator

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

Terminator handles canceling items using their ID

func NewTerminator

func NewTerminator() *Terminator

func (*Terminator) Cancel

func (t *Terminator) Cancel(id string, force bool)

func (*Terminator) CheckIn

func (t *Terminator) CheckIn(id string, job Cancelable)

func (*Terminator) CheckOut

func (t *Terminator) CheckOut(id string)

type Terraform added in v0.0.12

type Terraform interface {
	TerraformPath(version string) string
}

type TerraformDownloader added in v0.0.12

type TerraformDownloader struct {

	// used to lookup destination path for saving download
	Terraform
	// contains filtered or unexported fields
}

TerraformDownloader downloads terraform binaries

func NewTerraformDownloader added in v0.0.12

func NewTerraformDownloader() *TerraformDownloader

func (*TerraformDownloader) Download added in v0.0.12

func (d *TerraformDownloader) Download(ctx context.Context, version string, w io.Writer) (string, error)

Download ensures the given version of terraform is available on the local filesystem and returns its path. Thread-safe: if a download is in-flight and another download is requested then it'll be made to wait until the former has finished.

type TerraformPathFinder added in v0.0.12

type TerraformPathFinder struct{}

func (*TerraformPathFinder) TerraformPath added in v0.0.12

func (*TerraformPathFinder) TerraformPath(version string) string

TerraformPath returns the path to a given version of the terraform binary

type Worker

type Worker struct {
	*Supervisor
}

Worker sequentially executes runs on behalf of a supervisor.

func (*Worker) Start

func (w *Worker) Start(ctx context.Context)

Start starts the worker which waits for runs to execute.

Directories

Path Synopsis
Package mock provides mocks for the parent agent package
Package mock provides mocks for the parent agent package

Jump to

Keyboard shortcuts

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