operator

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplyResourceRequestDelete    = "delete"
	ApplyResourceRequestReconcile = "reconcile"
)

Variables

View Source
var (
	ErrInstanceAlreadyRunning  = fmt.Errorf("instance already running")
	ErrProviderNameAlreadyUsed = fmt.Errorf("name already used")
)
View Source
var ErrResourceNotFound = fmt.Errorf("resource not found")

Functions

This section is empty.

Types

type ApplyResourceRequest added in v0.1.3

type ApplyResourceRequest struct {
	Deployment *proto.Deployment
	Resource   *proto.ResourceSpec
	Action     string
}

type BaseOperator added in v0.1.3

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

func (*BaseOperator) ApplyNodes added in v0.1.3

func (b *BaseOperator) ApplyNodes(place []*proto.Instance, cluster []*proto.Instance) ([]*proto.Instance, error)

func (*BaseOperator) ApplyResource added in v0.1.3

func (b *BaseOperator) ApplyResource(req *ApplyResourceRequest) error

func (*BaseOperator) Client added in v0.1.3

func (b *BaseOperator) Client(node *proto.Instance) (interface{}, error)

func (*BaseOperator) Evaluate added in v0.1.3

func (b *BaseOperator) Evaluate(comp *proto.Component) (*proto.Component, error)

func (*BaseOperator) GetSchemas added in v0.1.3

func (b *BaseOperator) GetSchemas() GetSchemasResponse

func (*BaseOperator) SetHandler added in v0.1.3

func (b *BaseOperator) SetHandler(h Handler2)

func (*BaseOperator) Setup added in v0.1.3

func (b *BaseOperator) Setup(cplane ControlPlane)

type CallbackRequest added in v0.1.3

type CallbackRequest struct {
	Client interface{}
	Data   *schema.ResourceData
}

func (*CallbackRequest) Get added in v0.1.3

func (c *CallbackRequest) Get(s string) interface{}

type Config

type Config struct {
	// Provider is the provider used by the operator
	Provider Provider

	// State is the state access
	State *boltdb.BoltDB

	// Backends are the list of backends handled by the operator
	HandlerFactories []HandlerFactory

	// GRPCAddr is the address of the grpc server
	GRPCAddr *net.TCPAddr
}

Config is the parametrization of the operator server

type ControlPlane added in v0.1.3

type ControlPlane interface {
	UpsertInstance(*proto.Instance) error
	GetInstance(instanceID string) (*proto.Instance, error)
	SubscribeInstanceUpdates() <-chan *InstanceUpdate
}

type GetSchemasResponse added in v0.1.3

type GetSchemasResponse struct {
	Nodes     map[string]schema.Schema2
	Resources map[string]schema.Schema2
}

type Handler

type Handler interface {
	// Name returns the name of the handler (TODO. it can be removed later)
	Name() string

	// Setup starts the backend and passes the control plane reference
	Setup(cplane ControlPlane)

	// Evaluate evaluates a component schema
	Evaluate(comp *proto.Component) (*proto.Component, error)

	// GetSchemas returns the schemas for the backend
	GetSchemas() GetSchemasResponse

	// ApplyNodes applies to the spec the changes required
	ApplyNodes(n []*proto.Instance, cluster []*proto.Instance) ([]*proto.Instance, error)

	// ApplyResource applies a resource change
	ApplyResource(req *ApplyResourceRequest) error
}

Handler is the interface that needs to be implemented by the backend

type Handler2 added in v0.1.3

type Handler2 interface {
	Spec() *Spec
	Initialize(n []*proto.Instance, target *proto.Instance) (*proto.NodeSpec, error)
	Client(node *proto.Instance) (interface{}, error)
}

type HandlerFactory

type HandlerFactory func() Handler

HandlerFactory is a factory for Handlers

type Harness added in v0.1.3

type Harness struct {
	Deployment *proto.Deployment
	Handler    Handler
	Scheduler  Scheduler
	Component  *proto.Component
	// contains filtered or unexported fields
}

func NewHarness added in v0.1.3

func NewHarness(t assert.TestingT) *Harness

func (*Harness) AddComponent added in v0.1.3

func (h *Harness) AddComponent(c *proto.Component)

func (*Harness) ApplyDep added in v0.1.3

func (h *Harness) ApplyDep(plan *proto.Plan, callback func(i *proto.Instance)) *proto.Deployment

func (*Harness) Eval added in v0.1.3

func (h *Harness) Eval() *proto.Plan

func (*Harness) Expect added in v0.1.3

func (h *Harness) Expect(plan *proto.Plan, expect *HarnessExpect)

func (*Harness) GetComponentByID added in v0.1.3

func (h *Harness) GetComponentByID(dep, id string, sequence int64) (*proto.Component, error)

func (*Harness) GetHandler added in v0.1.3

func (h *Harness) GetHandler(id string) (Handler, error)

func (*Harness) LoadDeployment added in v0.1.3

func (h *Harness) LoadDeployment(id string) (*proto.Deployment, error)

type HarnessExpect added in v0.1.3

type HarnessExpect struct {
	Status string
	Nodes  []*HarnessExpectInstance
}

