Documentation
¶
Overview ¶
Package agent is the endpoint group for the agents of the fleet: the agents that report, and the actions on one agent. Admitting an agent is the admission group. Its spec part comes from this definition; until the group moves, the controller serves the hand-written spec in internal/controller/api/agent, and TestEndpointParity holds the two together.
Package agent is the endpoint group for the agents of the fleet: the agents that report, and the actions on one agent. Admitting an agent is the admission group. Its spec part comes from this definition; until the group moves, the controller serves the hand-written spec in internal/controller/api/agent, and TestEndpointParity holds the two together.
Index ¶
- Variables
- func Drain(ctx context.Context, d Deps, in DrainInput) (struct{}, error)
- func Undrain(ctx context.Context, d Deps, in UndrainInput) (struct{}, error)
- type Admissions
- type ConfigGetInput
- type ConfigRequest
- type ConfigResponse
- type ConfigSetInput
- type Deps
- type DrainInput
- type FactKeyEntry
- type FactKeysResponse
- type FactsInput
- type GetInput
- type Info
- type Jobs
- type JoinInput
- type JoinRequest
- type JoinResponse
- type Joiner
- type ListAgentsResponse
- type ListInput
- type LoadAverageResponse
- type MemoryResponse
- type Message
- type NetworkInterfaceResponse
- type NodeCondition
- type OSInfoResponse
- type RouteResponse
- type TimelineEvent
- type UndrainInput
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is an agent that is not there: not registered, or not // pending. ErrNotFound = errors.New("agent not found") // ErrState is an agent that is already in the state that was asked // for, or cannot go to it. ErrState = errors.New("agent is not in a state that allows it") )
var Group = endpoint.Register(endpoint.Define( "agent", "Manage the agents in the fleet: discovery, drain and PKI enrollment", endpoint.Area(area.Fleet), endpoint.CommandLong( "Most commands read the NATS KV heartbeat registry directly, and make no job.", ), endpoint.SubDoc("facts", "Read the keys of @fact references"), endpoint.SubDoc("config", "Read and set the config that the controller gives an agent"), endpoint.Title("Agent Management API"), endpoint.Tag("agent_operations", "Agent", "Operations related to agent discovery and details."), endpoint.Uses[Deps](), endpoint.Doc[types.AgentState]( "The scheduling state of an agent: Ready, Draining, Cordoned or Pending. A drain that the agent has not applied yet is Draining.", ), endpoint.Doc[types.ConditionType]("A condition that an agent or a component evaluates."), endpoint.Doc[LoadAverageResponse]("The system load averages for 1, 5, and 15 minutes."), endpoint.Doc[MemoryResponse]("Memory usage information."), endpoint.Doc[OSInfoResponse]("Operating system information."), endpoint.Doc[RouteResponse]("A network routing table entry."), endpoint.Get[FactsInput, FactKeysResponse]("facts"). Handle(Facts). Sub("facts"). Use("list"). ID("GetAgentFacts"). Permission(types.PermAgentRead). Describe("List the fact keys"). Explain("Returns the fact keys that an input can refer to as @fact.<key>: the "+ "built-in keys and the custom keys that agents register."). Returns("The fact keys."). Command("List the fact keys", "Lists each fact key that an input can refer to as @fact.<key>, with\n"+ "its description."). Example(""). Prints(sampleFacts). Example("--json"), endpoint.Get[ListInput, ListAgentsResponse]("list"). Notes("The `--json` output has more system facts that the agent collects:\n"+ "architecture, kernel version, FQDN, CPU count, network interfaces, service\n"+ "manager and package manager. The table view does not show these fields."). Command("List active agents", "This command reads the agent heartbeat registry directly. It makes no job.\nEach agent writes a heartbeat every 10 seconds, with a 30-second TTL. When\nan agent stops its heartbeat, it goes from the list."). Example(""). Prints(sampleList). Handle(List). ID("GetAgents"). Describe("List active agents"). Explain("Discover all active agents in the fleet."). Returns("List of active agents."), endpoint.Get[GetInput, Info]("get"). Fails("a hostname over 255 characters", GetInput{Hostname: long}). Command("Get agent details", "This command reads the agent heartbeat registry directly. It makes no job.\nThe data comes from the last heartbeat of the agent. `node status` runs a\nfull inspection through the job system, with disk usage and more metrics."). Example("--hostname web-01"). Prints(sampleWeb01). Handle(Get). ID("GetAgentDetails"). Describe("Get agent details"). Explain("Get detailed information about a specific agent by hostname."). Returns("Agent details."). Errors(endpoint.NotFound(ErrNotFound, "Agent not found")), endpoint.Post[JoinInput, JoinResponse]("join"). Handle(Join). Sub("join"). ID("JoinAgent"). Public(). NoCommand(). Describe("Join an agent with a join token"). Explain("An agent calls it one time, at its first start, over HTTPS, after it checks "+ "the controller's certificate against the fingerprint of its join string. A token "+ "that admits admits the machine at once, as admit does, and the admission record "+ "names the token. The request is signed with the agent's signing key, which shows "+ "that it holds the key that it asks the controller to admit. It needs no bearer "+ "token: the join token authorizes it."). Returns("The machine is admitted."). Fails("no token", joinWith(func(r *JoinRequest) { r.Token = "" })). Fails("a token over 256 characters", joinWith(func(r *JoinRequest) { r.Token = secret.Value(strings.Repeat("a", 257)) })). Fails("no machine ID", joinWith(func(r *JoinRequest) { r.MachineID = "" })). Fails("a machine ID over 255 characters", joinWith(func(r *JoinRequest) { r.MachineID = long })). Fails("no hostname", joinWith(func(r *JoinRequest) { r.Hostname = "" })). Fails("a hostname over 255 characters", joinWith(func(r *JoinRequest) { r.Hostname = long })). Fails("no public key", joinWith(func(r *JoinRequest) { r.PublicKey = "" })). Fails("a public key over 128 characters", joinWith(func(r *JoinRequest) { r.PublicKey = strings.Repeat("a", 132) })). Fails("a public key that is not base64", joinWith(func(r *JoinRequest) { r.PublicKey = "not base64!" })). Fails("no encryption key", joinWith(func(r *JoinRequest) { r.EncryptionKey = "" })). Fails("an encryption key over 128 characters", joinWith(func(r *JoinRequest) { r.EncryptionKey = strings.Repeat("a", 129) })). Fails("no signature", joinWith(func(r *JoinRequest) { r.Signature = "" })). Fails("a signature over 256 characters", joinWith(func(r *JoinRequest) { r.Signature = strings.Repeat("a", 260) })). Fails("a signature that is not base64", joinWith(func(r *JoinRequest) { r.Signature = "not base64!" })). Errors( endpoint.Forbidden(jointoken.ErrInvalid, "The token is not one the controller has, or it was revoked."), endpoint.Forbidden(jointoken.ErrExpired, "The token has expired."), endpoint.Forbidden(jointoken.ErrUsed, "The token has no use left."), endpoint.Forbidden(admission.ErrJoinSignature, "The request is not signed by the key that it asks to admit."), endpoint.Invalid(admission.ErrJoinEncryptionKey, "The encryption key is not a public P-256 key. An agent with an older key makes a new one and joins again."), endpoint.Unavailable(admission.ErrNoJoinTokens, "This controller takes no join."), ), endpoint.Post[DrainInput, struct{}]("drain"). AdminOnly(). Fails("a hostname over 255 characters", DrainInput{Hostname: long}). Status(http.StatusNoContent). Command("Drain an agent", "The agent changes from `Ready` to `Draining`. When all its running jobs are\ncomplete, the state is `Cordoned`. The agent continues to run and to send\nheartbeats. It only stops the intake of new work from the job queue. Use\n`agent undrain` to accept jobs again. The jobs that it runs now continue\nuntil they are complete."). Example("--hostname web-01"). Check("client agent get", "--hostname web-01", "state", command.OneOf(types.AgentDraining, types.AgentCordoned)). Handle(Drain). Action("drain"). Says("draining"). ID("DrainAgent"). Describe("Drain an agent"). Explain("Stop the agent from accepting new jobs. In-flight jobs continue to "+ "completion."). Returns("Agent drain initiated."). Errors( endpoint.NotFound(ErrNotFound, "Agent not found."), endpoint.Conflict(ErrState, "Agent already in requested state."), ), endpoint.Get[ConfigGetInput, ConfigResponse]("getconfig"). Handle(GetConfig). Sub("config"). Use("get"). ID("GetAgentConfig"). Permission(types.PermAgentRead). Describe("Read the config of an agent"). Explain("Returns the config that the controller holds for the agent, with its version."). Returns("The config of the agent."). Command("Read the config of an agent", "Shows the labels that the controller gives the agent, and the version of\n"+ "the config. The agent applies each version at once."). Example("--hostname web-01"). Prints(sampleConfig). Fails("a hostname over 255 characters", ConfigGetInput{Hostname: long}). Errors(endpoint.NotFound(ErrNotFound, "Agent not found.")), endpoint.Put[ConfigSetInput, ConfigResponse]("setconfig"). Handle(SetConfig). Sub("config"). Use("update"). ID("PutAgentConfig"). AdminOnly(). Describe("Set the config of an agent"). Explain("Sets the labels, the max jobs, the log level and the facts interval of the agent "+ "as the next version of its config. The agent applies them at once: it takes the jobs of the "+ "new labels, runs at most max jobs at the same time, logs at the level, collects "+ "its facts at the interval, and no restart is necessary."). Returns("The config of the agent after the change."). Command("Set the labels, the max jobs, the log level and the facts interval of an agent", "The labels replace the labels of the agent's config file with the same\n"+ "keys. Max jobs replaces its max_jobs, the log level the level of its debug\n"+ "setting, and the facts interval its agent.facts.interval; with none, the\n"+ "agent keeps the file's. The agent\n"+ "applies them at once, with no restart. A host that joins with a join\n"+ "token gets the labels of the token."). Example("--hostname web-01 --labels group=web --labels dc=east --max-jobs 4 --log-level debug --facts-interval 5m"). Prints(sampleConfig). Check("client agent config get", "--hostname web-01", "labels.group", "web", "labels.dc", "east", "max_jobs", 4, "log_level", "debug", "facts_interval", "5m"). Check("client agent get", "--hostname web-01", "labels.group", "web", "labels.dc", "east", "config_behind", command.Absent). Fails("a hostname over 255 characters", ConfigSetInput{Hostname: long}). Fails("max jobs below 1", ConfigSetInput{ Hostname: "web-01", Body: ConfigRequest{MaxJobs: -1}, }). Fails("max jobs over 1000", ConfigSetInput{ Hostname: "web-01", Body: ConfigRequest{MaxJobs: 1001}, }). Fails("a facts interval that is not a Go duration", ConfigSetInput{ Hostname: "web-01", Body: ConfigRequest{FactsInterval: "7d"}, }). Fails("a log level that is not one", ConfigSetInput{ Hostname: "web-01", Body: ConfigRequest{LogLevel: types.LogLevel("verbose")}, }). Errors(endpoint.NotFound(ErrNotFound, "Agent not found.")), endpoint.Post[UndrainInput, struct{}]("undrain"). AdminOnly(). Fails("a hostname over 255 characters", UndrainInput{Hostname: long}). Status(http.StatusNoContent). Command("Undrain an agent", "The agent subscribes to the NATS JetStream consumers again and changes back\nto `Ready`."). Example("--hostname web-01"). Check("client agent get", "--hostname web-01", "state", types.AgentReady). Handle(Undrain). Action("undrain"). Says("ready"). ID("UndrainAgent"). Describe("Undrain an agent"). Explain("Resume accepting jobs on a drained agent."). Returns("Agent undrain initiated."). Errors( endpoint.NotFound(ErrNotFound, "Agent not found."), endpoint.Conflict(ErrState, "Agent not in draining or cordoned state."), ), ))
Group is the agent group's definition.
Functions ¶
Types ¶
type Admissions ¶
Admissions reads the admission record of a machine.
type ConfigGetInput ¶
type ConfigGetInput struct {
Hostname string `json:"hostname" in:"path" validate:"required,min=1,max=255" doc:"The hostname of the agent."`
}
ConfigGetInput names the agent whose config is read.
type ConfigRequest ¶
type ConfigRequest struct {
Labels map[string]string `` /* 203-byte string literal not displayed */
MaxJobs int `` /* 198-byte string literal not displayed */
LogLevel types.LogLevel `` /* 185-byte string literal not displayed */
FactsInterval string `` /* 195-byte string literal not displayed */
// contains filtered or unexported fields
}
ConfigRequest is the config that the controller gives an agent.
type ConfigResponse ¶
type ConfigResponse struct {
Version int `` /* 136-byte string literal not displayed */
Labels map[string]string `` /* 135-byte string literal not displayed */
MaxJobs int `` /* 193-byte string literal not displayed */
LogLevel types.LogLevel `` /* 194-byte string literal not displayed */
FactsInterval string `` /* 199-byte string literal not displayed */
UpdatedAt *time.Time `` /* 213-byte string literal not displayed */
// contains filtered or unexported fields
}
ConfigResponse is the config that the controller holds for an agent.
func GetConfig ¶
func GetConfig( ctx context.Context, d Deps, in ConfigGetInput, ) (ConfigResponse, error)
GetConfig is the config that the controller holds for the agent.
func SetConfig ¶
func SetConfig( ctx context.Context, d Deps, in ConfigSetInput, ) (ConfigResponse, error)
SetConfig sets the labels, the max jobs and the log level of the agent, as the next version of its config. The agent applies them at once, and writes it to its timeline.
type ConfigSetInput ¶
type ConfigSetInput struct {
Hostname string `json:"hostname" in:"path" validate:"required,min=1,max=255" doc:"The hostname of the agent."`
Body ConfigRequest `json:"body" in:"body" validate:"required"`
}
ConfigSetInput names the agent and the labels of its config.
type Deps ¶
type Deps struct {
// Jobs reads the registry and writes the drain flag and the timeline.
Jobs Jobs
// Joiner admits an agent that joins with a token. Nil on a controller
// that takes no join.
Joiner Joiner
// Admissions are the admission records, which say the keys that the
// controller admitted for each machine. Nil checks no keys.
Admissions Admissions
}
Deps is what the agent group's handlers use. The controller gives it at startup; a test gives fakes.
type DrainInput ¶
type DrainInput struct {
Hostname string `json:"hostname" in:"path" validate:"required,min=1,max=255" doc:"The hostname of the agent to drain."`
}
DrainInput names the agent to drain.
type FactKeyEntry ¶
type FactKeyEntry struct {
Key string `json:"key" doc:"The fact key, such as 'interface.primary'." label:"Reference" prefix:"@fact."`
Description string `json:"description,omitempty" doc:"Human-readable description of the fact."`
Builtin bool `json:"builtin,omitempty" doc:"Whether this is a built-in fact key." render:"-"`
}
FactKeyEntry is one fact key.
type FactKeysResponse ¶
type FactKeysResponse struct {
Items []FactKeyEntry ` json:"items" doc:"Available fact keys for @fact. references."`
TotalItems int ` json:"total_items" doc:"Total number of fact keys."`
// contains filtered or unexported fields
}
FactKeysResponse is each fact key.
func Facts ¶
func Facts( _ context.Context, _ Deps, _ FactsInput, ) (FactKeysResponse, error)
Facts is each built-in fact key that an input can refer to as @fact.<key>, with its description.
type GetInput ¶
type GetInput struct {
Hostname string `json:"hostname" in:"path" validate:"required,min=1,max=255" doc:"The hostname of the agent to retrieve."`
}
GetInput names the agent to read.
type Info ¶
type Info struct {
Hostname string `json:"hostname" doc:"The hostname of the agent."`
MachineID string `json:"machine_id,omitempty" doc:"The permanent machine identifier."`
State types.AgentState `` /* 280-byte string literal not displayed */
Conditions []NodeCondition `` /* 289-byte string literal not displayed */
Labels map[string]string `json:"labels,omitempty" doc:"Key-value labels configured on the agent."`
StartedAt time.Time `` /* 301-byte string literal not displayed */
LoadAverage *LoadAverageResponse `` /* 302-byte string literal not displayed */
OSInfo *OSInfoResponse `` /* 300-byte string literal not displayed */
Version string `` /* 334-byte string literal not displayed */
ConfigVersion int `` /* 329-byte string literal not displayed */
ConfigWanted int `` /* 329-byte string literal not displayed */
ConfigBehind bool `` /* 205-byte string literal not displayed */
Fingerprint string `` /* 356-byte string literal not displayed */
ControllerKey string `` /* 356-byte string literal not displayed */
ControllerKeyNext string `` /* 356-byte string literal not displayed */
NATSCertNext string `` /* 356-byte string literal not displayed */
RegisteredAt time.Time `` /* 356-byte string literal not displayed */
Uptime string `` /* 356-byte string literal not displayed */
Memory *MemoryResponse `` /* 356-byte string literal not displayed */
Architecture string `` /* 356-byte string literal not displayed */
KernelVersion string `` /* 356-byte string literal not displayed */
CPUCount int `` /* 356-byte string literal not displayed */
FQDN string `` /* 356-byte string literal not displayed */
ServiceMgr string `` /* 356-byte string literal not displayed */
PackageMgr string `` /* 356-byte string literal not displayed */
PrimaryInterface string `` /* 356-byte string literal not displayed */
Interfaces []NetworkInterfaceResponse `` /* 356-byte string literal not displayed */
Routes []RouteResponse `` /* 356-byte string literal not displayed */
MissingPrograms []string `` /* 314-byte string literal not displayed */
Facts map[string]any `` /* 275-byte string literal not displayed */
Timeline []TimelineEvent `` /* 356-byte string literal not displayed */
KeyStored *bool `` /* 275-byte string literal not displayed */
Verified *bool `` /* 275-byte string literal not displayed */
// contains filtered or unexported fields
}
Info is one agent: its identity, its host's facts and its state. The spec names its schema for the type, so the name stays Info, as the hand-written spec and the clients made from it have it.
type Jobs ¶
type Jobs interface {
ListAgents(ctx context.Context) ([]job.AgentInfo, error)
GetAgent(ctx context.Context, hostname string) (*job.AgentInfo, error)
SetDrainFlag(ctx context.Context, hostname string) error
DeleteDrainFlag(ctx context.Context, hostname string) error
WriteAgentTimelineEvent(ctx context.Context, machineID, hostname, event, message string) error
GetAgentConfig(ctx context.Context, machineID string) (job.AgentConfig, error)
SetAgentConfig(
ctx context.Context,
machineID string,
set job.AgentConfig,
) (job.AgentConfig, error)
}
Jobs is the part of the job client the agent group uses.
type JoinInput ¶
type JoinInput struct {
Body JoinRequest `in:"body" validate:"required"`
}
JoinInput is an agent's join: its request, in the body.
type JoinRequest ¶
type JoinRequest struct {
Token secret.Value `` /* 159-byte string literal not displayed */
MachineID string `json:"machine_id" validate:"required,min=1,max=255" doc:"The machine ID of the host."`
Hostname string `json:"hostname" validate:"required,min=1,max=255" doc:"The hostname of the host."`
PublicKey string `json:"public_key" validate:"required,max=128,base64" doc:"The agent's Ed25519 signing key, in base64."`
EncryptionKey string `` /* 182-byte string literal not displayed */
Signature string `` /* 138-byte string literal not displayed */
}
JoinRequest is what an agent sends to join: the join token, who it is, its two public keys, and its signature over them with its signing key.
type JoinResponse ¶
type JoinResponse struct {
ControllerPublicKey string `` /* 143-byte string literal not displayed */
// contains filtered or unexported fields
}
JoinResponse is the controller's answer to a join that admits.
type Joiner ¶
Joiner admits the machine of a join request whose token admits, and returns the controller's public key.
type ListAgentsResponse ¶
type ListAgentsResponse struct {
Items []Info `json:"items" doc:"The active agents." empty:"An agent appears here once it starts and connects."`
TotalItems int `json:"total_items" doc:"Total number of active agents."`
}
ListAgentsResponse is the agents that report.
type LoadAverageResponse ¶
type LoadAverageResponse struct {
OneMin float32 `json:"1min" doc:"Load average for the last 1 minute." example:"0.32" label:"1 min"`
FiveMin float32 `json:"5min" doc:"Load average for the last 5 minutes." example:"0.28" label:"5 min"`
FifteenMin float32 `json:"15min" doc:"Load average for the last 15 minutes." example:"0.25" label:"15 min"`
}
LoadAverageResponse is the host's load over 1, 5 and 15 minutes.
type MemoryResponse ¶
type MemoryResponse struct {
Total int `json:"total" doc:"Total memory in bytes." example:"8388608" render:"bytes"`
Free int `json:"free" doc:"Free memory in bytes." example:"2097152" render:"bytes"`
Used int `json:"used" doc:"Used memory in bytes." example:"4194304" render:"bytes"`
}
MemoryResponse is the host's memory, in bytes.
type Message ¶
type Message = struct {
Message string `json:"message"`
}
Message is the answer of an action: a sentence that says what occurred. It is an alias of a struct with no name, so the spec has it in place, as the hand-written spec does.
type NetworkInterfaceResponse ¶
type NetworkInterfaceResponse struct {
Name string `json:"name" example:"eth0"`
IPv4 string `json:"ipv4,omitempty" example:"192.168.1.10"`
IPv6 string `json:"ipv6,omitempty" example:"fe80::1"`
MAC string `json:"mac,omitempty" example:"00:11:22:33:44:55"`
Family types.AddressFamily `json:"family,omitempty" example:"dual" doc:"IP address family." validate:"enum"`
}
NetworkInterfaceResponse is one network interface of the host.
type NodeCondition ¶
type NodeCondition struct {
Type types.ConditionType `json:"type"`
Reason string `json:"reason,omitempty"`
LastTransitionTime time.Time `json:"last_transition_time" label:"Since" render:"age"`
}
NodeCondition is a condition the controller evaluated for the host.
type OSInfoResponse ¶
type OSInfoResponse struct {
Distribution string `` /* 214-byte string literal not displayed */
Version string `` /* 213-byte string literal not displayed */
Family string `` /* 214-byte string literal not displayed */
}
OSInfoResponse is the host's operating system.
type RouteResponse ¶
type RouteResponse struct {
Destination string `json:"destination" doc:"Destination network address." example:"0.0.0.0"`
Gateway string `json:"gateway" doc:"Gateway address." example:"192.168.1.1"`
Interface string `json:"interface" doc:"Network interface name." example:"eth0"`
Mask string `json:"mask,omitempty" doc:"Network mask in CIDR notation." example:"/0"`
Metric int `json:"metric,omitempty" doc:"Route metric." example:"100"`
}
RouteResponse is one entry of the host's routing table.
type TimelineEvent ¶
type TimelineEvent struct {
Timestamp time.Time `json:"timestamp"`
Event string `json:"event"`
Hostname string `json:"hostname,omitempty"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
}
TimelineEvent is one change of the agent's state.
type UndrainInput ¶
type UndrainInput struct {
Hostname string `json:"hostname" in:"path" validate:"required,min=1,max=255" doc:"The hostname of the agent to undrain."`
}
UndrainInput names the agent to undrain.