util

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VolumeOperationAlreadyExistsFmt string format to return for concerrent operation
	VolumeOperationAlreadyExistsFmt = "an operation with the given Volume ID %s already exists"

	// SnapshotOperationAlreadyExistsFmt string format to return for concerrent operation
	SnapshotOperationAlreadyExistsFmt = "an operation with the given Snapshot ID %s already exists"
)
View Source
const (
	// MiB - MebiByte size
	MiB = 1024 * 1024
	GiB = MiB * 1024
)

remove this once kubernetes v1.14.0 release is done https://github.com/kubernetes/cloud-provider/blob/master/volume/helpers/rounding.go

View Source
const (

	// CephConfigPath ceph configuration file
	CephConfigPath = "/etc/ceph/ceph.conf"
)

Variables

View Source
var (
	// GitCommit tell the latest git commit image is built from
	GitCommit string
	// DriverVersion which will be driver version
	DriverVersion string
)

variables which will be set during the build time

View Source
var CtxKey = contextKey("ID")

CtxKey for context based logging

View Source
var ReqID = contextKey("Req-ID")

ReqID for logging request ID

Functions

func CheckRbdImageEncrypted

func CheckRbdImageEncrypted(ctx context.Context, cr *Credentials, monitors, imageSpec string) (string, error)

CheckRbdImageEncrypted verifies if rbd image was encrypted when created

func CloseEncryptedVolume

func CloseEncryptedVolume(ctx context.Context, mapperFile string) error

CloseEncryptedVolume closes encrypted volume so it can be detached

func CreateMountPoint added in v1.2.0

func CreateMountPoint(mountPath string) error

CreateMountPoint creates the directory with given path

func CreateObject

func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, objectName string) error

CreateObject creates the object name passed in and returns ErrObjectExists if the provided object is already present in rados

func DeviceEncryptionStatus

func DeviceEncryptionStatus(ctx context.Context, devicePath string) (mappedDevice, mapper string, err error)

DeviceEncryptionStatus looks to identify if the passed device is a LUKS mapping and if so what the device is and the mapper name as used by LUKS. If not, just returns the original device and an empty string.

func EncryptVolume

func EncryptVolume(ctx context.Context, devicePath, passphrase string) error

EncryptVolume encrypts provided device with LUKS

func ExecCommand

func ExecCommand(program string, args ...string) (stdout, stderr []byte, err error)

ExecCommand executes passed in program with args and returns separate stdout and stderr streams

func GenerateVolID

func GenerateVolID(ctx context.Context, monitors string, cr *Credentials, pool, clusterID, objUUID string, volIDVersion uint16) (string, error)

GenerateVolID generates a volume ID based on passed in parameters and version, to be returned to the CO system

func GetCryptoPassphrase

func GetCryptoPassphrase(secrets map[string]string) (string, error)

GetCryptoPassphrase Retrieves passphrase to encrypt volume

func GetImageMeta

func GetImageMeta(ctx context.Context, cr *Credentials, monitors, imageSpec, key string) (string, error)

GetImageMeta gets image metadata

func GetK8sNamespace

func GetK8sNamespace() string

GetK8sNamespace returns pod namespace. if pod namespace is empty it returns default namespace

func GetMonValFromSecret

func GetMonValFromSecret(secrets map[string]string) (string, error)

func GetOMapValue

func GetOMapValue(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName, oMapKey string) (string, error)

GetOMapValue gets the value for the given key from the named omap

func GetPIDLimit added in v1.2.0

func GetPIDLimit() (int, error)

GetPIDLimit returns the current PID limit, or an error. A value of -1 translates to "max".

func GetPoolID

func GetPoolID(ctx context.Context, monitors string, cr *Credentials, poolName string) (int64, error)

GetPoolID searches a list of pools in a cluster and returns the ID of the pool that matches the passed in poolName parameter

func GetPoolName

func GetPoolName(ctx context.Context, monitors string, cr *Credentials, poolID int64) (string, error)

