service

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStore

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

FileStore persists services to disk as JSON files under a root directory.

func NewFileStore

func NewFileStore(dir string) (*FileStore, error)

NewFileStore creates a new FileStore rooted at dir.

func (*FileStore) Delete

func (s *FileStore) Delete(name string) error

Delete removes a service directory from disk.

func (*FileStore) Get

func (s *FileStore) Get(name string) (*Service, error)

Get reads a service by name from disk.

func (*FileStore) List

func (s *FileStore) List() ([]*Service, error)

List returns all services from disk.

func (*FileStore) Save

func (s *FileStore) Save(svc *Service) error

Save writes a service to disk.

type Info

type Info struct {
	Name            string   `json:"name"`
	Image           string   `json:"image"`
	DesiredReplicas int      `json:"desired_replicas"`
	ReadyReplicas   int      `json:"ready_replicas"`
	Strategy        string   `json:"strategy"`
	Health          string   `json:"health"`
	Env             []string `json:"env,omitempty"`
	CreatedAt       string   `json:"created_at"`
	UpdatedAt       string   `json:"updated_at"`
	ReplicaIDs      []string `json:"replica_ids"`
}

Info is the serialisable representation of a service for API responses.

type Manager

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

Manager manages service lifecycle: creation, scaling, updates, and removal.

func NewManager

func NewManager(mgr vm.Manager, store StoreInterface) *Manager

NewManager creates a new service Manager backed by the given VM manager and store.

func (*Manager) Get

func (m *Manager) Get(name string) (*Service, error)

Get returns a service by name.

func (*Manager) List

func (m *Manager) List() ([]*Service, error)

List returns all services.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, name string) error

Remove stops all replicas of a service and deletes it.

func (*Manager) Replicas

func (m *Manager) Replicas(name string) []*vm.VM

Replicas returns the VM replicas belonging to a service.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, name, image string, replicas int, opts Options) (*Service, error)

Run creates a service with the desired number of replicas and starts them.

func (*Manager) Scale

func (m *Manager) Scale(ctx context.Context, name string, desiredReplicas int) (*Service, error)

Scale adjusts the number of replicas for a service to the desired count.

func (*Manager) ServiceInfo

func (m *Manager) ServiceInfo(svc *Service) Info

ServiceInfo builds an Info from a Service and its live replicas.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, name, newImage string, healthTimeout time.Duration) (*Service, error)

Update performs a rolling update of the service to a new image. If healthTimeout > 0, it waits for new replicas to become healthy before removing old ones.

type Options

type Options struct {
	Memory        string
	CPUs          int
	Env           []string
	PortMaps      []vm.PortMap
	NetworkName   string
	HealthCheck   *vm.HealthCheckConfig
	Restart       vm.RestartConfig
	Strategy      Strategy
	HealthTimeout time.Duration
}

Options contains optional parameters for creating a service.

type ReplicaInfo

type ReplicaInfo struct {
	ID     string          `json:"id"`
	Name   string          `json:"name"`
	State  vm.State        `json:"state"`
	Health vm.HealthStatus `json:"health"`
	IP     string          `json:"ip,omitempty"`
}

ReplicaInfo describes a single replica within a service.

type Service

type Service struct {
	// Name is the unique service identifier.
	Name string
	// Image is the unikernel image reference (e.g. "myapp:latest").
	Image string
	// DesiredReplicas is the target number of running replicas.
	DesiredReplicas int
	// Strategy controls how updates are applied.
	Strategy Strategy
	// HealthTimeout is the maximum duration to wait for new replicas to
	// become healthy during rolling updates. Zero means no waiting.
	HealthTimeout time.Duration
	// Config holds the VM configuration template used for each replica.
	Config vm.Config
	// CreatedAt is the timestamp when the service was created.
	CreatedAt time.Time
	// UpdatedAt is the timestamp when the service was last updated.
	UpdatedAt time.Time
}

Service represents a group of VM replicas managed as a single unit.

type StoreInterface

type StoreInterface interface {
	Save(svc *Service) error
	Get(name string) (*Service, error)
	List() ([]*Service, error)
	Delete(name string) error
}

StoreInterface is the interface for persisting and retrieving services.

type Strategy

type Strategy string

Strategy determines how updates are applied to a service's replicas.

const (
	// StrategyRollingUpdate creates new replicas before removing old ones.
	StrategyRollingUpdate Strategy = "RollingUpdate"
	// StrategyRecreate stops all replicas before starting new ones.
	StrategyRecreate Strategy = "Recreate"
)

Jump to

Keyboard shortcuts

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