storageclass

package
v1.10.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package storageclass manages the admin-registered directories where Miabi creates volumes. A class inverts the host-path trust model: the tenant names a class, the platform derives the path, so an unprivileged workspace can use operator storage without ever supplying a host path.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrImmutable is returned when an update tries to change a class's name or path. Both are
	// dereferenced rather than displayed — volumes and GitOps manifests point at the name, and
	// volumes already exist under the path — so a rewrite would break references, or silently
	// point live volumes at a directory their data is not in.
	ErrImmutable = errors.New("a storage class name and path cannot be changed after registration; register a new class instead")
	// ErrBuiltin is returned when an admin tries to delete or re-path the seeded default class.
	ErrBuiltin = errors.New("the built-in default storage class cannot be modified or deleted")
	// ErrInUse is returned when deleting a class that volumes still reference.
	ErrInUse = errors.New("storage class is in use by one or more volumes")
	// ErrNameTaken is returned when registering a class whose name is already taken.
	ErrNameTaken = errors.New("a storage class with this name already exists")
	// ErrDisabled is returned when creating a volume on a class an admin has turned off.
	ErrDisabled = errors.New("storage class is disabled")
	// ErrNotOnNode is returned when a class belongs to another node than the one a volume is placed on.
	ErrNotOnNode = errors.New("storage class is not available on this node")
	// ErrPathMissing is returned when the class path does not exist on its node.
	ErrPathMissing = errors.New("storage class path does not exist on the node")
	// ErrNotFound is returned when no class matches a name.
	ErrNotFound = errors.New("storage class not found")
	// ErrNameRequired and ErrPathRequired guard the create form.
	ErrNameRequired = errors.New("storage class name is required")
	ErrPathRequired = errors.New("storage class path is required")
)

Errors the handlers map to 4xx responses.

Functions

This section is empty.

Types

type ImageResolver

type ImageResolver interface {
	Ref(key string) string
}

ImageResolver resolves a deployment-config catalog key to an image ref.

type Input

type Input struct {
	Name          string
	DisplayName   string
	Description   string
	ServerID      uint
	ClusterID     uint
	Path          string
	Shared        bool
	IsDefault     bool
	Enabled       bool
	ReclaimPolicy models.ReclaimPolicy
}

Input is the editable surface of a storage class. Name, Path and ServerID are read on create only; Update refuses a change to Name or Path.

type NodeDocker

type NodeDocker interface {
	For(serverID uint) (docker.Client, error)
	LocalID() uint
}

NodeDocker resolves the Docker client for a node id (0 = local).

type ServerInfo

type ServerInfo interface {
	Get(id uint) (*models.Server, error)
}

ServerInfo resolves a node's display metadata by id (optional).

type Service

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

Service manages storage classes and the node-side directories they own.

func NewService

func NewService(repo *repositories.StorageClassRepository, clients NodeDocker) *Service

func (*Service) Count added in v1.10.5

func (s *Service) Count() (int64, error)

Count reports the size of the class catalog, for the edition cap.

func (*Service) Create

func (s *Service) Create(ctx context.Context, in Input) (*models.StorageClass, error)

Create registers a class after validating its path and probing the node for it. The probe is the point of the design: a class whose disk is not mounted fails here, naming the node, instead of at some tenant's first deploy.

func (*Service) Delete

func (s *Service) Delete(id uint) error

Delete removes a class. The built-in one is permanent, and a class still referenced by volumes is refused: disabling it is how an admin stops new volumes landing there without touching old ones.

func (*Service) DiskUsageAll

func (s *Service) DiskUsageAll(ctx context.Context, c *models.StorageClass) (map[string]int64, error)

DiskUsageAll measures every volume directory under a class in one helper run, keyed by Docker volume name. `docker system df` sizes a bind-backed volume's mountpoint stub rather than the data behind the bind, so a managed class is measured here instead.

func (*Service) EnsureBuiltin

func (s *Service) EnsureBuiltin() error

EnsureBuiltin seeds the "default" class: volumes created the way Docker creates them, in the engine's own data root. Every install has it, every pre-existing volume backfills to it, and it is what makes this feature a no-op for an install that registers no classes of its own.

func (*Service) EnsureDir

func (s *Service) EnsureDir(ctx context.Context, c *models.StorageClass, dockerName string) error

EnsureDir creates the per-volume directory under the class path on the node. Docker accepts a bind-backed volume whose device is absent and only fails when a container mounts it, so this runs before the volume is created.

func (*Service) Get

func (s *Service) Get(id uint) (*models.StorageClass, error)

Get returns one class by id.

func (*Service) List

func (s *Service) List() ([]models.StorageClass, error)

List returns every registered class, node-annotated.

func (*Service) ListForNode

func (s *Service) ListForNode(serverID uint) ([]models.StorageClass, error)

ListForNode returns the classes usable on a node: its own, plus every shared one.

func (*Service) ListManaged

func (s *Service) ListManaged() ([]models.StorageClass, error)

ListManaged returns the enabled classes that own a path, i.e. the ones with data to measure.

func (*Service) MeasureCapacity

func (s *Service) MeasureCapacity(ctx context.Context) error

MeasureCapacity refreshes every managed class's filesystem capacity. Best-effort: an unreachable node keeps its previous measurement, and the sweep always returns nil so cron does not retry.

func (*Service) Probe

func (s *Service) Probe(ctx context.Context, c *models.StorageClass) error

Probe verifies the class path exists on its node by binding it into a helper container with NoCreate set: the daemon refuses a missing source rather than creating an empty directory, which is what stops an unmounted disk from silently becoming a directory on the root filesystem. It records the filesystem's capacity while it is there.

func (*Service) RemoveDir

func (s *Service) RemoveDir(ctx context.Context, c *models.StorageClass, dockerName string) error

RemoveDir deletes the volume's directory under the class path. `docker volume rm` leaves a bind-backed volume's data on the disk, so without this a deleted volume would orphan every byte it held on the operator's storage. A retain-policy class keeps it for an admin to reclaim.

func (*Service) Resolve

func (s *Service) Resolve(serverID uint, name string) (*models.StorageClass, error)

Resolve returns the class a volume should be created on. An empty key takes the node's default class and falls back to the built-in one, so an install that registers nothing behaves exactly as it did before storage classes existed.

func (*Service) SetImageResolver

func (s *Service) SetImageResolver(r ImageResolver)

SetImageResolver wires the deployment-config resolver for the helper image.

func (*Service) SetServerInfo

func (s *Service) SetServerInfo(si ServerInfo)

SetServerInfo wires the resolver used to annotate classes with their node's name.

func (*Service) Update

func (s *Service) Update(id uint, in Input) (*models.StorageClass, error)

Update changes the editable fields. A name or path change is refused, not applied — see ErrImmutable.

Jump to

Keyboard shortcuts

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