GetPoolName lists all pools in a ceph cluster, and matches the pool whose pool ID is equal to the requested poolID parameter

func IsDeviceOpen

func IsDeviceOpen(ctx context.Context, device string) (bool, error)

IsDeviceOpen determines if encrypted device is already open

func IsMountPoint added in v1.2.0

func IsMountPoint(p string) (bool, error)

IsMountPoint checks if the given path is mountpoint or not

func Log added in v1.2.0

func Log(ctx context.Context, format string) string

Log helps in context based logging

func LuksClose

func LuksClose(mapperFile string) (stdout, stderr []byte, err error)

LuksClose removes existing mapping

func LuksFormat

func LuksFormat(devicePath, passphrase string) (stdout, stderr []byte, err error)

LuksFormat sets up volume as an encrypted LUKS partition

func LuksOpen

func LuksOpen(devicePath, mapperFile, passphrase string) (stdout, stderr []byte, err error)

LuksOpen opens LUKS encrypted partition and sets up a mapping

func LuksStatus

func LuksStatus(mapperFile string) (stdout, stderr []byte, err error)

LuksStatus returns encryption status of a provided device

func Mons

func Mons(pathToConfig, clusterID string) (string, error)

func Mount added in v1.2.0

func Mount(source, target, fstype string, options []string) error

Mount mounts the source to target path

func NewK8sClient

func NewK8sClient() *k8s.Clientset

NewK8sClient create kubernetes client

func OpenEncryptedVolume

func OpenEncryptedVolume(ctx context.Context, devicePath, mapperFile, passphrase string) error

OpenEncryptedVolume opens volume so that it can be used by the client

func RemoveOMapKey

func RemoveOMapKey(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName, oMapKey string) error

RemoveOMapKey removes the omap key from the given omap name

func RemoveObject

func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName string) error

RemoveObject removes the entire omap name passed in and returns ErrObjectNotFound is provided omap is not found in rados

func RoundOffBytes added in v1.2.2

func RoundOffBytes(bytes int64) int64

RoundOffBytes converts roundoff the size 1.1Mib will be round off to 2Mib same for GiB size less than 1MiB will be round off to 1MiB

func RoundOffVolSize added in v1.2.2

func RoundOffVolSize(size int64) int64

RoundOffVolSize rounds up given quantity upto chunks of MiB/GiB

func SaveRbdImageEncryptionStatus

func SaveRbdImageEncryptionStatus(ctx context.Context, cr *Credentials, monitors, imageSpec, status string) error

SaveRbdImageEncryptionStatus sets image metadata for encryption status

func SetImageMeta

func SetImageMeta(ctx context.Context, cr *Credentials, monitors, imageSpec, key, value string) error

SetImageMeta sets image metadata

func SetOMapKeyValue

func SetOMapKeyValue(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName, oMapKey, keyValue string) error

SetOMapKeyValue sets the given key and value into the provided Ceph omap name

func SetPIDLimit added in v1.2.0

func SetPIDLimit(limit int) error

SetPIDLimit configures the given PID limit for the current process. A value of -1 translates to "max".

func StartMetricsServer added in v1.2.0

func StartMetricsServer(c *Config)

StartMetricsServer starts http server

func StripSecretInArgs

func StripSecretInArgs(args []string) []string

StripSecretInArgs strips values of either "--key"/"--keyfile" or "secret=". `args` is left unchanged. Expects only one occurrence of either "--key"/"--keyfile" or "secret=".

func ValidateDriverName

func ValidateDriverName(driverName string) error

ValidateDriverName validates the driver name

func ValidateNodePublishVolumeRequest added in v1.2.0

func ValidateNodePublishVolumeRequest(req *csi.NodePublishVolumeRequest) error

ValidateNodePublishVolumeRequest validates the node publish request

func ValidateNodeStageVolumeRequest added in v1.2.0

func ValidateNodeStageVolumeRequest(req *csi.NodeStageVolumeRequest) error

ValidateNodeStageVolumeRequest validates the node stage request

