resource

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2025 License: PostgreSQL Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("resource not found")
View Source
var ErrStateNotFound = errors.New("state not found")

Functions

func FromContext

func FromContext[T Resource](rc *Context, identifier Identifier) (T, error)

func FromState

func FromState[T Resource](state *State, identifier Identifier) (T, error)

func Provide

func Provide(i *do.Injector)

func ProvideRegistry

func ProvideRegistry(i *do.Injector)

func RegisterResourceType

func RegisterResourceType[T Resource](registry *Registry, t Type)

func ToResource

func ToResource[T Resource](data *ResourceData) (T, error)

func TypedFromRegistry

func TypedFromRegistry[T Resource](registry *Registry, data *ResourceData) (T, error)

Types

type Context

type Context struct {
	State    *State
	Registry *Registry
	Injector *do.Injector
}

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 EventType

type EventType string
const (
	EventTypeRefresh EventType = "refresh"
	EventTypeCreate  EventType = "create"
	EventTypeUpdate  EventType = "update"
	EventTypeDelete  EventType = "delete"
)

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

func HostExecutor(hostID string) Executor

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

func PrimaryExecutor(nodeName string) Executor

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

type Identifier struct {
	ID   string `json:"id"`
	Type Type   `json:"type"`
}

func (Identifier) String

func (r Identifier) String() string

type Plan

type Plan [][]*Event

func (Plan) Summary

func (p Plan) Summary() PlanSummary

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

type RawJSON

type RawJSON []byte

RawJSON is a modified version of json.RawMessage that strips whitespace in its UnmarshalJSON method.

func (RawJSON) MarshalJSON

func (a RawJSON) MarshalJSON() ([]byte, error)

func (*RawJSON) UnmarshalJSON

func (a *RawJSON) UnmarshalJSON(data []byte) error

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Resource

func (r *Registry) Resource(data *ResourceData) (Resource, error)

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 NewService(store *Store) *Service

func (*Service) DeleteDatabase

func (s *Service) DeleteDatabase(ctx context.Context, databaseID string) error

func (*Service) GetState

func (s *Service) GetState(ctx context.Context, databaseID string) (*State, error)

func (*Service) PersistPlanSummaries

func (s *Service) PersistPlanSummaries(ctx context.Context, databaseID string, taskID uuid.UUID, plans []PlanSummary) error

func (*Service) PersistState

func (s *Service) PersistState(ctx context.Context, databaseID string, state *State) error

type State

type State struct {
	Resources map[Type]map[string]*ResourceData `json:"resources"`
}

func NewState

func NewState() *State

func (*State) Add

func (s *State) Add(data ...*ResourceData)

func (*State) AddResource

func (s *State) AddResource(resources ...Resource) error

func (*State) Apply

func (s *State) Apply(event *Event) error

func (*State) Clone

func (s *State) Clone() *State

func (*State) CreationOrdered

func (s *State) CreationOrdered(ignoreMissingDeps bool) (iter.Seq[[]*ResourceData], error)

CreationOrdered returns a sequence of resources in the order they should be created. In this order dependencies are returned before dependents.

func (*State) DeletionOrdered

func (s *State) DeletionOrdered(ignoreMissingDeps bool) (iter.Seq[[]*ResourceData], error)

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

func (s *State) MarkPendingDeletion(end *State)

MarkPendingDeletion takes an end state and marks all current resources that aren't in the end state with PendingDeletion = true.

func (*State) Merge

func (s *State) Merge(other *State)

func (*State) Plan

func (s *State) Plan(options PlanOptions, desired *State) (Plan, error)

func (*State) PlanAll

func (s *State) PlanAll(options PlanOptions, new ...*State) ([]Plan, error)

func (*State) PlanRefresh

func (s *State) PlanRefresh() (Plan, error)

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

type Store

type Store struct {
	State         *StateStore
	PlanSummaries *PlanSummaryStore
	// contains filtered or unexported fields
}

func NewStore

func NewStore(client *clientv3.Client, root string) *Store

func (*Store) Txn

func (s *Store) Txn(ops ...storage.TxnOperation) storage.Txn

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"`
}

type Type

type Type string

func (Type) String

func (r Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL