agent

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: MPL-2.0 Imports: 25 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 (
	DefaultID          = "agent-001"
	DefaultConcurrency = 5
)
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")
	DefaultEnvs    = []string{
		"TF_IN_AUTOMATION=true",
		"CHECKPOINT_DISABLE=true",
	}
)

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.

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 and its workers

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 *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

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
	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

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 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 {
	*Agent
}

Worker sequentially executes runs.

func (*Worker) Start

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

Start starts the worker which waits for runs to execute.

Jump to

Keyboard shortcuts

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