fanout

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0, LGPL-3.0 Imports: 12 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 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

View Source
const DefaultMax = 16

DefaultMax is used when nothing configures the fan-out.

Variables

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

func Failures(results []*transport.Result) []*transport.Result

Failures returns the results that did not succeed.

func Recovered added in v0.3.0

func Recovered(target string, v any) error

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.

func Status added in v0.3.0

func Status(r *transport.Result) string

Status says in a word how a target ended: "ok", "exit N", "unreachable" when the transport could not reach it, or "interrupted" when it was cancelled.

func Succeeded

func Succeeded(results []*transport.Result) *nodeset.NodeSet

Succeeded returns the node set whose targets succeeded.

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

func GroupByOutput(results []*transport.Result) ([]Group, error)

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.

Jump to

Keyboard shortcuts

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