app

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: GPL-3.0, LGPL-3.0 Imports: 38 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 app wires the configuration, the transport and the node model into the context every command runs against.

A command receives an App and asks it for targets, node sets and an executor. Nothing in a command reads the configuration or builds an ssh command line itself, so behaviour such as the dry run, the safety gate and the output format works the same everywhere.

Index

Constants

View Source
const (
	TransportRedfish = "redfish"
	TransportIPMI    = "ipmi"
)

The transports a service processor can be reached over.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Streams

	// Resolved is the merged configuration with its provenance.
	Resolved *config.Resolved
	// Spec is the merged configuration.
	Spec v1alpha1.EffectiveSpec
	// Namer turns node names into host names.
	Namer *naming.Namer
	// Inventory holds what is known about the nodes.
	Inventory *inventory.Inventory
	// Groups resolves @group references.
	Groups *groups.Resolver
	// SSH is the transport client; Runner is what commands run through,
	// which is a recorder during a dry run. It reports each request as a
	// progress call (transport.Traced).
	SSH    *transport.Client
	Runner transport.Runner
	// ReadRunner runs the read-only lookups a command makes before it
	// changes anything, such as asking Slurm whether a node runs a job. It
	// is the real transport even in a dry run, so that the dry run reaches
	// the same decision the real run would, and is traced as Runner is.
	ReadRunner transport.Runner
	// DryRunRecorder holds what a dry run would have sent.
	DryRunRecorder *transport.Recorder
	// Gate guards the destructive commands.
	Gate *safety.Gate
	// Format is the output format.
	Format output.Format
	// contains filtered or unexported fields
}

App is the resolved context a command runs against.

func New

func New(ctx context.Context, streams Streams, opts Options) (*App, error)

New resolves the configuration and builds the command context.

func (*App) AgeFile added in v0.4.0

func (a *App) AgeFile(ctx context.Context, path string) (_ []byte, err error)

AgeFile decrypts an age encrypted file of the site into memory, with the identities of the workstation. The decryption is reported as a hidden call, under the span ctx carries.

func (*App) BMCCredential

func (a *App) BMCCredential(ctx context.Context, node string) (credentials.Credential, error)

BMCCredential resolves the account used for a node's service processor, honouring a vendor profile that names its own.

func (*App) BMCCredentialName added in v0.3.0

func (a *App) BMCCredentialName(node string) string

BMCCredentialName names the credential used for a node's service processor: the one its vendor profile names, else the site's. Nodes with the same name share one account, which is how a set is grouped for a backend that takes one account for many processors.

func (*App) BMCHost added in v0.3.0

func (a *App) BMCHost(node string) (string, error)

BMCHost returns the host name or address of a node's service processor: the bmcAddress the inventory records for it, else the name the naming rules give it. The inventory wins because it names the one machine the site wrote down, where a derived name is only as good as its DNS record.

A node whose service processor has neither is refused; nothing falls back to the node's own name, where the BMC password would be sent to the node.

func (*App) BMCHosts added in v0.3.0

func (a *App) BMCHosts(nodes *nodeset.NodeSet) (*nodeset.NodeSet, error)

BMCHosts maps every node of a set to its service processor, the way BMCHost does.

func (*App) BMCOrder

func (a *App) BMCOrder(node string) []string

BMCOrder returns the transport preference for a node, as configured.

func (*App) BMCTransports added in v0.3.0

func (a *App) BMCTransports(node string) ([]string, error)

BMCTransports returns the transports to try for a node, in order. An entry that names no transport is refused rather than read as Redfish, so a misspelt ipmi does not send the BMC account over another protocol.

func (*App) Bound added in v0.4.0

func (a *App) Bound(setting int) int

Bound is the bound of a kind of work that has a setting of its own, such as bmc.redfish.maxConcurrent: the setting, or --fanout where that was given and is lower. --fanout never raises it, and fanout.max in the configuration does not change it (ADR 0022).

func (*App) CheckClusters added in v0.3.0

func (a *App) CheckClusters() error

CheckClusters checks what every Cluster document reads, not only the one the current context names, so that config validate reports a cluster that no command has used yet.

func (*App) Collect added in v0.4.0

func (a *App) Collect(req transport.Request) transport.Request

Collect fills in what a request whose output is collected, rather than shown on a terminal, leaves out: no terminal, and the configured command timeout unless it sets one.

func (*App) Context

func (a *App) Context() context.Context

Context returns the context bounding the command's remote work.

func (*App) Credentials

func (a *App) Credentials() *credentials.Resolver

Credentials returns the credential resolver of the site. It is safe for concurrent use, which the BMC commands need: they build one client per node in parallel.

func (*App) DHCPConfig added in v0.4.0

func (a *App) DHCPConfig(ctx context.Context) (*dhcp.Config, error)

DHCPConfig fetches and parses the DHCP server's configuration, and every file it includes, once per command.

A command asks for it for each node the inventory gives no address, and boot status and provision status go on past a node that failed. Read for each, the configuration was fetched once per node whenever its cached copy had expired, and a server that could not be read was asked again for every node, an ssh timeout each. So what the first read found is kept for the command, a failure as much as a configuration. A read the context stopped is not kept, since it says nothing about the server. A caller that asks while the file is being read waits for that read.

