provision

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package provision exposes the Engine type. Engine is a fully configurable type that can be used to implement custom provisioning of workloads

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetContract

func GetContract(ctx context.Context) substrate.NodeContract

GetContract of deployment. panics if engine has no substrate set.

func GetDeployment

func GetDeployment(ctx context.Context) (gridtypes.Deployment, error)

GetDeployment gets a copy of the current deployment with latest state

func GetDeploymentID

func GetDeploymentID(ctx context.Context) (twin uint32, deployment uint64)

GetDeploymentID gets twin and deployment ID for current deployment

func GetEngine

func GetEngine(ctx context.Context) provision.Engine

GetEngine gets engine from context

func GetWorkload

func GetWorkload(ctx context.Context, name gridtypes.Name) (gridtypes.WorkloadWithID, error)

GetWorkload get the last state of the workload for the current deployment

func IsRentedNode

func IsRentedNode(ctx context.Context) bool

IsRentedNode returns true if current node is rented

func NewMapProvisioner

func NewMapProvisioner(managers map[gridtypes.WorkloadType]Manager) provision.Provisioner

NewMapProvisioner returns a new instance of a map provisioner

func NewRegistrarAdmins

func NewRegistrarAdmins(registrarGateway *stubs.RegistrarGatewayStub, farmID uint64) (provision.Twins, error)

NewRegistrarAdmins creates a twins db that implements the provision.Users interface. but it also make sure the user is an admin

func NewRegistrarTwins

func NewRegistrarTwins(registrarGateway *stubs.RegistrarGatewayStub) (provision.Twins, error)

NewRegistrarTwins creates a users db that implements the provision.Users interface.

Types

type Callback

type Callback func(twin uint32, contract uint64, delete bool)

type EngineOption

type EngineOption interface {
	// contains filtered or unexported methods
}

EngineOption interface

func WithAPIGateway

func WithAPIGateway(node uint64, registrarGateway *stubs.RegistrarGatewayStub) EngineOption

WithAPIGateway sets the API Gateway. If set it will be used by the engine to fetch (and validate) the deployment contract then contract with be available on the deployment context

func WithAdmins

func WithAdmins(g provision.Twins) EngineOption

WithAdmins sets the admins key getter on the engine

func WithCallback

func WithCallback(cb Callback) EngineOption

WithCallback sets a callback that is called when a deployment is being Created, Updated, Or Deleted The handler then can use the id to get current "state" of the deployment from storage and take proper action. A callback must not block otherwise the engine operation will get blocked

func WithRerunAll

func WithRerunAll(t bool) EngineOption

WithRerunAll if set forces the engine to re-run all reservations on engine start.

func WithStartupOrder

func WithStartupOrder(t ...gridtypes.WorkloadType) EngineOption

WithStartupOrder forces a specific startup order of types any type that is not listed in this list, will get started in an nondeterministic order

func WithTwins

func WithTwins(g provision.Twins) EngineOption

WithTwins sets the user key getter on the engine

type Initializer

type Initializer interface {
	Initialize(ctx context.Context) error
}

Initializer interface define an extra Initialize method which is run on the provisioner before the provision engine is started.

type Manager

type Manager interface {
	Provision(ctx context.Context, wl *gridtypes.WorkloadWithID) (interface{}, error)
	Deprovision(ctx context.Context, wl *gridtypes.WorkloadWithID) error
}

Manager defines basic type manager functionality. This interface declares the provision and the deprovision method which is required by any Type manager.

type NativeEngine

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

NativeEngine is the core of this package The engine is responsible to manage provision and decomission of workloads on the system

func New

func New(storage provision.Storage, provisioner provision.Provisioner, root string, opts ...EngineOption) (*NativeEngine, error)

New creates a new engine. Once started, the engine will continue processing all reservations from the reservation source and try to apply them. the default implementation is a single threaded worker. so it process one reservation at a time. On error, the engine will log the error. and continue to next reservation.

func (*NativeEngine) Admins

func (e *NativeEngine) Admins() provision.Twins

Admins returns admins db

func (*NativeEngine) Changes

func (n *NativeEngine) Changes(twin uint32, contractID uint64) ([]gridtypes.Workload, error)

func (*NativeEngine) CreateOrUpdate

func (n *NativeEngine) CreateOrUpdate(twin uint32, deployment gridtypes.Deployment, update bool) error

func (*NativeEngine) DecommissionCached

func (e *NativeEngine) DecommissionCached(id string, reason string) error

DecommissionCached implements the zbus interface

func (*NativeEngine) Deprovision

func (e *NativeEngine) Deprovision(ctx context.Context, twin uint32, id uint64, reason string) error

Deprovision workload

func (*NativeEngine) Get

func (n *NativeEngine) Get(twin uint32, contractID uint64) (gridtypes.Deployment, error)

func (*NativeEngine) GetWorkloadStatus

func (e *NativeEngine) GetWorkloadStatus(id string) (gridtypes.ResultState, bool, error)

GetWorkloadStatus get workload status, returns status, exists, error

func (*NativeEngine) List

func (n *NativeEngine) List(twin uint32) ([]gridtypes.Deployment, error)

func (*NativeEngine) ListPrivateIPs

func (n *NativeEngine) ListPrivateIPs(twin uint32, network gridtypes.Name) ([]string, error)

func (*NativeEngine) ListPublicIPs

func (n *NativeEngine) ListPublicIPs() ([]string, error)

func (*NativeEngine) Pause

func (e *NativeEngine) Pause(ctx context.Context, twin uint32, id uint64) error

Pause deployment

func (*NativeEngine) Provision

func (e *NativeEngine) Provision(ctx context.Context, deployment gridtypes.Deployment) error

Provision workload

func (*NativeEngine) Resume

func (e *NativeEngine) Resume(ctx context.Context, twin uint32, id uint64) error

Resume deployment

func (*NativeEngine) Run

func (e *NativeEngine) Run(root context.Context) error

Run starts reader reservation from the Source and handle them

func (*NativeEngine) Storage

func (e *NativeEngine) Storage() provision.Storage

Storage returns

func (*NativeEngine) Twins

func (e *NativeEngine) Twins() provision.Twins

Twins returns twins db

func (*NativeEngine) Update

func (e *NativeEngine) Update(ctx context.Context, update gridtypes.Deployment) error

Update workloads

type Pauser

type Pauser interface {
	Pause(ctx context.Context, wl *gridtypes.WorkloadWithID) error
	Resume(ctx context.Context, wl *gridtypes.WorkloadWithID) error
}

Pauser defines optional Pause, Resume method for type managers. Types are allowed to implement pause, resume to put the workload in paused state where it's not usable by the user but at the same time not completely deleted.

type Response

type Response interface {
	error
	// contains filtered or unexported methods
}

func Ok

func Ok() Response

Ok response. you normally don't need to return this from Manager methods. instead returning `nil` error is preferred.

func Paused

func Paused() Response

func UnChanged

func UnChanged(cause error) Response

UnChanged is a special response status that states that an operation has failed but this did not affect the workload status. Usually during an update when the update could not carried out, but the workload is still running correctly with previous config

type Updater

type Updater interface {
	Update(ctx context.Context, wl *gridtypes.WorkloadWithID) (interface{}, error)
}

Updater defines the optional Update method for a type manager. Types are allowed to implement update to change their settings on the fly

Jump to

Keyboard shortcuts

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