func ValidateNodeUnpublishVolumeRequest added in v1.2.0

func ValidateNodeUnpublishVolumeRequest(req *csi.NodeUnpublishVolumeRequest) error

ValidateNodeUnpublishVolumeRequest validates the node unpublish request

func ValidateNodeUnstageVolumeRequest added in v1.2.0

func ValidateNodeUnstageVolumeRequest(req *csi.NodeUnstageVolumeRequest) error

ValidateNodeUnstageVolumeRequest validates the node unstage request

func ValidateURL added in v1.2.0

func ValidateURL(c *Config) error

ValidateURL validates the url

func VolumeMapper

func VolumeMapper(volumeID string) (mapperFile, mapperFilePath string)

VolumeMapper returns file name and it's path to where encrypted device should be open

func WriteCephConfig

func WriteCephConfig() error

WriteCephConfig writes out a basic ceph.conf file, making it easy to use ceph related CLIs

Types

type CSIIdentifier

type CSIIdentifier struct {
	LocationID      int64
	EncodingVersion uint16
	ClusterID       string
	ObjectUUID      string
}

CSIIdentifier contains the elements that form a CSI ID to be returned by the CSI plugin, and contains enough information to decompose and extract required cluster and pool information to locate the volume that relates to the CSI ID.

The CSI identifier is composed as elaborated in the comment against ComposeCSIID and thus, DecomposeCSIID is the inverse of the same function.

The CSIIdentifier structure carries the following fields,

  • LocationID: 64 bit integer identifier determining the location of the volume on the Ceph cluster. It is the ID of the poolname or fsname, for RBD or CephFS backed volumes respectively.
  • EncodingVersion: Carries the version number of the encoding scheme used to encode the CSI ID, and is preserved for any future proofing w.r.t changes in the encoding scheme, and to retain ability to parse backward compatible encodings.
  • ClusterID: Is a unique ID per cluster that the CSI instance is serving and is restricted to lengths that can be accommodated in the encoding scheme.
  • ObjectUUID: Is the on-disk uuid of the object (image/snapshot) name, for the CSI volume that corresponds to this CSI ID.

func (CSIIdentifier) ComposeCSIID

func (ci CSIIdentifier) ComposeCSIID() (string, error)

func (*CSIIdentifier) DecomposeCSIID

func (ci *CSIIdentifier) DecomposeCSIID(composedCSIID string) (err error)

DecomposeCSIID composes a CSIIdentifier from passed in string

type CSIJournal

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

func NewCSISnapshotJournal

func NewCSISnapshotJournal() *CSIJournal

CSISnapshotSnapshot returns an instance of snapshot keys

func NewCSIVolumeJournal

func NewCSIVolumeJournal() *CSIJournal

CSIVolumeJournal returns an instance of volume keys

func (*CSIJournal) CheckReservation

func (cj *CSIJournal) CheckReservation(ctx context.Context, monitors string, cr *Credentials, pool, reqName, parentName string) (string, error)

CheckReservation checks if given request name contains a valid reservation - If there is a valid reservation, then the corresponding UUID for the volume/snapshot is returned - If there is a reservation that is stale (or not fully cleaned up), it is garbage collected using the UndoReservation call, as appropriate - If a snapshot is being checked, then its source is matched to the parentName that is provided

NOTE: As the function manipulates omaps, it should be called with a lock against the request name held, to prevent parallel operations from modifying the state of the omaps for this request name.

Return values:

  • string: Contains the UUID that was reserved for the passed in reqName, empty if there was no reservation found
  • error: non-nil in case of any errors

func (*CSIJournal) GetObjectUUIDData

func (cj *CSIJournal) GetObjectUUIDData(ctx context.Context, monitors string, cr *Credentials, pool, objectUUID string, snapSource bool) (string, string, error)

GetObjectUUIDData fetches all keys from a UUID directory Return values:

  • string: Contains the request name for the passed in UUID
  • string: Contains the parent image name for the passed in UUID, if it is a snapshot
  • error: non-nil in case of any errors

