Documentation
¶
Overview ¶
Package agent contains code related to agents
Package agent contains code related to agents
Index ¶
- Constants
- Variables
- func New(logger logr.Logger, app client, cfg Config) (*daemon, error)
- func NewAgentsCommand(client *otfapi.Client) *cobra.Command
- func NewRPC(logger logr.Logger, cfg Config, apiConfig otfapi.Config) (*daemon, error)
- func NewRPCClient(cfg otfapi.Config, agentID *string) (*rpcClient, error)
- func NewService(opts ServiceOptions) *service
- type Agent
- type AgentService
- type AgentStatus
- type Config
- type CreateAgentPoolOptions
- type CreateAgentTokenOptions
- type InProcClient
- type Job
- func (j *Job) CanAccessOrganization(action rbac.Action, name string) bool
- func (j *Job) CanAccessSite(action rbac.Action) bool
- func (j *Job) CanAccessTeam(rbac.Action, string) bool
- func (j *Job) CanAccessWorkspace(action rbac.Action, policy internal.WorkspacePolicy) bool
- func (j *Job) IsOwner(string) bool
- func (j *Job) IsSiteAdmin() bool
- func (j *Job) LogValue() slog.Value
- func (j *Job) MarshalID() string
- func (j *Job) Organizations() []string
- func (j *Job) String() string
- func (j *Job) UnmarshalID(id string) error
- type JobSpec
- type JobStatus
- type Pool
- type Service
- type ServiceOptions
Constants ¶
const ( AgentTokenKind tokens.Kind = "agent_token" JobTokenKind tokens.Kind = "job_token" )
const AllocatorLockID int64 = 5577006791947779412
AllocatorLockID guarantees only one allocator on a cluster is running at any time.
const DefaultConcurrency = 5
const ManagerLockID int64 = 5577006791947779413
ManagerLockID guarantees only one manager on a cluster is running at any time.
Variables ¶
var ( ErrInvalidAgentStateTransition = errors.New("invalid agent state transition") )
var ( PluginCacheDir = filepath.Join(os.TempDir(), "plugin-cache") DefaultEnvs = []string{ "TF_IN_AUTOMATION=true", "CHECKPOINT_DISABLE=true", } )
var ( ErrInvalidJobStateTransition = errors.New("invalid job state transition") ErrMalformedJobSpecString = errors.New("malformed stringified job spec") )
var ( ErrCannotDeletePoolReferencedByWorkspaces = errors.New("agent pool is still being used by workspaces in your organization. You must switch your workspaces to a different agent pool or execution mode before you can delete this agent pool") ErrWorkspaceNotAllowedToUsePool = errors.New("access to this agent pool is not allowed - you must explictly grant access to the workspace first") ErrPoolAssignedWorkspacesNotAllowed = errors.New("workspaces assigned to the pool have not been granted access to the pool") )
Functions ¶
func NewRPC ¶ added in v0.2.0
NewRPC constructs a agent daemon that communicates with the server via RPC.
func NewRPCClient ¶ added in v0.2.0
NewRPCClient constructs a client that uses RPC to call OTF services. The agentID is added as an HTTP header to requests, allowing the server to identify the client; if nil then it is automatically added once the client successfully registers the agent.
func NewService ¶ added in v0.2.0
func NewService(opts ServiceOptions) *service
Types ¶
type Agent ¶ added in v0.2.0
type Agent struct {
// Unique system-wide ID
ID string `jsonapi:"primary,agents"`
// Optional name
Name string `jsonapi:"attribute" json:"name"`
// Version of agent
Version string `jsonapi:"attribute" json:"version"`
// Current status of agent
Status AgentStatus `jsonapi:"attribute" json:"status"`
// Max number of jobs agent can execute
MaxJobs int `jsonapi:"attribute" json:"max_jobs"`
// Current number of jobs allocated to agent.
CurrentJobs int `jsonapi:"attribute" json:"current_jobs"`
// Last time a ping was received from the agent
LastPingAt time.Time `jsonapi:"attribute" json:"last-ping-at"`
// Last time the status was updated
LastStatusAt time.Time `jsonapi:"attribute" json:"last-status-at"`
// IP address of agent
IPAddress net.IP `jsonapi:"attribute" json:"ip-address"`
// ID of agent' pool. If nil then the agent is assumed to be a server agent
// (otfd).
AgentPoolID *string `jsonapi:"attribute" json:"agent-pool-id"`
}
Agent describes an agent. (The agent *process* is Daemon).
type AgentService ¶ added in v0.2.0
type AgentService = Service
type AgentStatus ¶ added in v0.2.0
type AgentStatus string
const ( AgentIdle AgentStatus = "idle" AgentBusy AgentStatus = "busy" AgentExited AgentStatus = "exited" AgentErrored AgentStatus = "errored" AgentUnknown AgentStatus = "unknown" )
type Config ¶
type Config struct {
Name string // descriptive name for agent
Concurrency int // number of jobs the agent can execute at any one time
Sandbox bool // isolate privileged ops within sandbox
Debug bool // toggle debug mode
PluginCache bool // toggle use of terraform's shared plugin cache
TerraformBinDir string // destination directory for terraform binaries
// contains filtered or unexported fields
}
Config is configuration for an agent daemon
func NewConfigFromFlags ¶
type CreateAgentPoolOptions ¶ added in v0.2.0
type CreateAgentTokenOptions ¶ added in v0.2.0
type CreateAgentTokenOptions struct {
Description string `json:"description" schema:"description,required"`
}
type InProcClient ¶ added in v0.2.0
type InProcClient struct {
tokens.TokensService
variable.VariableService
state.StateService
internal.HostnameService
configversion.ConfigurationVersionService
run.RunService
workspace.WorkspaceService
logs.LogsService
Service
}
InProcClient is a client for in-process communication with the server.
type Job ¶ added in v0.2.0
type Job struct {
// Spec uniquely identifies the job, identifying the corresponding run
// phase.
Spec JobSpec `jsonapi:"primary,jobs"`
// Current status of job.
Status JobStatus `jsonapi:"attribute" json:"status"`
// ID of agent pool the job's workspace is assigned to use. If non-nil then
// the job is allocated to a pool agent belonging to the pool. If nil then
// the job is allocated to a server agent.
AgentPoolID *string `jsonapi:"attribute" json:"agent_pool_id"`
// Name of job's organization
Organization string `jsonapi:"attribute" json:"organization"`
// ID of job's workspace
WorkspaceID string `jsonapi:"attribute" json:"workspace_id"`
// ID of agent that this job is allocated to. Only set once job enters
// JobAllocated state.
AgentID *string `jsonapi:"attribute" json:"agent_id"`
// Signaled is non-nil when a cancelation signal has been sent to the job
// and it is true when it has been forceably canceled.
Signaled *bool `jsonapi:"attribute" json:"signaled"`
}
Job is the unit of work corresponding to a run phase. A job is allocated to an Agent, which then executes the work through to completion.
func (*Job) CanAccessOrganization ¶ added in v0.2.0
func (*Job) CanAccessWorkspace ¶ added in v0.2.0
func (*Job) IsSiteAdmin ¶ added in v0.2.0
func (*Job) Organizations ¶ added in v0.2.0
func (*Job) UnmarshalID ¶ added in v0.2.0
type JobSpec ¶ added in v0.2.0
type JobSpec struct {
// ID of the run that this job is for.
RunID string `json:"run_id"`
// Phase of run that this job is for.
Phase internal.PhaseType `json:"phase"`
}
JobSpec uniquely identifies a job.
type Pool ¶ added in v0.2.0
type Pool struct {
// Unique system-wide ID
ID string
Name string
CreatedAt time.Time
// Pool belongs to an organization with this name.
Organization string
// Whether pool of agents is accessible to all workspaces in organization
// (true) or only those specified in AllowedWorkspaces (false).
OrganizationScoped bool
// IDs of workspaces allowed to access pool. Ignored if OrganizationScoped
// is true.
AllowedWorkspaces []string
// IDs of workspaces assigned to the pool. Note: this is a subset of
// AllowedWorkspaces.
AssignedWorkspaces []string
}
Pool is a group of non-server agents sharing one or more tokens, assigned to an organization or particular workspaces within the organization.
type Service ¶ added in v0.2.0
type Service interface {
NewAllocator(logr.Logger) *allocator
NewManager() *manager
CreateAgentPool(ctx context.Context, opts CreateAgentPoolOptions) (*Pool, error)
GetAgentPool(ctx context.Context, poolID string) (*Pool, error)
WatchAgentPools(context.Context) (<-chan pubsub.Event[*Pool], func())
WatchAgents(context.Context) (<-chan pubsub.Event[*Agent], func())
CreateAgentToken(ctx context.Context, poolID string, opts CreateAgentTokenOptions) (*agentToken, []byte, error)
GetAgentToken(ctx context.Context, tokenID string) (*agentToken, error)
ListAgentTokens(ctx context.Context, poolID string) ([]*agentToken, error)
DeleteAgentToken(ctx context.Context, tokenID string) (*agentToken, error)
WatchJobs(context.Context) (<-chan pubsub.Event[*Job], func())
// contains filtered or unexported methods
}