type HarnessExpectInstance added in v0.1.3

type HarnessExpectInstance struct {
	Name   string
	KV     map[string]string
	Status proto.Instance_Status
	Spec   *proto.NodeSpec
}

type InmemControlPlane added in v0.1.3

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

func (*InmemControlPlane) GetInstance added in v0.1.3

func (i *InmemControlPlane) GetInstance(InstanceID string) (*proto.Instance, error)

func (*InmemControlPlane) SubscribeInstanceUpdates added in v0.1.3

func (i *InmemControlPlane) SubscribeInstanceUpdates() <-chan *InstanceUpdate

func (*InmemControlPlane) UpsertInstance added in v0.1.3

func (i *InmemControlPlane) UpsertInstance(ii *proto.Instance) error

type InstanceUpdate added in v0.1.3

type InstanceUpdate struct {
	InstanceID string
}

type Nodetype

type Nodetype struct {
	// Image is the default docker image for the node
	Image string

	// Config is the configuration fields for this node type
	Config interface{} // out

	Schema schema.Schema2

	// Version is the default docker image for the node
	DefaultVersion string

	// Volume is a list volumes for this node type
	Volumes []*Volume

	// Ports is a list of ports for this node type
	Ports []*Port
}

Nodetype is a type of node for the Backend

type Port

type Port struct {
	Name        string
	Port        uint64
	Description string
}

Port is an exposed port for the node

type Provider

type Provider interface {
	// Setup setups the provider (Maybe do this on the factory)
	Setup(ControlPlane) error

	// Start starts the provider
	Start() error

	Stop() error

	// Exec executes a shell script
	Exec(handler string, path string, args ...string) (string, error)

	// Resources returns a struct that defines the node resources
	// that can be configured for this provider
	Resources() ProviderResources

	Name() string
}

Provider is the entity that holds the state of the infrastructure. Both for the computing resources and the general resources.

type ProviderFactory

type ProviderFactory func(map[string]interface{}) error

ProviderFactory is a factory method to create factories

type ProviderResources added in v0.1.3

type ProviderResources struct {
	Resources schema.Schema2
	Storage   schema.Schema2
}

type Resource

type Resource interface {
	GetName() string
	Delete(conn interface{}) error
	Reconcile(conn interface{}) error
	Init(spec map[string]interface{}) error
}

Resource is a resource in the cluster

type Resource2 added in v0.1.3

type Resource2 struct {
	Name     string
	Schema   schema.Schema2
	DeleteFn func(req *CallbackRequest) error
	ApplyFn  func(req *CallbackRequest) error
}

type ResourceScheduler added in v0.1.3

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

func (*ResourceScheduler) Process added in v0.1.3

func (r *ResourceScheduler) Process(eval *proto.Evaluation) (*proto.Plan, error)

type Scheduler added in v0.1.3

type Scheduler interface {
	Process(eval *proto.Evaluation) (*proto.Plan, error)
}

func NewScheduler added in v0.1.3

func NewScheduler(state schedState) Scheduler

type Server

type Server struct {
	Provider Provider
	State    *boltdb.BoltDB
	// contains filtered or unexported fields
}

Server is the operator server

func NewServer

func NewServer(logger hclog.Logger, config *Config) (*Server, error)

NewServer starts an instance of the operator server

func (*Server) Config added in v0.1.1

func (s *Server) Config() *Config

func (*Server) Exec

func (s *Server) Exec(n *proto.Instance, path string, cmd ...string) (string, error)

Exec implements the Activator interface

func (*Server) GetComponentByID added in v0.1.3

func (s *Server) GetComponentByID(deployment, compID string, sequence int64) (*proto.Component, error)

func (*Server) GetHandler added in v0.1.3

func (s *Server) GetHandler(id string) (Handler, error)

func (*Server) GetInstance added in v0.1.3

func (s *Server) GetInstance(instanceID string) (*proto.Instance, error)

func (*Server) LoadDeployment added in v0.1.3

func (s *Server) LoadDeployment(id string) (*proto.Deployment, error)

func (*Server) Stop

func (s *Server) Stop()

Stop stops the server

func (*Server) SubmitPlan added in v0.1.3

func (s *Server) SubmitPlan(eval *proto.Evaluation, p *proto.Plan) error

func (*Server) SubscribeInstanceUpdates added in v0.1.3

func (s *Server) SubscribeInstanceUpdates() <-chan *InstanceUpdate

func (*Server) UpsertInstance added in v0.1.3

func (s *Server) UpsertInstance(n *proto.Instance) error

type Spec

type Spec struct {
	Name      string // out
	Nodetypes map[string]Nodetype
	Resources []*Resource2
	Validate  func(comp *proto.Component) (*proto.Component, error)
	Handlers  map[string]func(spec *proto.NodeSpec, grp *proto.ClusterSpec_Group, data *schema.ResourceData)
	Startup   func(i *proto.Instance) error
}

Spec returns the backend specification

type Volume

type Volume struct {
	Name        string
	Path        string
	Description string
}

Volume is a mounted path for the node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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