Documentation
¶
Overview ¶
Package fleet is the CLI's client of the manager's IAM-authorized API: the lookup of the API by name, the SigV4-signed calls, and what the routers and workloads commands build on them. The estimate never imports it (importguard_test.go).
Index ¶
- Variables
- func ParseTags(values []string) (map[string]string, error)
- func Plural(n int, word string) string
- func RoutersSummary(rs []Router, available string) string
- func RoutersTable(rs []Router, available string) string
- func WorkloadsSummary(w Workloads) string
- func WorkloadsTable(ws []Workload, now time.Time) string
- type APIError
- type Client
- func (c *Client) Delete(ctx context.Context, path string, out any) error
- func (c *Client) Get(ctx context.Context, path string, query url.Values, out any) error
- func (c *Client) Post(ctx context.Context, path string, body, out any) error
- func (c *Client) Put(ctx context.Context, path string, body, out any) error
- type Event
- type Health
- type Locator
- type OpRef
- type Operation
- type OperationStep
- type Operations
- type Outcome
- type Plan
- type Result
- type Router
- type RouterError
- type Routers
- type Selection
- type Skip
- type Step
- type Target
- type UpgradeOptions
- type Workload
- type Workloads
Constants ¶
This section is empty.
Variables ¶
var ErrNoAPI = errors.New("no manager API found")
ErrNoAPI is the lookup's answer when no API has the manager's name in the region.
var ErrNotSent = errors.New("not started")
ErrNotSent marks an error from before the request left: the credentials or the signature failed, nothing reached the manager.
Functions ¶
func ParseTags ¶
ParseTags reads --tag values, key=value: the value may hold "=" but no comma (API Gateway joins repeated parameters with commas and the manager splits them there), and a key is given once.
func RoutersSummary ¶
RoutersSummary is the line under the table: the version available and how many of rs are below it.
func RoutersTable ¶
RoutersTable is the routers list: the version as "from → to" when below the one available, "upgrading" while an upgrade runs, "?" when unknown; the workloads as their total and their count per state.
func WorkloadsSummary ¶
WorkloadsSummary is the line under the table: the total, with the count per state of the rows listed when they are all there. The manager's byState counts every workload the caller sees, whatever the filters, so it is not used.
Types ¶
type APIError ¶
type APIError struct {
Status int
Code, Message string
Gateway bool
// contains filtered or unexported fields
}
APIError is a refusal from API Gateway (Gateway) or from the manager (Code and Message).
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the manager's /iam routes, signing each request with SigV4 for execute-api.
func New ¶
func New(httpClient *http.Client, baseURL, region string, creds aws.CredentialsProvider, now func() time.Time) *Client
New is a Client of the API at baseURL (no trailing path), signing for region with creds; the timeout is httpClient's.
func (*Client) Delete ¶ added in v0.5.0
Delete calls DELETE /iam<path> and decodes the answer into out (nil to ignore it); never retried.
func (*Client) Get ¶
Get calls GET /iam<path>?query and decodes the JSON answer into out (nil to ignore it).
type Health ¶
type Health struct {
Status string `json:"status"`
}
Health is a router's health as the manager reports it ("" when unknown).
type Locator ¶
Locator finds the manager's API endpoint of an environment.
func NewLocator ¶
NewLocator is the Locator over API Gateway in cfg's region, with the standard retryer (5 attempts).
type Operation ¶
type Operation struct {
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status"` // running, succeeded or failed
Steps []OperationStep `json:"steps"`
}
Operation is the manager's operation, as far as the upgrade reads it.
type OperationStep ¶
type OperationStep struct {
Name string `json:"name"`
Status string `json:"status"`
Detail string `json:"detail,omitempty"`
}
OperationStep is one step of an operation: pending, running, done, skipped or failed.
type Operations ¶
type Operations interface {
Start(ctx context.Context, router string) (Operation, error)
Get(ctx context.Context, id string) (Operation, error)
}
Operations starts and reads the manager's operations.
func NewOperations ¶
func NewOperations(c *Client) Operations
NewOperations is the manager's operations through c: POST /operations, GET /operations/<id>.
type Outcome ¶
type Outcome struct {
Router string `json:"router"`
From string `json:"from"`
To string `json:"to"`
Operation string `json:"operation,omitempty"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
Duration time.Duration `json:"-"`
}
Outcome is what became of an upgrade. Status: succeeded, failed (it did not start, or ended failed), running (the run stopped following it), unknown (the operation could not be read) or "not started" (the run stopped first).
type Plan ¶
Plan is what an upgrade does to the routers selected.
func PlanUpgrade ¶
PlanUpgrade decides for each router, in order: written in Terraform, an operation running, its version unknown, up to date, newer than the version available (a pre-release is below its release), else upgraded.
type Result ¶
type Result struct {
Available string `json:"available"`
Upgraded []Outcome `json:"upgraded"`
Skipped []Skip `json:"skipped"`
Stopped bool `json:"-"` // the context ended before every upgrade did
}
Result is what an upgrade run did: the outcome of each router of the plan, in its order, and the routers skipped.
func Upgrade ¶
func Upgrade(ctx context.Context, api Operations, plan Plan, o UpgradeOptions) Result
Upgrade starts the plan's upgrades, at most Concurrency at once, and follows each every Poll until it ends. When ctx ends, it starts no more and stops following: the upgrades started go on in the manager, reported as running.
func (Result) NotStarted ¶
func (Result) Running ¶
Running counts those the run stopped following; NotStarted those it stopped before starting.
func (Result) Summary ¶
Summary counts the outcomes: "2 upgraded, 1 failed, 1 still running, 3 not started" (only those there are).
func (Result) Unfinished ¶
Unfinished counts the upgrades with an operation in the manager whose end the run did not see: they may go on there.
type Router ¶
type Router struct {
Name string `json:"name"`
Account string `json:"account,omitempty"` // absent for a router of the manager's own account written in Terraform
Region string `json:"region"`
Source string `json:"source"` // manager or terraform
Version string `json:"version,omitempty"` // "" when unknown (null)
Health Health `json:"health"`
Workloads int `json:"workloads"`
WorkloadStates map[string]int `json:"workloadStates,omitempty"`
Error string `json:"error,omitempty"` // the router did not answer
Operation *OpRef `json:"operation,omitempty"`
// contains filtered or unexported fields
}
Router is a row of GET /iam/routers: what the CLI reads of it. The row as the API sent it is kept, so --json prints every field, not only these.
func (Router) MarshalJSON ¶
MarshalJSON is the row as the API sent it, or the fields known when it was built here.
func (Router) Outdated ¶
Outdated tells whether the router runs a version below the one available (a pre-release is below its release; an unknown version, or none available, is not outdated).
func (*Router) UnmarshalJSON ¶
type RouterError ¶
RouterError is a router that did not answer the workloads' listing.
type Routers ¶
Routers is the answer of GET /iam/routers: the rows and the version available ("" when the manager names none).
func (Routers) MarshalJSON ¶
MarshalJSON is the API's shape: available is absent when none is named.
func (*Routers) UnmarshalJSON ¶
type Selection ¶
type Selection struct {
Names, Accounts, RouterRegions []string
NameGlob string // *, ? and […] on the router's name
Tags map[string]string
All bool
}
Selection is which routers a command acts on: the names given (upgrade) narrowed by the filters. Accounts and RouterRegions are ORed within each, every filter ANDed with the others; Tags keeps the routers that serve a workload carrying all of them (the caller asks the manager for those workloads and passes their routers to Select).
type Target ¶ added in v0.5.0
type Target struct{ Router, ID string }
Target is a workload as a command names it: <router>/<id>.
func ParseTarget ¶ added in v0.5.0
ParseTarget reads "<router>/<id>": the router's name, then the workload's id (everything after the first slash).
type UpgradeOptions ¶
type UpgradeOptions struct {
Concurrency int // at most this many upgrades run at once
Poll time.Duration
Sleep func(context.Context, time.Duration) error // ends with the context's error when it is done
Now func() time.Time
Progress func(Event) // called one at a time
}
UpgradeOptions are how Upgrade runs; Sleep and Now are injected so that tests need no real time.
type Workload ¶
type Workload struct {
WorkloadID string `json:"workloadId"`
Name string `json:"name,omitempty"`
Router string `json:"router"`
Account string `json:"account,omitempty"`
Region string `json:"region,omitempty"`
State string `json:"state"`
Tags map[string]string `json:"tags,omitempty"`
StateAt string `json:"stateAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
Scheduled bool `json:"scheduled,omitempty"` // a schedule is set (manager 0.16.0)
}
Workload is a row of GET /iam/workloads. StateAt is when its state began; UpdatedAt the last change of any kind.
type Workloads ¶
type Workloads struct {
Rows []Workload `json:"workloads"`
Total int `json:"total"`
ByState map[string]int `json:"byState,omitempty"`
Cursor json.RawMessage `json:"cursor,omitempty"` // null when the listing is complete
Errors []RouterError `json:"errors,omitempty"`
}
Workloads is the answer of GET /iam/workloads.