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 Environment
- func (e *Environment) Cancel(force bool)
- func (e *Environment) Execute(run *otf.Run, job otf.Job) (err error)
- func (e *Environment) GetConfigurationVersionService() otf.ConfigurationVersionService
- func (e *Environment) GetPath() string
- func (e *Environment) GetRunService() otf.RunService
- func (e *Environment) GetStateVersionService() otf.StateVersionService
- func (e *Environment) RunCLI(name string, args ...string) error
- func (e *Environment) RunFunc(fn otf.EnvironmentFunc) error
- type RunLister
- type Spooler
- type SpoolerDaemon
- type Subscriber
- type Supervisor
- type Terminator
- type Worker
Constants ¶
const ( DefaultDataDir = "~/.otf-agent" DefaultID = "agent-001" )
const (
DefaultConcurrency = 5
)
const (
// SpoolerCapacity is the max number of queued runs the spooler can store
SpoolerCapacity = 100
)
Variables ¶
var ( // QueuedStatuses are the list of run statuses that indicate it is in a // queued state QueuedStatuses = []otf.RunStatus{otf.RunPlanQueued, otf.RunApplyQueued} )
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// ID uniquely identifies the agent.
ID string
// DataDir stores artefacts relating to runs, i.e. downloaded plugins,
// modules (?), configuration versions, state, etc.
DataDir string
// ServerAddr is the address (<host>:<port>) of the OTF server to connect
// to.
ServerAddr string
Spooler
*Supervisor
}
Agent runs remote operations
func NewAgent ¶
func NewAgent(logger logr.Logger, cvs otf.ConfigurationVersionService, svs otf.StateVersionService, rs otf.RunService, ps otf.PlanService, as otf.ApplyService, sub Subscriber) (*Agent, error)
NewAgent is the constructor for an Agent
type Cancelable ¶
type Cancelable interface {
Cancel(force bool)
}
Cancelable is something that is cancelable, either forcefully or gracefully.
type Environment ¶ added in v0.0.8
type Environment struct {
otf.JobService
RunService otf.RunService
ConfigurationVersionService otf.ConfigurationVersionService
StateVersionService otf.StateVersionService
logr.Logger
// contains filtered or unexported fields
}
Environment provides an execution environment for a running a run job, providing a working directory, capturing logs etc.
func NewEnvironment ¶ added in v0.0.8
func NewEnvironment( logger logr.Logger, rs otf.RunService, cvs otf.ConfigurationVersionService, svs otf.StateVersionService, js otf.JobService, job otf.Job) (*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) Execute ¶ added in v0.0.8
Execute executes a run (or anything with a Do(env)) and regardless of whether it fails, it'll close the environment logs.
func (*Environment) GetConfigurationVersionService ¶ added in v0.0.8
func (e *Environment) GetConfigurationVersionService() otf.ConfigurationVersionService
func (*Environment) GetPath ¶ added in v0.0.8
func (e *Environment) GetPath() string
func (*Environment) GetRunService ¶ added in v0.0.8
func (e *Environment) GetRunService() otf.RunService
func (*Environment) GetStateVersionService ¶ added in v0.0.8
func (e *Environment) GetStateVersionService() otf.StateVersionService
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.
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 *otf.Run
}
Spooler is a daemon from which enqueued runs can be retrieved
type SpoolerDaemon ¶
type SpoolerDaemon struct {
// Subscriber allows subscribing to stream of events
Subscriber
// Logger for logging various events
logr.Logger
// 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(rl RunLister, sub Subscriber, logger logr.Logger) (*SpoolerDaemon, error)
NewSpooler is a constructor for a Spooler pre-populated with queued runs
func (*SpoolerDaemon) GetCancelation ¶
func (s *SpoolerDaemon) GetCancelation() <-chan *otf.Run
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 Subscriber ¶ added in v0.0.8
type Subscriber interface {
Subscribe(id string) (otf.Subscription, error)
}
type Supervisor ¶
type Supervisor struct {
RunService otf.RunService
ConfigurationVersionService otf.ConfigurationVersionService
StateVersionService otf.StateVersionService
otf.JobSelector
logr.Logger
AgentID string
Spooler
*Terminator
// contains filtered or unexported fields
}
Supervisor supervises concurrently running workers.
func NewSupervisor ¶
func NewSupervisor(spooler Spooler, cvs otf.ConfigurationVersionService, svs otf.StateVersionService, rs otf.RunService, ps otf.PlanService, as otf.ApplyService, logger logr.Logger, concurrency int) *Supervisor
NewSupervisor is the constructor for Supervisor
func (*Supervisor) Start ¶
func (s *Supervisor) Start(ctx context.Context)
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)