module

package
v0.2.12-rc Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 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

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

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

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) (*resource.Resource, 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

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

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

func NewService

func NewService(registry Registry, store Store) *Service

func (*Service) CreateModule

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

func (*Service) DeleteModule

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

func (*Service) GetModule

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

func (*Service) GetOutput

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

func (*Service) ListModules

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

func (*Service) PlanAction

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

func (*Service) StreamLogs

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

func (*Service) SyncState

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

func (*Service) UpdateModule

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

type Store

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