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) Write(p []byte) (int, error)
- type Spooler
- type SpoolerDaemon
- type Supervisor
- type Terminator
- type Terraform
- type TerraformDownloader
- type TerraformPathFinder
- type Worker
Constants ¶
const (
DefaultConcurrency = 5
)
const (
DefaultID = "agent-001"
)
const HashicorpReleasesHost = "releases.hashicorp.com"
const SpoolerCapacity = 100
SpoolerCapacity is the max number of queued runs the spooler can store
Variables ¶
var PluginCacheDir = filepath.Join(os.TempDir(), "plugin-cache")
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
Spooler
*Supervisor
}
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 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
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
// 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
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 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
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