func (*CSIJournal) NamingPrefix

func (cj *CSIJournal) NamingPrefix() string

NamingPrefix returns the value of naming prefix from the journal keys

func (*CSIJournal) ReserveName

func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *Credentials, pool, reqName, parentName string) (string, error)

ReserveName adds respective entries to the csiDirectory omaps, post generating a target UUIDDirectory for use. Further, these functions update the UUIDDirectory omaps, to store back pointers to the CSI generated request names.

NOTE: As the function manipulates omaps, it should be called with a lock against the request name held, to prevent parallel operations from modifying the state of the omaps for this request name.

Return values:

  • string: Contains the UUID that was reserved for the passed in reqName
  • error: non-nil in case of any errors

func (*CSIJournal) SetCSIDirectorySuffix

func (cj *CSIJournal) SetCSIDirectorySuffix(suffix string)

SetCSIDirectorySuffix sets the given suffix for the csiDirectory omap

func (*CSIJournal) SetNamespace

func (cj *CSIJournal) SetNamespace(ns string)

SetNamespace sets the namespace in which all RADOS objects would be created

func (*CSIJournal) UndoReservation

func (cj *CSIJournal) UndoReservation(ctx context.Context, monitors string, cr *Credentials, pool, volName, reqName string) error

UndoReservation undoes a reservation, in the reverse order of ReserveName - The UUID directory is cleaned up before the VolName key in the csiDirectory is cleaned up

NOTE: Ensure that the Ceph volume (image or FS subvolume) backing the reservation is cleaned up prior to cleaning up the reservation

NOTE: As the function manipulates omaps, it should be called with a lock against the request name held, to prevent parallel operations from modifying the state of the omaps for this request name.

type CacheEntryNotFound

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

CacheEntryNotFound is an error type for "Not Found" cache errors

type CachePersister

type CachePersister interface {
	Create(identifier string, data interface{}) error
	Get(identifier string, data interface{}) error
	ForAll(pattern string, destObj interface{}, f ForAllFunc) error
	Delete(identifier string) error
}

CachePersister interface implemented for store

func CreatePersistanceStorage

func CreatePersistanceStorage(sPath, metaDataStore, pluginPath string) (CachePersister, error)

CreatePersistanceStorage creates storage path and initializes new cache

func NewCachePersister

func NewCachePersister(metadataStore, pluginPath string) (CachePersister, error)

NewCachePersister returns CachePersister based on store

type Config added in v1.2.0

type Config struct {
	Vtype           string // driver type [rbd|cephfs|liveness]
	Endpoint        string // CSI endpoint
	DriverName      string // name of the driver
	NodeID          string // node id
	InstanceID      string // unique ID distinguishing this instance of Ceph CSI
	MetadataStorage string // metadata persistence method [node|k8s_configmap]
	PluginPath      string // location of cephcsi plugin

	// cephfs related flags
	MountCacheDir string // mount info cache save dir

	// metrics related flags
	MetricsPath       string        // path of prometheus endpoint where metrics will be available
	HistogramOption   string        // Histogram option for grpc metrics, should be comma separated value, ex:= "0.5,2,6" where start=0.5 factor=2, count=6
	MetricsIP         string        // TCP port for liveness/ metrics requests
	PidLimit          int           // PID limit to configure through cgroups")
	MetricsPort       int           // TCP port for liveness/grpc metrics requests
	PollTime          time.Duration // time interval in seconds between each poll
	PoolTimeout       time.Duration // probe timeout in seconds
	EnableGRPCMetrics bool          // option to enable grpc metrics

	IsControllerServer bool // if set to true start provisoner server
	IsNodeServer       bool // if set to true start node server
	Version            bool // cephcsi version

	// cephfs related flags
	ForceKernelCephFS bool // force to use the ceph kernel client even if the kernel is < 4.17

}

Config holds the parameters list which can be configured

type Credentials

type Credentials struct {
	ID      string
	KeyFile string
}

func NewAdminCredentials added in v1.2.0

