Documentation ¶
Index ¶
- Variables
- func AddTextDiff(m map[string]Diff, name, original, current, defaultVal string) map[string]Diff
- func AnyChanges(diffs map[string]Diff) bool
- type Diff
- type ExportedField
- type FieldMap
- type HealthStatus
- func (h *HealthStatus) Changes() map[string]Diff
- func (h *HealthStatus) Error() error
- func (h *HealthStatus) HasChanges() bool
- func (h *HealthStatus) HasFailingDeps() bool
- func (h *HealthStatus) IsError() bool
- func (h *HealthStatus) IsWarning() bool
- func (h *HealthStatus) Messages() []string
- func (h *HealthStatus) ShouldDisplay() bool
- func (h *HealthStatus) UpgradeWarning(level HealthStatusCode)
- type HealthStatusCode
- type Preparer
- type Renderer
- type Resource
- type Status
- func (t *Status) AddDifference(name, original, current, defaultVal string)
- func (t *Status) AddMessage(message ...string)
- func (t *Status) Diffs() map[string]Diff
- func (t *Status) Error() error
- func (t *Status) ExportedFields() FieldMap
- func (t *Status) FailingDep(id string, stat TaskStatus)
- func (t *Status) HasChanges() bool
- func (t *Status) HealthCheck() (status *HealthStatus, err error)
- func (t *Status) Messages() []string
- func (t *Status) RaiseLevel(level StatusLevel)
- func (t *Status) RaiseLevelForDiffs()
- func (t *Status) SetError(err error)
- func (t *Status) SetWarning(warning string)
- func (t *Status) StatusCode() StatusLevel
- func (t *Status) UpdateExportedFields(input Task) error
- func (t *Status) Warning() string
- type StatusLevel
- type Task
- type TaskStatus
- type TaskWrapper
- type Tasker
- type TextDiff
- type ThunkTask
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilStruct is returned if there is an attempt to introspect a nil value ErrNilStruct = errors.New("cannot inspect types with a nil value") // ErrNonStructIntrospection is returned when attempting to introspect fields // on a non-struct type. ErrNonStructIntrospection = errors.New("cannot extract fields for types other than struct") // ErrFieldIndexOutOfBounds is returned when a field index is beyond the // number of fields in the struct type ErrFieldIndexOutOfBounds = errors.New("struct field index is out of bounds") // ErrDuplicateFieldName is returned if there is a duplicate reference name in // an exported field slice during map construction ErrDuplicateFieldName = errors.New("detected duplicate field name") )
var ( // ErrStatusCantChange is returned when an error is not set but the level is // StatusCantChange ErrStatusCantChange = errors.New("resource cannot change because of an error") // ErrStatusFatal is returned when an error is not set but the level is // StatusFatal ErrStatusFatal = errors.New("resource encountered an error") )
error messages
Functions ¶
func AddTextDiff ¶
AddTextDiff inserts a new TextDiff into a map of names to Diffs
func AnyChanges ¶
AnyChanges takes a diff map and returns true if any of the diffs in the map have changes.
Types ¶
type ExportedField ¶
type ExportedField struct { FieldName string ReferenceName string StructField *reflect.StructField Value reflect.Value }
ExportedField represents an exported field, including the containing struct, offset, field name, and lookup name
func ExportedFields ¶
func ExportedFields(input interface{}) (exported []*ExportedField, err error)
ExportedFields returns a slice of fields that have been exported from a struct; including embedded fields
type FieldMap ¶
type FieldMap map[string]interface{}
FieldMap represents a map of field names to interfaces
func GenerateLookupMap ¶
func GenerateLookupMap(fields []*ExportedField) (FieldMap, error)
GenerateLookupMap takes an exported field list and generates a map of lookup names to values
func LookupMapFromInterface ¶
LookupMapFromInterface gets the concrete implementation of an interface and then gets the struct fields from it
func LookupMapFromStruct ¶
LookupMapFromStruct generates a lookup map from a struct
type HealthStatus ¶
type HealthStatus struct { TaskStatus WarningLevel HealthStatusCode DisplayLevel *HealthStatusCode FailingDeps map[string]string }
HealthStatus contains a status level, display threshold, and status message
func (*HealthStatus) Changes ¶
func (h *HealthStatus) Changes() map[string]Diff
Changes returns changes from the underlying TaskStatus diffs
func (*HealthStatus) Error ¶
func (h *HealthStatus) Error() error
Error returns nil on success. If the health checks or it's dedencies are failing an appropriate error is returned.
func (*HealthStatus) HasChanges ¶
func (h *HealthStatus) HasChanges() bool
HasChanges returns true if the status indicates that there are changes
func (*HealthStatus) HasFailingDeps ¶
func (h *HealthStatus) HasFailingDeps() bool
HasFailingDeps returns true of FailingDeps is not empty
func (*HealthStatus) IsError ¶
func (h *HealthStatus) IsError() bool
IsError returns true if the warning level is StatusError
func (*HealthStatus) IsWarning ¶
func (h *HealthStatus) IsWarning() bool
IsWarning returns true if the warning level is StatusWarning
func (*HealthStatus) Messages ¶
func (h *HealthStatus) Messages() []string
Messages returns health status messages
func (*HealthStatus) ShouldDisplay ¶
func (h *HealthStatus) ShouldDisplay() bool
ShouldDisplay returns true if the warning level is at least the display level
func (*HealthStatus) UpgradeWarning ¶
func (h *HealthStatus) UpgradeWarning(level HealthStatusCode)
UpgradeWarning will increase the warning level to at least `level`, but will not decrease it if it's already higher.
type HealthStatusCode ¶
type HealthStatusCode int
HealthStatusCode is a status indicator for health level. It should be one of:
StatusHealth StatusWarning StatusError
const ( // StatusHealthy indicates a passing health check StatusHealthy HealthStatusCode = iota // StatusWarning indicates a change is needed StatusWarning // StatusError indicates that a module is non-functional StatusError )
type Preparer ¶
Preparer wraps and implements resource.Resource in order to deserialize into regular Preparers
func NewPreparer ¶
NewPreparer wraps a given resource in this preparer
func NewPreparerWithSource ¶
NewPreparerWithSource creates a new preparer with the source included
type Renderer ¶
type Renderer interface { GetID() string Value() (value Value, present bool) Render(name, content string) (string, error) }
Renderer is passed to resources
type Status ¶
type Status struct { // Differences contains the things that will change as a part of this // Status. This will be used almost exclusively in the Check phase of // operations on resources. Use `NewStatus` to get a Status with this // initialized properly. Differences map[string]Diff // Output is the human-consumable fields on this struct. Output will be // returned as the Status' messages Output []string // Level indicates the change level of the status. Level is a gradation (see // the Status* contsts above.) Level StatusLevel // contains filtered or unexported fields }
Status is the default TaskStatus implementation
func (*Status) AddDifference ¶
AddDifference adds a TextDiff to the Differences map
func (*Status) AddMessage ¶
AddMessage adds a human-readable message(s) to the output
func (*Status) Error ¶
Error returns an error, if set. If the level is StatusCantChange or StatusFatal and an error is not set, Error will generate an appropriate error message.
func (*Status) ExportedFields ¶
ExportedFields returns the exported fields from the status
func (*Status) FailingDep ¶
func (t *Status) FailingDep(id string, stat TaskStatus)
FailingDep tracks a new failing dependency
func (*Status) HasChanges ¶
HasChanges returns the WillChange value
func (*Status) HealthCheck ¶
func (t *Status) HealthCheck() (status *HealthStatus, err error)
HealthCheck provides a default health check implementation for statuses
func (*Status) RaiseLevel ¶
func (t *Status) RaiseLevel(level StatusLevel)
RaiseLevel raises the status level to the given level
func (*Status) RaiseLevelForDiffs ¶
func (t *Status) RaiseLevelForDiffs()
RaiseLevelForDiffs raises the status level to StatusWillChange if there are differences in the Differences map
func (*Status) SetWarning ¶
SetWarning sets a warning on a status
func (*Status) StatusCode ¶
func (t *Status) StatusCode() StatusLevel
StatusCode returns the current warning level
func (*Status) UpdateExportedFields ¶
UpdateExportedFields sets the exported fields in the status
type StatusLevel ¶
type StatusLevel uint32
StatusLevel will be used as a level in Status. It indicates if a resource needs to be changed, as well as fatal conditions.
const ( // StatusNoChange means no changes are necessary. This status signals that // execution of dependent resources can continue. StatusNoChange StatusLevel = iota // StatusWontChange indicates an acceptable delta that wont be corrected. // This status signals that execution of dependent resources can continue. StatusWontChange // StatusWillChange indicates an unacceptable delta that will be corrected. // This status signals that execution of dependent resources can continue. StatusWillChange // StatusMayChange indicates an unacceptable delta that may be corrected. This // is considered a warning state that indicates that the resource needs to // change but is likely dependent on the succesful execution of another // resource. This status signals that execution of dependent resources can // continue. StatusMayChange // StatusCantChange indicates an unacceptable delta that can't be corrected. // This is just like StatusFatal except the user will see that the resource // needs to change, but can't because of the condition specified in your // messaging. This status halts execution of dependent resources. StatusCantChange // StatusFatal indicates an error. This is just like StatusCantChange except // it does not imply that there are changes to be made. This status halts // execution of dependent resources. StatusFatal )
func (StatusLevel) String ¶
func (l StatusLevel) String() string
type Task ¶
type Task interface { Check(context.Context, Renderer) (TaskStatus, error) Apply(context.Context) (TaskStatus, error) }
Task controls checks and application inside the system. Check will be called first; if it indicates changes will be made then Apply will also be called. Check will be called again if Apply succeeds with no error to get the final status of the resource.
func ResolveTask ¶
ResolveTask unwraps Tasker layers until it finds an underlying Task or fails
type TaskStatus ¶
type TaskStatus interface { Diffs() map[string]Diff StatusCode() StatusLevel Messages() []string HasChanges() bool Error() error Warning() string UpdateExportedFields(Task) error ExportedFields() FieldMap }
TaskStatus represents the results of Check called during planning or application.
type TaskWrapper ¶
type TaskWrapper struct {
Task
}
TaskWrapper provides an implementation of render.Tasker for tasks
func (*TaskWrapper) GetStatus ¶
func (t *TaskWrapper) GetStatus() TaskStatus
GetStatus returns a nil status for a wrapped task
func (*TaskWrapper) GetTask ¶
func (t *TaskWrapper) GetTask() (Task, bool)
GetTask provides Tasker.GetTask ontop of a task
type Tasker ¶
type Tasker interface { GetTask() (Task, bool) GetStatus() TaskStatus }
Tasker is a struct that is or contains an embedded resource.Task and a resource.Status. It's implemented by plan.Result and apply.Result
type TextDiff ¶
TextDiff is the default Diff implementation
type ThunkTask ¶
type ThunkTask struct {
Name string
}
ThunkTask represents an abstract task over a thunk, used when we need to serialized a thunked value.
func NewThunkedTask ¶
NewThunkedTask generates a ThunkTask from a PrepareThunk
func (*ThunkTask) Apply ¶
func (t *ThunkTask) Apply(context.Context) (TaskStatus, error)
Apply returns a task status with thunk information