Documentation
¶
Overview ¶
Package fanout runs one request on many targets at once.
The degree of parallelism is bounded and conservative by default: a connection through a tunnel or a jump host is far more fragile than a local one, and a wide fan-out is what makes sshd refuse connections under its MaxStartups limit.
Index ¶
Constants ¶
const DefaultMax = 16
DefaultMax is used when nothing configures the fan-out.
Variables ¶
var PanicLog io.Writer = os.Stderr
PanicLog is where the stack of a recovered panic is written: the process's standard error, which under clusterctl mcp is the server's log.
Functions ¶
func Recovered ¶ added in v0.3.0
Recovered turns a panic in the work for one target into that target's error, and writes the stack to PanicLog. It is called as Recovered(name, recover()) in a function deferred by the goroutine doing the work, and returns nil when nothing panicked.
recover only stops a panic in its own goroutine, so each worker of a fan-out needs its own; without it, a panic on one target ends the process, and under clusterctl mcp every plan waiting to be applied.
Types ¶
type Executor ¶
type Executor struct {
// Runner performs one request; a Recorder stands in for a dry run.
Runner transport.Runner
// Max is how many targets are worked on at once.
Max int
// OnResult is called as each target finishes, in completion order, for
// progress output. It must be safe to call from several goroutines.
OnResult func(*transport.Result)
}
Executor runs requests on many targets.
func (*Executor) Run ¶
func (e *Executor) Run(ctx context.Context, targets []transport.Target, req transport.Request) []*transport.Result
Run executes the same request on every target.
func (*Executor) RunEach ¶
func (e *Executor) RunEach(ctx context.Context, targets []transport.Target, build func(transport.Target) transport.Request) []*transport.Result
RunEach executes a request built per target, which is how a command sends each node its own arguments.
Results come back in the order the targets were given, whatever order they finished in, so output is reproducible. A target that fails does not stop the others: the point of a fan-out is to learn about every node.
type Group ¶
type Group struct {
// Nodes are the targets that produced this output.
Nodes *nodeset.NodeSet `json:"nodes" yaml:"nodes"`
// Output is the standard output they shared, exactly as it came.
Output string `json:"output" yaml:"output"`
// ExitCode is the status they shared.
ExitCode int `json:"exitCode" yaml:"exitCode"`
// Status says how they ended, as Status reports it.
Status string `json:"status" yaml:"status"`
}
Group is a set of targets that produced identical output.
func GroupByOutput ¶
GroupByOutput collects targets that answered the same thing, which turns the output of a thousand nodes into the handful of answers worth reading.
Targets are grouped only when both their output and the way they ended are the same: for grep -q or test -e the status is the whole answer, and a node that could not be reached said nothing, which is not the same as a node that answered with nothing. Output that differs only in blank lines at the end is not the same output either.
Groups come back largest first, and equally sized groups in node set order, so two runs of the same command print the same thing.
A group holds its targets as a node set, so a target whose name is not one host name cannot be put into one: it would be read as an expression, or lost. GroupByOutput then returns an error naming it rather than groups that drop or miscount it.