Documentation ¶
Index ¶
- Variables
- func DependOn(dep string, deps ...string) func(*addOptions)
- func EqualPlans(p1, p2 Plan) bool
- func ParamString(template string, params ...*string) fmt.Stringer
- type Builder
- type Diff
- type InvalidityReason
- type LocalRunner
- type Plan
- func (p *Plan) Apply(ctx context.Context, r Runner, diff Diff) (bool, error)
- func (p *Plan) ApplyResourceGraph(ctx context.Context, resourceIDs []string, diff *Diff, runner Runner) map[string]ValidityTree
- func (p *Plan) EnsureResourceValid(ctx context.Context, resourceID string, runner Runner) ValidityTree
- func (p *Plan) EnsureResourcesValid(ctx context.Context, resourceIDs []string, runner Runner) map[string]ValidityTree
- func (p *Plan) GetResource(name string) Resource
- func (p *Plan) QueryState(ctx context.Context, runner Runner) (State, error)
- func (p *Plan) SetUndoCondition(checkFun func(Runner, State) bool)
- func (p *Plan) State() State
- func (p *Plan) ToDOT() string
- func (p *Plan) ToHumanReadableJSON() string
- func (p *Plan) ToJSON() string
- func (p *Plan) ToState() State
- func (p *Plan) Undo(ctx context.Context, runner Runner, current State) error
- type Resource
- type RunError
- type Runner
- type State
- func (s State) Bool(path string) bool
- func (s State) Diff(t State) (string, error)
- func (s State) Equal(other State) bool
- func (s State) Get(path string) (interface{}, error)
- func (s State) GetBool(path string) (bool, error)
- func (s State) GetNumber(path string) (float64, error)
- func (s State) GetObject(path string) (State, error)
- func (s State) GetString(path string) (string, error)
- func (s State) IsEmpty() bool
- func (s State) Merge(a State)
- func (s State) Number(path string) float64
- func (s State) Object(path string) State
- func (s State) Set(path string, v interface{})
- func (s State) SetBool(path string, b bool)
- func (s State) SetNumber(path string, f float64)
- func (s State) SetObject(path string, o State)
- func (s State) SetString(path string, str string)
- func (s State) String(path string) string
- func (s State) ToJSON() string
- type Validity
- type ValidityTree
Constants ¶
This section is empty.
Variables ¶
var EmptyState = State(nil)
EmptyState is the empty State.
Functions ¶
func EqualPlans ¶
EqualPlans Compares Plans for equality; not currently used except in tests
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a plan builder.
func (*Builder) AddResource ¶
AddResource adds a resource to the plan.
type Diff ¶
Diff represents the motivation for performing an Apply; a cached version of the current State and any dependee Resources that have been invalidated.
type InvalidityReason ¶
type InvalidityReason int
InvalidityReason describes why a resource isn't valid
const ( None InvalidityReason = iota ApplyError QueryError ChildInvalid ChildInconclusive DependencyInvalid DependencyInconclusive )
func (InvalidityReason) MarshalJSON ¶
func (r InvalidityReason) MarshalJSON() ([]byte, error)
MarshalJSON marshals the enum as a quoted json string
func (InvalidityReason) String ¶
func (r InvalidityReason) String() string
func (*InvalidityReason) UnmarshalJSON ¶
func (r *InvalidityReason) UnmarshalJSON(b []byte) error
UnmarshalJSON unmashals a quoted json string to the enum value
type LocalRunner ¶
type LocalRunner struct{}
LocalRunner is a runner executing commands on the same host it's running on.
func (*LocalRunner) RunCommand ¶
func (r *LocalRunner) RunCommand(ctx context.Context, cmd string, stdin io.Reader) (stdouterr string, err error)
RunCommand implements Runner.
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
Plan is a succession of Steps to produce a desired outcome.
func NewPlanFromJSON ¶
NewPlanFromJSON Reads a Plan from JSON via State
func (*Plan) Apply ¶
Apply applies this plan. The diff contains:
- either a state roll-up of contained resource states or nil
- a set of updated resources (of which only direct dependencies will be handed to individual resources
func (*Plan) ApplyResourceGraph ¶
func (*Plan) EnsureResourceValid ¶
func (p *Plan) EnsureResourceValid(ctx context.Context, resourceID string, runner Runner) ValidityTree
EnsureResourceValid ensures that a resource is valid by recursively checking dependencies for validity and re-applying as necessary to achieve it
func (*Plan) EnsureResourcesValid ¶
func (p *Plan) EnsureResourcesValid(ctx context.Context, resourceIDs []string, runner Runner) map[string]ValidityTree
EnsureResourcesValid ensures that a set of resources is valid by recursively checking dependencies for validity and re-applying as necessary to achieve it; returns only results for the top-level resources as results for underlying resources will roll up
func (*Plan) GetResource ¶
func (*Plan) QueryState ¶
QueryState implements Resource
func (*Plan) SetUndoCondition ¶
SetUndoCondition sets the function that determines if the Plan will allow undoing its actions
func (*Plan) ToHumanReadableJSON ¶
ToHumanReadableJSON translates a Plan into JSON using State as an intermediate target
type Resource ¶
type Resource interface { // State returns the state that this step will realize when applied. State() State // QueryState returns the current state of this step. For instance, if the step // describes the installation of a package, QueryState will return if the // package is actually installed and its version. QueryState(ctx context.Context, runner Runner) (State, error) // Apply this step and indicate whether downstream resources should be re-applied Apply(ctx context.Context, runner Runner, diff Diff) (propagate bool, err error) // Undo this step. Undo(ctx context.Context, runner Runner, current State) error }
Resource is an atomic step of the plan.
func RegisterResource ¶
RegisterResource is used to map a Resource type name to its type information for deserialization
type Runner ¶
type Runner interface { // RunCommand runs a command in a shell. This means cmd can be more than one // single command, it can be a full bourne shell script. RunCommand(ctx context.Context, cmd string, stdin io.Reader) (stdouterr string, err error) }
Runner is something that can realise a step.
type State ¶
type State map[string]interface{}
State is a collection of (key, value) pairs describing unequivocally a step and, by extension, a plan.
func NewStateFromJSON ¶
NewStateFromJSON creates State from JSON.
func (State) Equal ¶
Equal returns true if two States are equal. Note that State deserialised from JSON can contain map types which do not compare equal.
type Validity ¶
type Validity int
Validity is a Resource's measured "goodness" Either 'Valid', 'Invalid', or 'Inconclusive'. The state is 'Inconclusive' if a state query
fails in the validity tree
func (Validity) MarshalJSON ¶
MarshalJSON marshals the enum as a quoted json string
func (*Validity) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string to the enum value
type ValidityTree ¶
type ValidityTree struct { ResourceID string `json:"resource"` ValidityStatus Validity `json:"status,omitempty"` Reason InvalidityReason `json:"reason,omitempty"` Updated bool `json:"updated,omitempty"` ObservedError string `json:"error,omitempty"` Dependencies []ValidityTree `json:"dependencies,omitempty"` Children []ValidityTree `json:"children,omitempty"` }
ValidityTree is the hierarchical explanation for why a resource is Valid, Invalid, or Inconclusive. Each ValidityTree contains a set of dependency ValidityTrees showing how the Validity status rolls up
func (ValidityTree) Error ¶
func (v ValidityTree) Error() string
func (ValidityTree) ObservedErrorString ¶
func (v ValidityTree) ObservedErrorString() string
func (ValidityTree) ToExplanation ¶
func (v ValidityTree) ToExplanation() ValidityTree
ToExplanation removes all VALID resource dependencies before producing JSON to make it more clear what went wrong. It also only shows full data for a tree the first time it's resource is seen.
func (ValidityTree) ToJSON ¶
func (v ValidityTree) ToJSON() string
ToJSON returns a JSON representation of the ValidityTree.