Documentation ¶
Index ¶
- Variables
- func Diff(a, b interface{}) []diffmatchpatch.Diff
- func DiffsHasChanges(diffs []diffmatchpatch.Diff) bool
- type Action
- type Bundle
- type HostState
- type IndividuallyManageableResource
- type ManageableResource
- type MergeableManageableResources
- type Name
- type Plan
- type RefreshableManageableResource
- type Resource
- func (r Resource) IsMergeableManageableResources() bool
- func (r Resource) ManageableResource() ManageableResource
- func (r Resource) MustIndividuallyManageableResource() IndividuallyManageableResource
- func (r Resource) MustMergeableManageableResources() MergeableManageableResources
- func (r Resource) MustName() Name
- func (r Resource) MustType() Type
- func (r Resource) Refreshable() bool
- func (r Resource) String() string
- func (r *Resource) UnmarshalYAML(node *yaml.Node) error
- type Resources
- type State
- type Step
- type StepAction
- type StepActionIndividual
- type StepActionMerged
- func (sam StepActionMerged) ActionResourcesMap() map[Action]Resources
- func (sam StepActionMerged) Actionable() bool
- func (sam StepActionMerged) Execute(ctx context.Context, hst host.Host) error
- func (sam StepActionMerged) MustMergeableManageableResources() MergeableManageableResources
- func (sam StepActionMerged) String() string
- func (sam StepActionMerged) StringNoAction() string
- type Type
- type TypeName
- func (tn TypeName) IsIndividuallyManageableResource() bool
- func (tn TypeName) IsMergeableManageableResources() bool
- func (tn TypeName) ManageableResource() ManageableResource
- func (tn TypeName) MustIndividuallyManageableResource() IndividuallyManageableResource
- func (tn TypeName) Name() Name
- func (tn TypeName) Type() Type
- func (tn *TypeName) UnmarshalYAML(node *yaml.Node) error
- type TypeNameStateMap
Constants ¶
This section is empty.
Variables ¶
var IndividuallyManageableResourceTypeMap = map[Type]IndividuallyManageableResource{}
IndividuallyManageableResourceTypeMap maps Type to IndividuallyManageableResource.
var ManageableResourcesStateMap = map[Type]State{}
ManageableResourcesStateMap maps Type to its State.
var MergeableManageableResourcesTypeMap = map[Type]MergeableManageableResources{}
MergeableManageableResourcesTypeMap maps Type to MergeableManageableResources.
Functions ¶
func Diff ¶
func Diff(a, b interface{}) []diffmatchpatch.Diff
func DiffsHasChanges ¶
func DiffsHasChanges(diffs []diffmatchpatch.Diff) bool
DiffsHasChanges return true when the diff contains no changes.
Types ¶
type Action ¶
type Action int
Action to be executed for a resource.
const ( ActionNone Action = iota // ActionOk means state is as expected ActionOk // ActionSkip denotes no action is required as the resource was merged. ActionSkip // ActionRefresh means that any in-memory state is to be refreshed (eg: restart a service, reload configuration from files etc). ActionRefresh // ActionConfigure means that the state of the resource is not as expected and it that it must be configured. ActionConfigure // ActionDestroy means that the resource is no longer needed and is to be destroyed. ActionDestroy // ActionCount has the number of existing actions ActionCount )
func (Action) Actionable ¶
type Bundle ¶
type Bundle []Resources
Bundle holds all resources for a host.
func LoadBundle ¶
LoadBundle search for .yaml files at root, each having the Resources schema, loads and returns all of them. Bundle is sorted by alphabetical order.
func NewRollbackBundle ¶
func NewRollbackBundle( newBundle Bundle, previousBundle *Bundle, typeNameStateMap TypeNameStateMap, intendedAction Action, ) Bundle
func (Bundle) HasTypeName ¶
HasTypeName returns true if Resource is contained at Bundle.
func (Bundle) IsClean ¶
func (b Bundle) IsClean( ctx context.Context, hst host.Host, typeNameStateMap TypeNameStateMap, ) (bool, error)
IsClean whether all resources at Bundle are clean.
type HostState ¶
type HostState struct { // Version of the binary used to put the host in this state. Version version.Version `yaml:"version"` PreviousBundle Bundle `yaml:"previous_bundle"` }
HostState holds the state for a host
func NewHostState ¶
type IndividuallyManageableResource ¶
type IndividuallyManageableResource interface { ManageableResource // GetState gets the state of the resource, or nil if not present. GetState(ctx context.Context, hst host.Host, name Name) (State, error) // Configure configures the resource to given state. // Must be idempotent. Configure(ctx context.Context, hst host.Host, name Name, state State) error // Destroy a configured resource at given host. // Must be idempotent. Destroy(ctx context.Context, hst host.Host, name Name) error }
IndividuallyManageableResource is an interface for managing a single resource name. This is the most common use case, where resources can be individually managed without one resource having dependency on others and changing one resource does not affect the state of another.
type ManageableResource ¶
type ManageableResource interface { // ValidateName validates the name of the resource ValidateName(name Name) error }
ManageableResource defines a common interface for managing resource state.
type MergeableManageableResources ¶
type MergeableManageableResources interface { ManageableResource // GetStates gets the state of all resources, or nil if not present. GetStates(ctx context.Context, hst host.Host, names []Name) (map[Name]State, error) // ConfigureAll configures all resource to given state. // Must be idempotent. ConfigureAll( ctx context.Context, hst host.Host, actionNameStateMap map[Action]map[Name]State, ) error }
MergeableManageableResources is an interface for managing multiple resources together. The use cases for this are resources where there's inter-dependency between resources, and they must be managed "all or nothing". The typical use case is Linux distribution package management, where one package may conflict with another, and the transaction of the final state must be computed altogether.
type Name ¶
type Name string
Name is a name that globally uniquely identifies a resource instance of a given type. Eg: for File type a Name would be the file absolute path such as /etc/issue.
type Plan ¶
type Plan struct { Steps []*Step TypeNameStateMap TypeNameStateMap }
Plan is a directed graph which contains the plan for applying resources to a host.
func (Plan) Actionable ¶
type RefreshableManageableResource ¶
type RefreshableManageableResource interface { ManageableResource // Refresh the resource. This is typically used to update the in-memory state of a resource // (eg: kerner: sysctl, iptables; process: systemd service) after persistent changes are made // (eg: change configuration file) Refresh(ctx context.Context, hst host.Host, name Name) error }
RefreshableManageableResource defines an interface for resources that can be refreshed. Refresh means updating in-memory state as a function of file changes (eg: restarting a service, loading iptables rules to the kernel etc.)
type Resource ¶
type Resource struct { TypeName TypeName `yaml:"resource"` State State `yaml:"state"` Destroy bool `yaml:"destroy"` }
Resource holds a single resource.
func (Resource) IsMergeableManageableResources ¶
IsMergeableManageableResources returns true only if ManageableResource is of type MergeableManageableResources.
func (Resource) ManageableResource ¶
func (r Resource) ManageableResource() ManageableResource
func (Resource) MustIndividuallyManageableResource ¶
func (r Resource) MustIndividuallyManageableResource() IndividuallyManageableResource
MustIndividuallyManageableResource returns IndividuallyManageableResource from ManageableResource or panics if it isn't of the required type.
func (Resource) MustMergeableManageableResources ¶
func (r Resource) MustMergeableManageableResources() MergeableManageableResources
MustMergeableManageableResources returns MergeableManageableResources from ManageableResource or panics if it isn't of the required type.
func (Resource) Refreshable ¶
Refreshable returns whether the resource is refreshable or not.
func (*Resource) UnmarshalYAML ¶
type Resources ¶
type Resources []Resource
Resources is the schema used to declare multiple resources at a single file.
func LoadResources ¶
LoadBundle loads resources from given Yaml file path.
type State ¶
type State interface { // ValidateAndUpdate validates and updates the state with any required information from the host. // Eg: transform username into UID. ValidateAndUpdate(ctx context.Context, hst host.Host) (State, error) }
State is a Type specific interface for defining resource state as configured by users.
type Step ¶
type Step struct { StepAction StepAction // contains filtered or unexported fields }
Step that's used at a Plan
func (Step) ActionResourcesMap ¶
func (Step) Actionable ¶
func (Step) HasTypeName ¶
type StepAction ¶
type StepAction interface { // Execute actions for all bundled resources. Execute(ctx context.Context, hst host.Host) error String() string // Actionable returns whether any action is different from ActionOk or ActionSkip Actionable() bool // ActionResources returns a map from Action to a slice of Resource. ActionResourcesMap() map[Action]Resources }
StepAction defines an interface for an action that can be executed from a Step.
type StepActionIndividual ¶
StepActionIndividual is a StepAction which can execute a single Resource.
func (StepActionIndividual) ActionResourcesMap ¶
func (sai StepActionIndividual) ActionResourcesMap() map[Action]Resources
func (StepActionIndividual) Actionable ¶
func (sai StepActionIndividual) Actionable() bool
func (StepActionIndividual) String ¶
func (sai StepActionIndividual) String() string
type StepActionMerged ¶
StepActionMerged is a StepAction which contains multiple merged Resource.
func (StepActionMerged) ActionResourcesMap ¶
func (sam StepActionMerged) ActionResourcesMap() map[Action]Resources
func (StepActionMerged) Actionable ¶
func (sam StepActionMerged) Actionable() bool
func (StepActionMerged) MustMergeableManageableResources ¶
func (sam StepActionMerged) MustMergeableManageableResources() MergeableManageableResources
MustMergeableManageableResources returns MergeableManageableResources common to all Resource or panics.
func (StepActionMerged) String ¶
func (sam StepActionMerged) String() string
func (StepActionMerged) StringNoAction ¶
func (sam StepActionMerged) StringNoAction() string
type Type ¶
type Type string
Type is the name of the resource type.
func NewTypeFromStr ¶
func (Type) ManageableResource ¶
func (t Type) ManageableResource() ManageableResource
ManageableResource returns an instance for the resource type.
func (Type) MustMergeableManageableResources ¶
func (t Type) MustMergeableManageableResources() MergeableManageableResources
MustMergeableManageableResources returns MergeableManageableResources from ManageableResource or panics if it isn't of the required type.
type TypeName ¶
type TypeName string
TypeName is a string that identifies a resource type and name. Eg: File[/etc/issue].
func NewTypeNameFromStr ¶
func (TypeName) IsIndividuallyManageableResource ¶
IsIndividuallyManageableResource returns true if ManageableResource() is of type IndividuallyManageableResource.
func (TypeName) IsMergeableManageableResources ¶
IsMergeableManageableResources returns true only if ManageableResource() is of type MergeableManageableResources.
func (TypeName) ManageableResource ¶
func (tn TypeName) ManageableResource() ManageableResource
ManageableResource returns an instance for the resource type.
func (TypeName) MustIndividuallyManageableResource ¶
func (tn TypeName) MustIndividuallyManageableResource() IndividuallyManageableResource
MustIndividuallyManageableResource returns IndividuallyManageableResource from ManageableResource or panics if it isn't of the required type.
func (*TypeName) UnmarshalYAML ¶
type TypeNameStateMap ¶
func GetTypeNameStateMap ¶
func GetTypeNameStateMap( ctx context.Context, hst host.Host, typeNames []TypeName, ) (TypeNameStateMap, error)
GetTypeNameStateMap gets current state for all given TypeName.