write

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package write is the surface the mutating commands of manager tools share: naming the Unit to write to, saying whether this is a dry run, and reporting what a function invocation did -- including, path by path, what it changed or on a dry run would change, so a reader can judge a change before committing it.

It is deliberately the reporting half only. Which function to run, and with what arguments, is what each tool is about; how the outcome is rendered is not, and tools rendering it each their own way would be that many things to keep in step for no gain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Change

func Change(changeDesc string, dryRun bool) cubapi.Change

Change turns dry-run/description into a cubapi.Change. An empty description is what makes a call a dry run, so a dry run is spelled by not describing one. Either way it asks for each Unit's diff, which ReportMutations shows.

func DryRunSuffix

func DryRunSuffix(dryRun bool) string

DryRunSuffix is the reminder a dry run's summary line ends with.

func ReleaseNote added in v0.10.4

func ReleaseNote(space string) string

ReleaseNote is what a committed write's report ends with, for a command with a report of its own as for ReportMutations: the Units changed, and none of it reaches a Target until the Space is released. A write command edits configuration; releasing it is a separate, deliberate step.

func ReportMutations

func ReportMutations(cmd *cobra.Command, command, space string, dryRun bool, output string, results ...*cubapi.Result) error

ReportMutations renders one or more cubapi function Results as JSON or a table, aggregated per Unit -- so a command that runs several functions over the same Unit shows a single row, mutated if any function changed it. On a dry run the mutated count is what would change; on a commit it is what did. The table is followed by each changed Unit's diff, when the Change asked for one.

func WriteDiffs

func WriteDiffs(w io.Writer, command string, rep Report)

WriteDiffs writes what each changed Unit in rep was changed by, or on a dry run would be.

func WriteUnitDiffs

func WriteUnitDiffs(w io.Writer, command string, diffs []UnitDiff)

WriteUnitDiffs writes each diff under a header naming the Unit and the command, colored only for a terminal.

func WriteWithheld added in v0.10.14

func WriteWithheld(w io.Writer, rep Report)

WriteWithheld writes, per Unit, what rep's change did not write, or on a dry run would not, and the --clearance that would let it. A write the guards held back is otherwise easy to read as complete: the Unit still counts as changed when the rest of the change was written.

Types

type CommitFlags added in v0.10.14

type CommitFlags struct {
	cliutil.CommitFlags
	Guards          []string
	InheritedGuards []string
	Clearance       []string
	// ChangeSet is the ChangeSet to make the change in, by space/slug or UUID.
	ChangeSet string
}

CommitFlags are the flags every mutating command of a manager tool takes: --commit and --change-desc, which make it write; the guards it records on what it writes and the clearance it writes with, as cub's own writes take them; and the ChangeSet to make it in.

A value a tool writes into a Unit whose configuration is uploaded from somewhere else, such as a rendered chart, is lost the next time it is uploaded unless it is guarded, as in --guard Override=External; and a Unit that is already guarded is written only where --clearance covers its guards.

func (*CommitFlags) Bind added in v0.10.14

func (c *CommitFlags) Bind(cmd *cobra.Command)

Bind registers --commit, --change-desc, --guard, --inherited-guard, --changeset and --clearance on cmd.

func (CommitFlags) Change added in v0.10.14

func (c CommitFlags) Change(summary string) (cubapi.Change, error)

Change validates the flags and returns the change they describe: a dry run unless --commit, asking for each Unit's diff either way, as Change does, with the guards to record and the clearance to write with. summary is suggested when --change-desc is missing.

The clearance includes each guard being recorded, because a change has to be cleared for the guards on a path before overwriting it: without that, running a command a second time would withhold the very paths the first run guarded.

type Outcome

type Outcome struct {
	// Space is where the Unit lives. A slug is unique only within a Space, so a
	// fleet-wide report has to carry it to name the Unit at all.
	Space   string `json:"space,omitempty"`
	Unit    string `json:"unit"`
	Mutated bool   `json:"mutated"`
	Error   string `json:"error,omitempty"`
	// Diffs are what each contributing invocation did to the Unit, or on a dry
	// run would do, in the order they ran. An invocation that changed nothing
	// adds none.
	Diffs []goclientnew.ConfigDiff `json:"diffs,omitempty"`
	// Withheld is what the change did not write to the Unit, or on a dry run would not, with
	// the reason: above all each path whose guards the change's clearance did not cover. The
	// rest of the change is written, so a Unit can be both mutated and withheld from.
	Withheld []goclientnew.MutationConflict `json:"withheld,omitempty"`
	// contains filtered or unexported fields
}

Outcome is one Unit's aggregated result from one or more mutating function invocations.

type Report

type Report struct {
	Command   string    `json:"command"`
	Space     string    `json:"space,omitempty"`
	DryRun    bool      `json:"dryRun"`
	Outcomes  []Outcome `json:"outcomes"`
	Mutated   int       `json:"mutated"`
	Committed int       `json:"committed"`
}

Report is the JSON/table result of a write command.

func Summarize

func Summarize(command, space string, dryRun bool, results ...*cubapi.Result) Report

Summarize aggregates results per Unit without rendering them, for a command that folds the outcome into a report of its own.

Aggregation is by UnitID, not by slug. A slug is unique only within a Space, and a bulk edit spans Spaces: keying by slug silently folds every `app` in the fleet into one row, so the count an operator reads off a dry run is the number of distinct names rather than the number of Units about to change.

type UnitDiff

type UnitDiff struct {
	Space string                 `json:"space,omitempty"`
	Unit  string                 `json:"unit"`
	Diff  goclientnew.ConfigDiff `json:"diff"`
}

UnitDiff is what a change did to one Unit, or on a dry run would do. A command with a report of its own carries these in it, from Diffs.

func Diffs

func Diffs(results ...*cubapi.Result) []UnitDiff

Diffs collects the non-empty diffs in results, per Unit and in the order the invocations ran, sorted by Space and Unit as Summarize sorts its rows.

type UnitRef

type UnitRef struct {
	SpaceID   goclientnew.UUID
	SpaceSlug string
	UnitSlug  string
}

UnitRef is a resolved <space>/<unit> target for a single-Unit write command.

func ParseUnitRef

func ParseUnitRef(ctx context.Context, c *cubapi.Client, arg string) (UnitRef, error)

ParseUnitRef parses a "<space>/<unit>" argument and resolves the Space to its ID against the server.

A Unit slug carrying a quote or a backslash is rejected here rather than at the selector, where the error would name a filter expression the operator never wrote.

func (UnitRef) Selector

func (u UnitRef) Selector() cubapi.Selector

Selector scopes a mutation to exactly this Unit.

Jump to

Keyboard shortcuts

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