func NewAdminCredentials(secrets map[string]string) (*Credentials, error)

func NewCredentials added in v1.2.0

func NewCredentials(id, key string) (*Credentials, error)

func NewUserCredentials added in v1.2.0

func NewUserCredentials(secrets map[string]string) (*Credentials, error)

func (*Credentials) DeleteCredentials added in v1.2.0

func (cr *Credentials) DeleteCredentials()

type ErrKeyNotFound

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

ErrKeyNotFound is returned when requested key in omap is not found

func (ErrKeyNotFound) Error

func (e ErrKeyNotFound) Error() string

type ErrObjectExists

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

ErrObjectExists is returned when named omap is already present in rados

func (ErrObjectExists) Error

func (e ErrObjectExists) Error() string

type ErrObjectNotFound

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

ErrObjectNotFound is returned when named omap is not found in rados

func (ErrObjectNotFound) Error

func (e ErrObjectNotFound) Error() string

type ErrPoolNotFound

type ErrPoolNotFound struct {
	Pool string
	Err  error
}

ErrPoolNotFound is returned when pool is not found

func (ErrPoolNotFound) Error

func (e ErrPoolNotFound) Error() string

type ErrSnapNameConflict

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

ErrSnapNameConflict is generated when a requested CSI snap name already exists on RBD but with different properties, and hence is in conflict with the passed in CSI volume name

func (ErrSnapNameConflict) Error

func (e ErrSnapNameConflict) Error() string

type ForAllFunc

type ForAllFunc func(identifier string) error

ForAllFunc is a unary predicate for visiting all cache entries matching the `pattern' in CachePersister's ForAll function.

type K8sCMCache

type K8sCMCache struct {
	Client    *k8s.Clientset
	Namespace string
}

K8sCMCache to store metadata

func (*K8sCMCache) Create

func (k8scm *K8sCMCache) Create(identifier string, data interface{}) error

Create stores the metadata in configmaps with identifier name

func (*K8sCMCache) Delete

func (k8scm *K8sCMCache) Delete(identifier string) error

Delete deletes the metadata in configmaps with identifier name

func (*K8sCMCache) ForAll

func (k8scm *K8sCMCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) error

ForAll list the metadata in configmaps and filters outs based on the pattern

func (*K8sCMCache) Get

func (k8scm *K8sCMCache) Get(identifier string, data interface{}) error

Get retrieves the metadata in configmaps with identifier name

type NodeCache

type NodeCache struct {
	BasePath string
	CacheDir string
}

NodeCache to store metadata

func (*NodeCache) Create

func (nc *NodeCache) Create(identifier string, data interface{}) error

Create creates the metadata file in cache directory with identifier name

func (*NodeCache) Delete

func (nc *NodeCache) Delete(identifier string) error

Delete deletes the metadata file from cache directory with identifier name

func (*NodeCache) EnsureCacheDirectory

func (nc *NodeCache) EnsureCacheDirectory(cacheDir string) error

EnsureCacheDirectory creates cache directory if not present

func (*NodeCache) ForAll

func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) error

ForAll list the metadata in Nodecache and filters outs based on the pattern

func (*NodeCache) Get

func (nc *NodeCache) Get(identifier string, data interface{}) error

Get retrieves the metadata from cache directory with identifier name

type VolumeLocks added in v1.2.1

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

VolumeLocks implements a map with atomic operations. It stores a set of all volume IDs with an ongoing operation.

func NewVolumeLocks added in v1.2.1

func NewVolumeLocks() *VolumeLocks

NewVolumeLocks returns new VolumeLocks

func (*VolumeLocks) Release added in v1.2.1

func (vl *VolumeLocks) Release(volumeID string)

func (*VolumeLocks) TryAcquire added in v1.2.1

func (vl *VolumeLocks) TryAcquire(volumeID string) bool

TryAcquire tries to acquire the lock for operating on volumeID and returns true if successful. If another operation is already using volumeID, returns false.

Jump to

Keyboard shortcuts

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