fleet

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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.

Functions

func ParseTags

func ParseTags(values []string) (map[string]string, error)

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 Plural

func Plural(n int, word string) string

Plural is word, in the plural unless n is 1.

func RoutersSummary

func RoutersSummary(rs []Router, available string) string

RoutersSummary is the line under the table: the version available and how many of rs are below it.

func RoutersTable

func RoutersTable(rs []Router, available string) string

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

func WorkloadsSummary(w Workloads) string

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.

func WorkloadsTable

func WorkloadsTable(ws []Workload, now time.Time) string

WorkloadsTable is the workloads list: tags as k=v sorted by key, CHANGED the time since the state began (else the last update), as 5m, 3h or 2d.

Types

type APIError

type APIError struct {
	Status        int
	Code, Message string
	Gateway       bool
}

APIError is a refusal from API Gateway (Gateway) or from the manager (Code and Message).

func (*APIError) Error

func (e *APIError) Error() string

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

func (c *Client) Get(ctx context.Context, path string, query url.Values, out any) error

Get calls GET /iam<path>?query and decodes the JSON answer into out (nil to ignore it).

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body, out any) error

Post calls POST /iam<path> with body as JSON (nil for none) and decodes the answer into out; never retried.

type Event

type Event struct {
	Ended bool
	Outcome
}

Event is reported as an upgrade starts and as it ends.

type Health

type Health struct {
	Status string `json:"status"`
}

Health is a router's health as the manager reports it ("" when unknown).

type Locator

type Locator interface {
	APIURL(ctx context.Context, env, region string) (string, error)
}

Locator finds the manager's API endpoint of an environment.

func NewLocator

func NewLocator(cfg aws.Config, region string) Locator

NewLocator is the Locator over API Gateway in region, with the standard retryer (5 attempts).

type OpRef

type OpRef struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

OpRef is the install, upgrade or uninstall running on a router.

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

func (Outcome) Line

func (o Outcome) Line() string

Line is the outcome as printed when it ends: ✓ from → to and its duration, or ✗ the failed step and its detail.

type Plan

type Plan struct {
	Available string
	Upgrade   []Step
	Skipped   []Skip
}

Plan is what an upgrade does to the routers selected.

func PlanUpgrade

func PlanUpgrade(rs []Router, available string) Plan

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.

func (Plan) Text

func (p Plan) Text() string

Text is the plan as printed: the routers to upgrade with from → to, then the skipped ones with their reasons.

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

func (r Result) Failed() int

Failed counts the upgrades that failed or whose operation could not be read.

func (Result) NotStarted

func (r Result) NotStarted() int

func (Result) Running

func (r Result) Running() int

Running counts those the run stopped following; NotStarted those it stopped before starting.

func (Result) Summary

func (r Result) Summary() string

Summary counts the outcomes: "2 upgraded, 1 failed, 1 still running, 3 not started" (only those there are).

func (Result) Unfinished

func (r Result) Unfinished() (n int)

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

func (r Router) MarshalJSON() ([]byte, error)

MarshalJSON is the row as the API sent it, or the fields known when it was built here.

func (Router) Outdated

func (r Router) Outdated(available string) bool

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

func (r *Router) UnmarshalJSON(data []byte) error

type RouterError

type RouterError struct {
	Router  string `json:"router"`
	Message string `json:"message"`
}

RouterError is a router that did not answer the workloads' listing.

type Routers

type Routers struct {
	Rows      []Router
	Available string
}

Routers is the answer of GET /iam/routers: the rows and the version available ("" when the manager names none).

func (Routers) MarshalJSON

func (rs Routers) MarshalJSON() ([]byte, error)

MarshalJSON is the API's shape: available is absent when none is named.

func (*Routers) UnmarshalJSON

func (rs *Routers) UnmarshalJSON(data []byte) error

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

func (Selection) Select

func (s Selection) Select(rs []Router, tagged map[string]bool) ([]Router, error)

Select is the routers of rs the selection keeps, in rs's order, each once (a name given twice, or named and matched by a filter, counts once). tagged is the set of routers serving workloads that carry Tags. A name that is no router's is an error.

func (Selection) Validate

func (s Selection) Validate(forUpgrade bool) error

Validate refuses what cannot be selected. An upgrade must name routers, filter them or take --all, and --all takes neither: an upgrade of everything is never the default of an empty command line.

type Skip

type Skip struct {
	Router string `json:"router"`
	Reason string `json:"reason"`
}

Skip is a router the plan leaves alone, and why.

type Step

type Step struct{ Router, From, To string }

Step is a router the plan upgrades.

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"`
}

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.

func (Workloads) More

func (w Workloads) More() bool

More tells whether the answer is a page of a longer listing.

Jump to

Keyboard shortcuts

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