Documentation
¶
Overview ¶
Package ceph is VirtoMir's hyper-converged Ceph (D4, ADR-0073): bootstrapping a cluster with cephadm on the VirtoMir hosts, adding hosts and OSDs (only on empty disks), health and capacity telemetry, RBD pools that become libvirt pools on every member, storage policies that name a pool for new disks, and noout around host maintenance. It drives the stock tools (cephadm, ceph, rbd, lsblk) through a Runner, so every command it would run is tested without Ceph installed. Experimental: not tested on hardware.
Index ¶
- Constants
- Variables
- func AddHost(ctx context.Context, r Runner, hostname, ip string) error
- func AddOSD(ctx context.Context, r Runner, hostname string, disk DiskInfo) error
- func AuthorizePeerKey(pubKey string) error
- func CreateRBDPool(ctx context.Context, r Runner, spec PoolSpec) error
- func DeleteRBDPool(ctx context.Context, r Runner, name string, dataPool string) error
- func EnsureDiskEmpty(ctx context.Context, r Runner, path string) error
- func EnterHostMaintenance(ctx context.Context, r Runner, store *Store, hostname string) error
- func ExitHostMaintenance(ctx context.Context, r Runner, store *Store, hostname string) error
- func LibvirtPool(cfg ClusterConfig, cephPool, libvirtName string) virt.PoolSpec
- func MarkUsed(disks []DiskInfo, used func(path string) string)
- func SetCompression(ctx context.Context, r Runner, pool, dataPool, mode, algorithm string) error
- func SetNoout(ctx context.Context, r Runner, store *Store, on bool) error
- type BootstrapSpec
- type CapacityReport
- type CephHost
- type ClusterConfig
- type ClusterHealth
- type Daemons
- type DiskInfo
- type Exec
- type HealthCheck
- type OSDNode
- type PGSummary
- type PoliciesShared
- type PoolCapacity
- type PoolDetail
- type PoolSpec
- type Runner
- type StoragePolicy
- type Store
- func (s *Store) Adopt(sh PoliciesShared) (bool, error)
- func (s *Store) Config() (ClusterConfig, bool)
- func (s *Store) CreatePolicy(p StoragePolicy) (StoragePolicy, error)
- func (s *Store) DeletePolicy(id string) error
- func (s *Store) Policies() []StoragePolicy
- func (s *Store) Policy(id string) (StoragePolicy, bool)
- func (s *Store) SaveConfig(c ClusterConfig) error
- func (s *Store) SetHostMaintenance(host string, on bool) error
- func (s *Store) SetNoout(noout bool) error
- func (s *Store) Shared() PoliciesShared
- func (s *Store) UpdatePolicy(p StoragePolicy) (StoragePolicy, error)
- type Telemetry
Constants ¶
const ClientUser = "virtomir"
ClientUser is the cephx user VirtoMir creates for libvirt: RBD rights only, not admin.
Variables ¶
var ( ErrInvalid = errors.New("invalid") ErrNotFound = errors.New("not found") ErrExists = errors.New("exists") ErrBusy = errors.New("in use") ErrDiskNotEmpty = errors.New("disk not empty") )
Errors for the API.
var AuthorizedKeysFile = "/root/.ssh/authorized_keys"
AuthorizedKeysFile is where the cluster's SSH key goes so cephadm can manage this host.
var Busy = func(path string) bool { f, err := os.OpenFile(path, os.O_RDONLY|os.O_EXCL, 0) if err != nil { return errors.Is(err, syscall.EBUSY) } _ = f.Close() return false }
Busy reports whether the kernel holds a disk exclusively, which catches what leaves no signature on it (an iSCSI target's backing disk, a device-mapper user). Tests replace it.
Functions ¶
func AddHost ¶
AddHost has the orchestrator take over a host; its root must already trust the cluster's SSH key (AuthorizePeerKey there).
func AddOSD ¶
AddOSD makes an OSD of a disk on a host. disk is what that host reported about it (the API asks the host itself); a disk that is not empty is refused here, and ceph-volume refuses it again.
func AuthorizePeerKey ¶
AuthorizePeerKey lets the cluster's cephadm log in here as root, once.
func CreateRBDPool ¶
CreateRBDPool creates a pool for RBD images.
func DeleteRBDPool ¶
DeleteRBDPool removes a pool (and its data pool), with all images in it. Ceph only deletes pools while mon_allow_pool_delete is on, so it is switched on just for this.
func EnsureDiskEmpty ¶
EnsureDiskEmpty refuses a disk that holds anything.
func EnterHostMaintenance ¶
EnterHostMaintenance sets noout and stops the host's Ceph daemons. Ceph refuses when stopping them would make data unavailable; its answer is the error.
func ExitHostMaintenance ¶
ExitHostMaintenance starts the host's daemons again; the last host to leave maintenance clears noout.
func LibvirtPool ¶
func LibvirtPool(cfg ClusterConfig, cephPool, libvirtName string) virt.PoolSpec
LibvirtPool is the libvirt pool spec for an RBD pool of the cluster.
func MarkUsed ¶
MarkUsed refuses the disks that are something else's (a libvirt pool's volume, a machine's disk); used says by what ("" = nothing).
func SetCompression ¶
SetCompression sets BlueStore compression on the pool that holds a pool's data (the data pool of an erasure-coded one); it applies to data written from now on.
Types ¶
type BootstrapSpec ¶
type BootstrapSpec struct {
MonIP string `json:"monIp"`
ClusterNetwork string `json:"clusterNetwork,omitempty"`
InitialOSDDisk string `json:"initialOsdDisk,omitempty"`
SingleHostDefaults bool `json:"singleHostDefaults"`
}
BootstrapSpec is what bootstrapping a cluster on this host needs.
func (BootstrapSpec) Validate ¶
func (b BootstrapSpec) Validate() error
Validate checks the addresses and the disk path.
type CapacityReport ¶
type CapacityReport struct {
TotalBytes uint64 `json:"totalBytes"`
UsedBytes uint64 `json:"usedBytes"`
AvailBytes uint64 `json:"availBytes"`
PercentUsed float64 `json:"percentUsed"`
Pools []PoolCapacity `json:"pools"`
}
CapacityReport is the raw capacity and what each pool stores.
type CephHost ¶
type CephHost struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
Labels []string `json:"labels"`
Status string `json:"status"` // online, offline or maintenance
}
CephHost is a host of the Ceph cluster as the orchestrator sees it.
type ClusterConfig ¶
type ClusterConfig struct {
FSID string `json:"fsid"`
BootstrapHost string `json:"bootstrapHost"`
MonEndpoints []string `json:"monEndpoints"`
ClientUser string `json:"clientUser"`
// ClientKey is the cephx key libvirt pools use; the API never shows it.
ClientKey string `json:"clientKey,omitempty"`
SSHPublicKey string `json:"sshPublicKey"`
MaintenanceHosts []string `json:"maintenanceHosts"`
Noout bool `json:"noout"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
ClusterConfig is what VirtoMir knows of the Ceph cluster it bootstrapped or joined.
func AdoptCluster ¶
func AdoptCluster(ctx context.Context, r Runner, store *Store, hostname string) (ClusterConfig, error)
AdoptCluster records an existing cluster this host can reach as admin (for clusters made outside VirtoMir).
func Bootstrap ¶
func Bootstrap(ctx context.Context, r Runner, store *Store, hostname string, spec BootstrapSpec) (ClusterConfig, error)
Bootstrap creates a Ceph cluster with this host (hostname) as its first monitor and manager, creates VirtoMir's RBD user and, with InitialOSDDisk, the first OSD. The disk is checked before cephadm runs: a disk with data stops everything.
type ClusterHealth ¶
type ClusterHealth struct {
Status string `json:"status"` // HEALTH_OK, HEALTH_WARN or HEALTH_ERR
Checks []HealthCheck `json:"checks"`
}
ClusterHealth is Ceph's overall verdict and its checks.
func Health ¶
func Health(ctx context.Context, r Runner) (ClusterHealth, error)
Health asks Ceph how it is, with the details of each check.
func (ClusterHealth) Summary ¶
func (h ClusterHealth) Summary() string
Summary is the checks' summaries in one line.
type Daemons ¶
type Daemons struct {
Mons int `json:"mons"`
Quorum []string `json:"quorum"`
MgrUp bool `json:"mgrUp"`
OSDs int `json:"osds"`
OSDsUp int `json:"osdsUp"`
OSDsIn int `json:"osdsIn"`
NooutIsSet bool `json:"noout"`
}
Daemons counts monitors, managers and OSDs.
type DiskInfo ¶
type DiskInfo struct {
Path string `json:"path"`
Name string `json:"name"`
SizeBytes uint64 `json:"sizeBytes"`
Rotational bool `json:"rotational"`
DeviceType string `json:"deviceType"` // ssd, nvme or hdd
MountPoint string `json:"mountPoint,omitempty"`
FSType string `json:"fsType,omitempty"`
Partitions []string `json:"partitions,omitempty"`
// Empty: no partition table, partitions, file system, LVM/ZFS/RAID label or mount.
// Only empty disks become OSDs; RefusalReason says what is on the others.
Empty bool `json:"empty"`
RefusalReason string `json:"refusalReason,omitempty"`
}
DiskInfo is a host disk and whether Ceph may take it.
func InspectDisk ¶
InspectDisk describes one disk.
type HealthCheck ¶
type HealthCheck struct {
Name string `json:"name"`
Severity string `json:"severity"` // HEALTH_WARN or HEALTH_ERR
Summary string `json:"summary"`
Detail []string `json:"detail,omitempty"`
}
HealthCheck is one problem Ceph reports.
type OSDNode ¶
type OSDNode struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"` // root, host, osd, …
Status string `json:"status,omitempty"` // up or down (OSDs)
In bool `json:"in"`
Weight float64 `json:"weight"`
DeviceClass string `json:"deviceClass,omitempty"`
Children []int `json:"children,omitempty"`
}
OSDNode is a node of the CRUSH tree: the root, hosts and OSDs.
type PoliciesShared ¶
type PoliciesShared struct {
}
PoliciesShared is the versioned policy list members exchange (newest version wins).
type PoolCapacity ¶
type PoolCapacity struct {
ID int `json:"id"`
Name string `json:"name"`
StoredBytes uint64 `json:"storedBytes"`
Objects uint64 `json:"objects"`
PercentUsed float64 `json:"percentUsed"`
MaxAvail uint64 `json:"maxAvailBytes"`
// Compressed is the raw space compressed data takes, CompressedFrom what it was before
// (BlueStore compression, ADR-0074).
Compressed uint64 `json:"compressedBytes"`
CompressedFrom uint64 `json:"compressedFromBytes"`
}
PoolCapacity is one pool's share of the cluster.
type PoolDetail ¶
type PoolDetail struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"` // replicated or erasure
Size int `json:"size"` // copies (replicated) or k+m (erasure)
MinSize int `json:"minSize"`
ECProfile string `json:"ecProfile,omitempty"`
DataPool string `json:"dataPool,omitempty"` // erasure: where the data goes
StoredBytes uint64 `json:"storedBytes"`
PercentUsed float64 `json:"percentUsed"`
MaxAvail uint64 `json:"maxAvailBytes"`
// Compression of the pool that holds the data (none, passive, aggressive, force) and
// what it saves: CompressedFrom bytes were stored as Compressed.
CompressionMode string `json:"compressionMode"`
CompressionAlgorithm string `json:"compressionAlgorithm,omitempty"`
Compressed uint64 `json:"compressedBytes"`
CompressedFrom uint64 `json:"compressedFromBytes"`
}
PoolDetail is an RBD pool and what it stores.
func ListRBDPools ¶
func ListRBDPools(ctx context.Context, r Runner) ([]PoolDetail, error)
ListRBDPools lists the pools with the rbd application; an erasure-coded pool shows as its metadata pool with the data pool's usage.
type PoolSpec ¶
type PoolSpec struct {
Name string `json:"name"`
Type string `json:"type"` // replicated or erasure
ReplicaSize int `json:"replicaSize,omitempty"` // replicated: copies, default 3
ECK int `json:"ecK,omitempty"` // erasure: data chunks, default 4
ECM int `json:"ecM,omitempty"` // erasure: coding chunks, default 2
DeviceClass string `json:"deviceClass,omitempty"` // ssd, hdd or nvme: only OSDs of that class
PGNum int `json:"pgNum,omitempty"` // first placement group count; the autoscaler adjusts it
}
PoolSpec is an RBD pool to create. Erasure-coded pools keep their data in <name>-data and the image metadata in <name> (RBD needs a replicated pool for that); libvirt only ever sees <name>.
type StoragePolicy ¶
type StoragePolicy struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Pool string `json:"pool"`
Default bool `json:"default"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
StoragePolicy names the libvirt pool new disks of that kind go to ("fast", "replica-3", "cold-ec"), so people pick an intent instead of a pool. Pools are often Ceph RBD pools, but any pool works.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps -state-dir/ceph.json: the cluster this host manages and the storage policies, which are the same on every member.
func (*Store) Adopt ¶
func (s *Store) Adopt(sh PoliciesShared) (bool, error)
Adopt takes over a member's policies when they are newer; it reports whether it did.
func (*Store) Config ¶
func (s *Store) Config() (ClusterConfig, bool)
Config returns the cluster configuration, if this host has one.
func (*Store) CreatePolicy ¶
func (s *Store) CreatePolicy(p StoragePolicy) (StoragePolicy, error)
CreatePolicy adds a policy.
func (*Store) DeletePolicy ¶
DeletePolicy removes a policy; machines keep their disks where they are.
func (*Store) Policies ¶
func (s *Store) Policies() []StoragePolicy
Policies lists the storage policies by name.
func (*Store) Policy ¶
func (s *Store) Policy(id string) (StoragePolicy, bool)
Policy returns one policy.
func (*Store) SetHostMaintenance ¶
SetHostMaintenance records a host entering or leaving maintenance.
func (*Store) Shared ¶
func (s *Store) Shared() PoliciesShared
Shared returns the policies with their version.
func (*Store) UpdatePolicy ¶
func (s *Store) UpdatePolicy(p StoragePolicy) (StoragePolicy, error)
UpdatePolicy changes a policy's name, description, pool and default flag.
type Telemetry ¶
type Telemetry struct {
FSID string `json:"fsid"`
Health ClusterHealth `json:"health"`
Daemons Daemons `json:"daemons"`
Capacity CapacityReport `json:"capacity"`
OSDTree []OSDNode `json:"osdTree"`
PGs PGSummary `json:"pgs"`
Collected time.Time `json:"collected"`
}
Telemetry is the cluster at one moment.