Documentation
¶
Overview ¶
Package agent provides a daemon capable of running remote operations on behalf of a user.
Index ¶
- Constants
- Variables
- type Agent
- type Cancelable
- type Cancelation
- type Config
- type Doer
- type Download
- type Environment
- func (e *Environment) Cancel(force bool)
- func (e *Environment) Close() error
- func (e *Environment) Execute(phase Doer) (err error)
- func (e *Environment) Path() string
- func (e *Environment) RunCLI(name string, args ...string) error
- func (e *Environment) RunFunc(fn otf.EnvironmentFunc) error
- func (e *Environment) RunTerraform(cmd string, args ...string) error
- func (e *Environment) TerraformPath() string
- func (e *Environment) WorkingDir() string
- func (e *Environment) Write(p []byte) (int, error)
- type Spooler
- type SpoolerDaemon
- type Terminator
- type Terraform
- type TerraformDownloader
- type TerraformPathFinder
- type Worker
Constants ¶
const ( DefaultID = "agent-001" DefaultConcurrency = 5 )
const HashicorpReleasesHost = "releases.hashicorp.com"
const SpoolerCapacity = 100
SpoolerCapacity is the max number of queued runs the spooler can store
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
Config
otf.Application
logr.Logger
Spooler // spools new run events
*Terminator // terminates runs
otf.Downloader // terraform cli downloader
// contains filtered or unexported fields
}
Agent processes runs.
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 Config ¶ added in v0.0.12
type Config struct {
Organization *string // only process runs belonging to org
External bool // dedicated agent (true) or otfd (false)
Concurrency int // number of workers
Sandbox bool // isolate privileged ops within sandbox
Debug bool // toggle debug mode
PluginCache bool // toggle use of terraform's shared plugin cache
}
Config configures the agent.
func NewConfigFromFlags ¶ added in v0.0.12
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
type Environment ¶ added in v0.0.8
type Environment struct {
otf.Application
logr.Logger
otf.Downloader // Downloader for workers to download terraform cli on demand
Terraform // For looking up path to terraform cli
Config
// 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( ctx context.Context, logger logr.Logger, app otf.Application, run *otf.Run, envs []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. The path is set to the workspace's working directory.
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) WorkingDir ¶ added in v0.0.24
func (e *Environment) WorkingDir() string
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
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 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