Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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

    func AddTextDiff(m map[string]Diff, name, original, current, defaultVal string) map[string]Diff

      AddTextDiff inserts a new TextDiff into a map of names to Diffs

      func AnyChanges

      func AnyChanges(diffs map[string]Diff) bool

        AnyChanges takes a diff map and returns true if any of the diffs in the map have changes.

        Types

        type Diff

        type Diff interface {
        	Original() string
        	Current() string
        	Changes() bool
        }

          Diff represents a difference

          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

                  func LookupMapFromInterface(input interface{}) (FieldMap, error)

                    LookupMapFromInterface gets the concrete implementation of an interface and then gets the struct fields from it

                    func LookupMapFromStruct

                    func LookupMapFromStruct(input interface{}) (FieldMap, error)

                      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

                                            type Preparer struct {
                                            	Source      map[string]interface{}
                                            	Destination Resource
                                            }

                                              Preparer wraps and implements resource.Resource in order to deserialize into regular Preparers

                                              func NewPreparer

                                              func NewPreparer(r Resource) *Preparer

                                                NewPreparer wraps a given resource in this preparer

                                                func NewPreparerWithSource

                                                func NewPreparerWithSource(r Resource, source map[string]interface{}) *Preparer

                                                  NewPreparerWithSource creates a new preparer with the source included

                                                  func (*Preparer) Prepare

                                                  func (p *Preparer) Prepare(ctx context.Context, r Renderer) (Task, error)

                                                    Prepare the destination to prepare itself.

                                                    type Renderer

                                                    type Renderer interface {
                                                    	GetID() string
                                                    	Value() (value Value, present bool)
                                                    	Render(name, content string) (string, error)
                                                    }

                                                      Renderer is passed to resources

                                                      type Resource

                                                      type Resource interface {
                                                      	Prepare(context.Context, Renderer) (Task, error)
                                                      }

                                                        Resource adds metadata about the executed tasks

                                                        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 NewStatus

                                                          func NewStatus() *Status

                                                            NewStatus returns a Status with all fields initialized

                                                            func (*Status) AddDifference

                                                            func (t *Status) AddDifference(name, original, current, defaultVal string)

                                                              AddDifference adds a TextDiff to the Differences map

                                                              func (*Status) AddMessage

                                                              func (t *Status) AddMessage(message ...string)

                                                                AddMessage adds a human-readable message(s) to the output

                                                                func (*Status) Diffs

                                                                func (t *Status) Diffs() map[string]Diff

                                                                  Diffs returns the internal differences

                                                                  func (*Status) Error

                                                                  func (t *Status) Error() 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

                                                                    func (t *Status) ExportedFields() FieldMap

                                                                      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

                                                                        func (t *Status) HasChanges() bool

                                                                          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) Messages

                                                                            func (t *Status) Messages() []string

                                                                              Messages returns the current output slice

                                                                              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) SetError

                                                                                  func (t *Status) SetError(err error)

                                                                                    SetError sets an error on a status

                                                                                    func (*Status) SetWarning

                                                                                    func (t *Status) SetWarning(warning string)

                                                                                      SetWarning sets a warning on a status

                                                                                      func (*Status) StatusCode

                                                                                      func (t *Status) StatusCode() StatusLevel

                                                                                        StatusCode returns the current warning level

                                                                                        func (*Status) UpdateExportedFields

                                                                                        func (t *Status) UpdateExportedFields(input Task) error

                                                                                          UpdateExportedFields sets the exported fields in the status

                                                                                          func (*Status) Warning

                                                                                          func (t *Status) Warning() string

                                                                                            Warning returns the warning message, if set.

                                                                                            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

                                                                                                func ResolveTask(w interface{}) (Task, bool)

                                                                                                  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 WrapTask

                                                                                                      func WrapTask(t Task) *TaskWrapper

                                                                                                        WrapTask creates a new TaskWrapper

                                                                                                        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

                                                                                                              type TextDiff struct {
                                                                                                              	Default string
                                                                                                              	Values  [2]string
                                                                                                              }

                                                                                                                TextDiff is the default Diff implementation

                                                                                                                func (TextDiff) Changes

                                                                                                                func (t TextDiff) Changes() bool

                                                                                                                  Changes is true if the Original and Current values differ

                                                                                                                  func (TextDiff) Current

                                                                                                                  func (t TextDiff) Current() string

                                                                                                                    Current returns the modified value of the diff

                                                                                                                    func (TextDiff) Original

                                                                                                                    func (t TextDiff) Original() string

                                                                                                                      Original returns the unmodified value of the diff

                                                                                                                      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

                                                                                                                        func NewThunkedTask(name string) *ThunkTask

                                                                                                                          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

                                                                                                                            func (*ThunkTask) Check

                                                                                                                              Check returns a task status with thunk information

                                                                                                                              func (*ThunkTask) ToStatus

                                                                                                                              func (t *ThunkTask) ToStatus() *Status

                                                                                                                                ToStatus converts a ThunkStatus to a *Status

                                                                                                                                type Value

                                                                                                                                type Value interface{}

                                                                                                                                  Value is anything that can be in a renderer's Value