Documentation ¶
Overview ¶
Package agent contains code related to agents
Package agent contains code related to agents
Index ¶
- Constants
- Variables
- func NewAgentsCommand(apiClient *otfapi.Client) *cobra.Command
- func NewPoolDaemon(logger logr.Logger, cfg Config, apiConfig otfapi.Config) (*daemon, error)
- func NewServerDaemon(logger logr.Logger, cfg Config, opts ServerDaemonOptions) (*daemon, error)
- type Agent
- type AgentStatus
- type Config
- type CreateAgentPoolOptions
- type CreateAgentTokenOptions
- type DaemonOptions
- 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 ServerDaemonOptions
- type Service
- func (s *Service) AddHandlers(r *mux.Router)
- func (s *Service) CreateAgentPool(ctx context.Context, opts CreateAgentPoolOptions) (*Pool, error)
- func (s *Service) CreateAgentToken(ctx context.Context, poolID string, opts CreateAgentTokenOptions) (*agentToken, []byte, error)
- func (s *Service) DeleteAgentToken(ctx context.Context, tokenID string) (*agentToken, error)
- func (s *Service) GetAgentPool(ctx context.Context, poolID string) (*Pool, error)
- func (s *Service) GetAgentToken(ctx context.Context, tokenID string) (*agentToken, error)
- func (s *Service) ListAgentTokens(ctx context.Context, poolID string) ([]*agentToken, error)
- func (f Service) NewAgentToken(poolID string, opts CreateAgentTokenOptions) (*agentToken, []byte, error)
- func (s *Service) NewAllocator(logger logr.Logger) *allocator
- func (s *Service) NewManager() *manager
- func (s *Service) WatchAgentPools(ctx context.Context) (<-chan pubsub.Event[*Pool], func())
- func (s *Service) WatchAgents(ctx context.Context) (<-chan pubsub.Event[*Agent], func())
- func (s *Service) WatchJobs(ctx context.Context) (<-chan pubsub.Event[*Job], func())
- 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 NewAgentsCommand ¶ added in v0.2.0
func NewPoolDaemon ¶ added in v0.2.2
NewPoolDaemon constructs a pool agent daemon that communicates with the otfd server via RPC.
func NewServerDaemon ¶ added in v0.2.2
func NewServerDaemon(logger logr.Logger, cfg Config, opts ServerDaemonOptions) (*daemon, error)
NewServerDaemon constructs a server agent daemon that is part of the otfd server.
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 netip.Addr `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 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 }
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 DaemonOptions ¶ added in v0.2.2
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 ServerDaemonOptions ¶ added in v0.2.2
type ServerDaemonOptions struct { Logger logr.Logger Config Config RunService *run.Service WorkspaceService *workspace.Service VariableService *variable.Service ConfigurationVersionService *configversion.Service StateService *state.Service LogsService *logs.Service AgentService *Service HostnameService *internal.HostnameService }
type Service ¶ added in v0.2.0
func NewService ¶ added in v0.2.0
func NewService(opts ServiceOptions) *Service
func (*Service) AddHandlers ¶ added in v0.2.2
func (*Service) CreateAgentPool ¶ added in v0.2.0
func (*Service) CreateAgentToken ¶ added in v0.2.0
func (*Service) DeleteAgentToken ¶ added in v0.2.0
func (*Service) GetAgentPool ¶ added in v0.2.0
func (*Service) GetAgentToken ¶ added in v0.2.0
func (*Service) ListAgentTokens ¶ added in v0.2.0
func (Service) NewAgentToken ¶ added in v0.2.2
func (f Service) NewAgentToken(poolID string, opts CreateAgentTokenOptions) (*agentToken, []byte, error)
NewAgentToken constructs a token for an agent, returning both the representation of the token, and the cryptographic token itself.
func (*Service) NewAllocator ¶ added in v0.2.0
func (*Service) NewManager ¶ added in v0.2.0
func (s *Service) NewManager() *manager