module

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateAction = "create"
	UpdateAction = "update"
	DeleteAction = "delete"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionDesc

type ActionDesc struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	ParamSchema string `json:"param_schema"`
	// contains filtered or unexported fields
}

ActionDesc is a descriptor for an action supported by a module.

func (*ActionDesc) Sanitise added in v0.1.3

func (ad *ActionDesc) Sanitise() error

Sanitise cleans action description by removing whitespaces, checking parameter-schema etc.

type ActionRequest

type ActionRequest struct {
	Name   string            `json:"name"`
	Params json.RawMessage   `json:"params"`
	Labels map[string]string `json:"labels"`
}

ActionRequest describes an invocation of action on module.

type Descriptor

type Descriptor struct {
	Kind          string                                     `json:"kind"`
	Actions       []ActionDesc                               `json:"actions"`
	Dependencies  map[string]string                          `json:"dependencies"`
	DriverFactory func(conf json.RawMessage) (Driver, error) `json:"-"`
}

Descriptor is a module descriptor that represents supported actions, resource-kind the module can operate on, etc.

type Driver added in v0.1.3

type Driver interface {
	// Plan SHOULD validate the action on the current version of the resource,
	// return the resource with config/status/state changes (if any) applied.
	// Plan SHOULD NOT have side effects on anything other than the resource.
	Plan(ctx context.Context, res ExpandedResource, act ActionRequest) (*Plan, error)

	// Sync is called repeatedly by Entropy core until the returned state is
	// a terminal status. Driver implementation is free to execute an action
	// in a single Sync() call or split into steps for better feedback to the
	// end-user about the progress.
	// Sync can return state in resource.StatusDeleted to indicate resource
	// should be removed from the Entropy storage.
	Sync(ctx context.Context, res ExpandedResource) (*resource.State, error)

	// Output returns the current external state of the resource
	// Output should not have any side effects on any external resource
	Output(ctx context.Context, res ExpandedResource) (json.RawMessage, error)
}

Driver is responsible for achieving desired external system states based on a resource in Entropy.

type ExpandedResource added in v0.1.3

type ExpandedResource struct {
	resource.Resource `json:"resource"`

	Dependencies map[string]ResolvedDependency `json:"dependencies"`
}

ExpandedResource represents the context for Plan() or Sync() invocations.

type LogChunk

type LogChunk struct {
	Data   []byte            `json:"data"`
	Labels map[string]string `json:"labels"`
}

type Loggable

type Loggable interface {
	Driver

	Log(ctx context.Context, res ExpandedResource, filter map[string]string) (<-chan LogChunk, error)
}

Loggable extension of driver allows streaming log data for a resource.

type Module

type Module struct {
	URN       string          `json:"urn"`
	Name      string          `json:"name"`
	Project   string          `json:"project"`
	Configs   json.RawMessage `json:"configs"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
}

Module represents all the data needed to initialize a particular module.

type Plan added in v0.1.3

type Plan struct {
	Resource      resource.Resource
	ScheduleRunAt time.Time
	Reason        string
}

Plan represents the changes to be staged and later synced by module.

type Registry

type Registry interface {
	GetDriver(ctx context.Context, mod Module) (Driver, Descriptor, error)
}

Registry is responsible for installing and managing module-drivers as per module definitions provided.

type ResolvedDependency

type ResolvedDependency struct {
	Kind   string          `json:"kind"`
	Output json.RawMessage `json:"output"`
}

type Service added in v0.1.3

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

func NewService added in v0.1.3

func NewService(registry Registry, store Store) *Service

func (*Service) CreateModule added in v0.1.3

func (mr *Service) CreateModule(ctx context.Context, mod Module) (*Module, error)

func (*Service) DeleteModule added in v0.1.3

func (mr *Service) DeleteModule(ctx context.Context, urn string) error

func (*Service) GetModule added in v0.1.3

func (mr *Service) GetModule(ctx context.Context, urn string) (*Module, error)

func (*Service) GetOutput added in v0.1.3

func (mr *Service) GetOutput(ctx context.Context, res ExpandedResource) (json.RawMessage, error)

func (*Service) ListModules added in v0.1.3

func (mr *Service) ListModules(ctx context.Context, project string) ([]Module, error)

func (*Service) PlanAction added in v0.1.3

func (mr *Service) PlanAction(ctx context.Context, res ExpandedResource, act ActionRequest) (*Plan, error)

func (*Service) StreamLogs added in v0.1.3

func (mr *Service) StreamLogs(ctx context.Context, res ExpandedResource, filter map[string]string) (<-chan LogChunk, error)

func (*Service) SyncState added in v0.1.3

func (mr *Service) SyncState(ctx context.Context, res ExpandedResource) (*resource.State, error)

func (*Service) UpdateModule added in v0.1.3

func (mr *Service) UpdateModule(ctx context.Context, urn string, newConfigs json.RawMessage) (*Module, error)

type Store added in v0.1.3

type Store interface {
	GetModule(ctx context.Context, urn string) (*Module, error)
	ListModules(ctx context.Context, project string) ([]Module, error)
	CreateModule(ctx context.Context, m Module) error
	UpdateModule(ctx context.Context, m Module) error
	DeleteModule(ctx context.Context, urn string) error
}

Store is responsible for persisting modules defined for each project.

Jump to

Keyboard shortcuts

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