func (*App) DryRun

func (a *App) DryRun() bool

DryRun reports whether nothing may actually be changed.

func (*App) Executor

func (a *App) Executor() *fanout.Executor

Executor returns a fan-out executor bound to the configured limits.

func (*App) FanoutFlag added in v0.4.0

func (a *App) FanoutFlag() int

FanoutFlag is what --fanout gave, zero when it was not given. fanout.max holds it too, but it may as well come from a document, the environment or --set, and only the flag lowers the bounds that have a setting of their own (Bound). Under clusterctl mcp it is the server's own --fanout, since an agent cannot give one.

func (*App) IPMIBackend

func (a *App) IPMIBackend(ctx context.Context, node string) (*ipmi.Backend, error)

IPMIBackend builds the backend that runs the IPMI tools, on the host role bmc.ipmi.via names, with the account of the given node. Nothing runs the tools locally, so a site that names no role gets a usage error. The processors ipmitool is run for at once are bmc.ipmi.maxConcurrent, or fewer where --fanout is lower; ipmipower, which fans out by itself, is handed --fanout when it was given.

func (*App) Identities

func (a *App) Identities() ([]age.Identity, error)

Identities loads the configured age identities, once.

func (*App) IdentityPaths

func (a *App) IdentityPaths() []string

IdentityPaths returns the configured age identities as absolute paths.

func (*App) InventoryNode added in v0.3.0

func (a *App) InventoryNode(name string) (*inventory.Node, bool)

InventoryNode returns the inventory entry of the machine a name refers to.

Host names are not case sensitive and a trailing dot only makes a name absolute, so EXE0001 and exe0001. are exe0001, and so is exe1 when the inventory pads it. A name with a domain is the node only when it is the host name the naming rules give the node's short name; any other domain is another machine. Everything looked up per node goes through here, so that every spelling of a machine gets its own settings rather than the site's.

func (*App) Node

func (a *App) Node(name string) (transport.Target, error)

Node returns the target of a compute node, whose host name comes from the naming rules.

func (*App) NodeTargets

func (a *App) NodeTargets(ns *nodeset.NodeSet) ([]transport.Target, error)

NodeTargets returns a target for each node of a set, in expansion order.

func (*App) Path

func (a *App) Path(path string) string

Path resolves a configured path against the directory of the site document, so that a site can be kept in version control and moved.

func (*App) PinStore added in v0.4.0

func (a *App) PinStore() *redfish.PinStore

noteFirstContact says so when no certificate is recorded for a service processor yet. The client records whatever the host presents, and sends the BMC account to it, so the administrator should know it trusted a certificate nobody vouched for, and which host it came from. PinStore is where the certificate fingerprints of the service processors are recorded: bmc.redfish.pinStore, or a file in the state directory.

func (*App) Print

func (a *App) Print(r output.Result) error

Print renders a result in the selected format. A jq program stops with the command's context, when the command is interrupted or cancelled.

func (*App) Printf

func (a *App) Printf(format string, args ...any)

Printf writes a message to the error stream, which is where progress and notes go so that they never mix into parsed output.

func (*App) ReadOnRole added in v0.3.0

func (a *App) ReadOnRole(ctx context.Context, role string, req transport.Request) (*transport.Result, error)

ReadOnRole is RunOnRole for a command that only reads. It runs through ReadRunner, so a dry run reaches the host and sees what the real run would.

func (*App) RedfishClient

func (a *App) RedfishClient(ctx context.Context, node string) (*redfish.Client, error)

RedfishClient builds a client for a node's service processor.

func (*App) RemoteFile

func (a *App) RemoteFile(ctx context.Context, role, path string, ttl time.Duration) (_ []byte, err error)

RemoteFile reads a file from an infrastructure host, reusing a cached copy while it is younger than ttl.

A configuration such as dhcpd.conf is read once per command and often several times in a row, and fetching it again for each node turned a node set query into one connection per node.

The file is read through ReadRunner, so a dry run sees the same file the real run would. The read is reported as a hidden call, with Cache saying whether the cached copy answered it or the host was asked.

func (*App) Role

func (a *App) Role(name string) (transport.Target, error)

Role returns the target of an infrastructure role.

func (*App) RoleNames

func (a *App) RoleNames() []string

RoleNames lists the configured host roles in sorted order.

func (*App) RunOnRole

func (a *App) RunOnRole(ctx context.Context, role string, req transport.Request) (*transport.Result, error)

RunOnRole runs one command on an infrastructure host and returns the result, failing the command when it did not succeed. The request is completed by Collect.

func (*App) SecretContent

func (a *App) SecretContent(ctx context.Context, file v1alpha1.SecretFile) ([]byte, error)

SecretContent decrypts one secret file of the site into memory, from its own age encrypted file or from a key of a Secret document.

func (*App) SecretValue

func (a *App) SecretValue(ctx context.Context, ref v1alpha1.SecretKeyRef) ([]byte, error)

