Documentation
¶
Index ¶
- Variables
- func FromContext[T Resource](rc *Context, identifier Identifier) (T, error)
- func FromState[T Resource](state *State, identifier Identifier) (T, error)
- func Provide(i *do.Injector)
- func ProvideRegistry(i *do.Injector)
- func RegisterResourceType[T Resource](registry *Registry, t Type)
- func ToResource[T Resource](data *ResourceData) (T, error)
- func TypedFromRegistry[T Resource](registry *Registry, data *ResourceData) (T, error)
- type Context
- type Event
- type EventReason
- type EventSummary
- type EventType
- type Executor
- type ExecutorType
- type Identifier
- type Plan
- type PlanOptions
- type PlanSummary
- type PlanSummaryStore
- func (s *PlanSummaryStore) DatabasePrefix(databaseID string) string
- func (s *PlanSummaryStore) DeleteByDatabaseID(databaseID string) storage.DeleteOp
- func (s *PlanSummaryStore) GetByKey(databaseID string, taskID uuid.UUID) storage.GetOp[*StoredPlanSummaries]
- func (s *PlanSummaryStore) Key(databaseID string, taskID uuid.UUID) string
- func (s *PlanSummaryStore) Prefix() string
- func (s *PlanSummaryStore) Put(item *StoredPlanSummaries) storage.PutOp[*StoredPlanSummaries]
- type RawJSON
- type Registry
- type Resource
- type ResourceData
- type Service
- func (s *Service) DeleteDatabase(ctx context.Context, databaseID string) error
- func (s *Service) GetState(ctx context.Context, databaseID string) (*State, error)
- func (s *Service) PersistPlanSummaries(ctx context.Context, databaseID string, taskID uuid.UUID, plans []PlanSummary) error
- func (s *Service) PersistState(ctx context.Context, databaseID string, state *State) error
- type State
- func (s *State) Add(data ...*ResourceData)
- func (s *State) AddResource(resources ...Resource) error
- func (s *State) Apply(event *Event) error
- func (s *State) Clone() *State
- func (s *State) CreationOrdered(ignoreMissingDeps bool) (iter.Seq[[]*ResourceData], error)
- func (s *State) DeletionOrdered(ignoreMissingDeps bool) (iter.Seq[[]*ResourceData], error)
- func (s *State) Get(identifier Identifier) (*ResourceData, bool)
- func (s *State) GetAll(resourceType Type) []*ResourceData
- func (s *State) HasResources(identifiers ...Identifier) bool
- func (s *State) MarkPendingDeletion(end *State)
- func (s *State) Merge(other *State)
- func (s *State) Plan(options PlanOptions, desired *State) (Plan, error)
- func (s *State) PlanAll(options PlanOptions, new ...*State) ([]Plan, error)
- func (s *State) PlanRefresh() (Plan, error)
- func (s *State) Remove(data *ResourceData)
- func (s *State) RemoveByIdentifier(identifier Identifier)
- type StateStore
- func (s *StateStore) DeleteByKey(databaseID string) storage.DeleteOp
- func (s *StateStore) ExistsByKey(databaseID string) storage.ExistsOp
- func (s *StateStore) GetByKey(databaseID string) storage.GetOp[*StoredState]
- func (s *StateStore) Key(databaseID string) string
- func (s *StateStore) Prefix() string
- func (s *StateStore) Put(item *StoredState) storage.PutOp[*StoredState]
- type Store
- type StoredPlanSummaries
- type StoredState
- type Type
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("resource not found")
var ErrStateNotFound = errors.New("state not found")
Functions ¶
func FromContext ¶
func FromContext[T Resource](rc *Context, identifier Identifier) (T, error)
func ProvideRegistry ¶
func RegisterResourceType ¶
func ToResource ¶
func ToResource[T Resource](data *ResourceData) (T, error)
func TypedFromRegistry ¶
func TypedFromRegistry[T Resource](registry *Registry, data *ResourceData) (T, error)
Types ¶
type Event ¶
type Event struct {
Type EventType `json:"type"`
Resource *ResourceData `json:"resource"`
Reason EventReason `json:"reason,omitempty"`
Diff jsondiff.Patch `json:"diff,omitempty"`
}
func (*Event) Summary ¶
func (e *Event) Summary() *EventSummary
func (*Event) WithData ¶
func (e *Event) WithData(data *ResourceData) *Event
WithData returns a clone of this event with the given data.
type EventReason ¶
type EventReason string
const ( EventReasonDoesNotExist EventReason = "does_not_exist" EventReasonNeedsRecreate EventReason = "needs_recreate" EventReasonHasDiff EventReason = "has_diff" EventReasonForceUpdate EventReason = "force_update" EventReasonDependencyUpdated EventReason = "dependency_updated" )
type EventSummary ¶
type EventSummary struct {
Type EventType `json:"type"`
ResourceID string `json:"resource_id"`
Reason EventReason `json:"reason,omitempty"`
Diff RawJSON `json:"diff"`
}
type Executor ¶
type Executor struct {
Type ExecutorType `json:"type"`
ID string `json:"id"`
}
Executor identifies where a resource's lifecycle methods should be executed.
func AnyExecutor ¶
func AnyExecutor() Executor
AnyExecutor will execute resource methods on any host.
func HostExecutor ¶
HostExecutor will execute resource methods on the given host.
func ManagerExecutor ¶
func ManagerExecutor() Executor
ManagerExecutor will execute resource methods on any host with cohort manager capabilities.
func PrimaryExecutor ¶
PrimaryExecutor will execute resource methods on the host that's running the primary instance for the given node.
type ExecutorType ¶
type ExecutorType string
const ( ExecutorTypeHost ExecutorType = "host" ExecutorTypePrimary ExecutorType = "primary" ExecutorTypeAny ExecutorType = "any" ExecutorTypeManager ExecutorType = "manager" )
func (ExecutorType) String ¶
func (e ExecutorType) String() string
type Identifier ¶
func (Identifier) String ¶
func (r Identifier) String() string
type PlanOptions ¶
type PlanOptions struct {
ForceUpdate bool
}
type PlanSummary ¶
type PlanSummary [][]*EventSummary
func SummarizePlans ¶
func SummarizePlans(plans []Plan) []PlanSummary
type PlanSummaryStore ¶
type PlanSummaryStore struct {
// contains filtered or unexported fields
}
func NewPlanSummaryStore ¶
func NewPlanSummaryStore(client *clientv3.Client, root string) *PlanSummaryStore
func (*PlanSummaryStore) DatabasePrefix ¶
func (s *PlanSummaryStore) DatabasePrefix(databaseID string) string
func (*PlanSummaryStore) DeleteByDatabaseID ¶
func (s *PlanSummaryStore) DeleteByDatabaseID(databaseID string) storage.DeleteOp
func (*PlanSummaryStore) GetByKey ¶
func (s *PlanSummaryStore) GetByKey(databaseID string, taskID uuid.UUID) storage.GetOp[*StoredPlanSummaries]
func (*PlanSummaryStore) Key ¶
func (s *PlanSummaryStore) Key(databaseID string, taskID uuid.UUID) string
func (*PlanSummaryStore) Prefix ¶
func (s *PlanSummaryStore) Prefix() string
func (*PlanSummaryStore) Put ¶
func (s *PlanSummaryStore) Put(item *StoredPlanSummaries) storage.PutOp[*StoredPlanSummaries]
type RawJSON ¶
type RawJSON []byte
RawJSON is a modified version of json.RawMessage that strips whitespace in its UnmarshalJSON method.
func (RawJSON) MarshalJSON ¶
func (*RawJSON) UnmarshalJSON ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
type Resource ¶
type Resource interface {
Executor() Executor
Identifier() Identifier
Dependencies() []Identifier
Refresh(ctx context.Context, rc *Context) error
Create(ctx context.Context, rc *Context) error
Update(ctx context.Context, rc *Context) error
Delete(ctx context.Context, rc *Context) error
DiffIgnore() []string
ResourceVersion() string
}
type ResourceData ¶
type ResourceData struct {
NeedsRecreate bool `json:"needs_recreate"`
Executor Executor `json:"executor"`
Identifier Identifier `json:"identifier"`
Attributes json.RawMessage `json:"attributes"`
Dependencies []Identifier `json:"dependencies"`
DiffIgnore []string `json:"diff_ignore"`
ResourceVersion string `json:"resource_version"`
PendingDeletion bool `json:"pending_deletion"`
}
func ToResourceData ¶
func ToResourceData(resource Resource) (*ResourceData, error)
func (*ResourceData) Clone ¶
func (r *ResourceData) Clone() *ResourceData
func (*ResourceData) Diff ¶
func (r *ResourceData) Diff(other *ResourceData) (jsondiff.Patch, error)
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) DeleteDatabase ¶
func (*Service) PersistPlanSummaries ¶
type State ¶
type State struct {
Resources map[Type]map[string]*ResourceData `json:"resources"`
}
func (*State) Add ¶
func (s *State) Add(data ...*ResourceData)
func (*State) AddResource ¶
func (*State) CreationOrdered ¶
CreationOrdered returns a sequence of resources in the order they should be created. In this order dependencies are returned before dependents.
func (*State) DeletionOrdered ¶
DeletionOrdered returns a sequence of resources in the order they should be deleted. In this order dependents are returned before dependencies.
func (*State) Get ¶
func (s *State) Get(identifier Identifier) (*ResourceData, bool)
func (*State) GetAll ¶
func (s *State) GetAll(resourceType Type) []*ResourceData
func (*State) HasResources ¶
func (s *State) HasResources(identifiers ...Identifier) bool
func (*State) MarkPendingDeletion ¶
MarkPendingDeletion takes an end state and marks all current resources that aren't in the end state with PendingDeletion = true.
func (*State) PlanRefresh ¶
func (*State) Remove ¶
func (s *State) Remove(data *ResourceData)
func (*State) RemoveByIdentifier ¶
func (s *State) RemoveByIdentifier(identifier Identifier)
type StateStore ¶
type StateStore struct {
// contains filtered or unexported fields
}
func NewStateStore ¶
func NewStateStore(client *clientv3.Client, root string) *StateStore
func (*StateStore) DeleteByKey ¶
func (s *StateStore) DeleteByKey(databaseID string) storage.DeleteOp
func (*StateStore) ExistsByKey ¶
func (s *StateStore) ExistsByKey(databaseID string) storage.ExistsOp
func (*StateStore) GetByKey ¶
func (s *StateStore) GetByKey(databaseID string) storage.GetOp[*StoredState]
func (*StateStore) Key ¶
func (s *StateStore) Key(databaseID string) string
func (*StateStore) Prefix ¶
func (s *StateStore) Prefix() string
func (*StateStore) Put ¶
func (s *StateStore) Put(item *StoredState) storage.PutOp[*StoredState]
type Store ¶
type Store struct {
State *StateStore
PlanSummaries *PlanSummaryStore
// contains filtered or unexported fields
}
type StoredPlanSummaries ¶
type StoredPlanSummaries struct {
storage.StoredValue
DatabaseID string `json:"database_id"`
TaskID uuid.UUID `json:"task_id"`
Plans []PlanSummary `json:"plans"`
}
type StoredState ¶
type StoredState struct {
storage.StoredValue
DatabaseID string `json:"database_id"`
State *State `json:"state"`
}