SecretValue decrypts the Secret document a reference names, once per process, and returns the value of the key. The plaintext stays in memory. The decryption is reported under the span ctx carries, the credential or the step that needs it.

func (*App) SecretValues

func (a *App) SecretValues(ctx context.Context, name string) (map[string][]byte, error)

SecretValues decrypts a whole Secret document. The decryption, which runs sops, is reported as a hidden call; a document decrypted before is not decrypted again, and not reported.

func (*App) Select

func (a *App) Select(expr string) (*nodeset.NodeSet, error)

Select parses a node set expression, resolving group references.

An empty expression falls back to what -n or the environment named, so a session can select a set once and then work with it. An expression replaces a set from the environment, which is only a default, but not one from -n: the two together are refused rather than one of them dropped.

func (*App) SelectOptional

func (a *App) SelectOptional(expr string) (*nodeset.NodeSet, error)

SelectOptional is Select without the requirement that anything is selected; it returns nil when nothing was named.

func (*App) Slurm

func (a *App) Slurm() (*slurm.Client, error)

Slurm returns a client for the workload manager, which runs its clients on the host role the cluster names.

func (*App) Sops added in v0.4.0

func (a *App) Sops() *secrets.Sops

Sops is the sops command Secret documents are decrypted with: workstation.sopsBinary, or sops in PATH.

func (*App) StatePath

func (a *App) StatePath(parts ...string) string

StatePath returns a path inside the state directory.

func (*App) Timeout

func (a *App) Timeout() v1alpha1.Duration

Timeout returns the command timeout for remote execution.

func (*App) VendorProfile

func (a *App) VendorProfile(node string) v1alpha1.VendorProfile

VendorProfile returns the BMC overrides for a node's hardware vendor.

type Options

type Options struct {
	// ConfigFiles replaces the search path when it is set.
	ConfigFiles []string
	// Context selects the context.
	Context string
	// Nodes is the default node set, from -n or the environment.
	Nodes string
	// NodesFromFlag says Nodes came from -n, so a node set given as an
	// argument as well is a contradiction rather than an override.
	NodesFromFlag bool
	// Format is the -o value.
	Format string
	// Set are the --set assignments.
	Set map[string]string
	// DryRun reports what would be done and changes nothing.
	DryRun bool
	// AssumeYes answers the confirmations in advance.
	AssumeYes bool
	// Force allows protected hosts to be touched.
	Force bool
	// Fanout overrides how many hosts are worked on at once.
	Fanout int
	// SiteHostsOnly refuses a node that is neither in the inventory nor in
	// one of the site's domains. The MCP server sets it for the commands an
	// agent runs.
	SiteHostsOnly bool
	// Env reads environment variables; nil reads the process environment.
	Env func(string) string
	// Runner replaces the ssh transport for everything a command runs. A
	// dry run sets it to a recorder, and the tests use it to drive the
	// commands without a cluster.
	Runner transport.Runner
}

Options are the global flags, resolved before a command runs.

type Streams

type Streams struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
	// Diag receives what clusterctl has to say about itself rather than
	// about the command: what a password helper writes on its standard
	// error, and the stack of a recovered panic. Under clusterctl mcp it is
	// the server's log, where Err is the notes a call returns to the agent.
	// Nil means Err.
	Diag io.Writer
	// WorkerDiag receives what the goroutines of the command's own pools
	// have to say about themselves: the stack of a panic a worker recovered
	// from. They write at any moment, so while a progress display is shown
	// it holds their lines while a question is asked, and writes them once
	// it has been answered, never into it. Nil means Diag.
	WorkerDiag io.Writer

	// IsTTY says standard input is a terminal, so that a confirmation or a
	// password can be asked for.
	IsTTY bool
	// OutIsTTY and ErrIsTTY say standard output and standard error are
	// terminals, so that something may be drawn on them.
	OutIsTTY bool
	ErrIsTTY bool
	// OutIsPipe says standard output goes into a pipe or a socket, whose
	// reader, such as grep or less, may well write to the terminal a
	// display would draw on, where nothing keeps the two apart.
	OutIsPipe bool
	// Size returns the width and height of the terminal on standard error,
	// asked afresh on every call so that a resized window is seen. It is nil
	// when standard error is not a terminal.
	Size func() (w, h int, err error)
	// Foreground reports whether the process is the job in the foreground
	// of the terminal on standard error, asked afresh on every call, so that
	// nothing is drawn while it runs in the background under the shell's
	// prompt. It is nil when standard error is not a terminal, or there are
	// no jobs to tell apart.
	Foreground func() bool
	// Display says a progress display, the live tree, the counter or plain
	// lines, is shown on standard error while the command runs, through Out
	// and Err, which keep what the command writes clear of it. Nothing else
	// may draw there then: scp's progress meter is left off.
	Display bool

	StateDir string
	CacheDir string
}

Streams are the input and output a command talks to. Tests replace them with buffers.

The zero value of each terminal field means there is no terminal, which is what a test, the MCP server and the documentation generator have.

func DefaultStreams

func DefaultStreams() Streams

DefaultStreams returns the process streams.

A state or cache directory that cannot be known is left empty, and New refuses to run without it.

Jump to

Keyboard shortcuts

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