volume

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// VolumeOperationTimeoutInSeconds specifies the default CSI operation timeout in seconds
	VolumeOperationTimeoutInSeconds = 300

	// MbInBytes is the number of bytes in one mebibyte.
	MbInBytes = int64(1024 * 1024)
)

Variables

View Source
var ErrListViewTaskAddition = errors.New("failure to add task to listview")
View Source
var ErrSessionNotAuthenticated = errors.New("session is not authenticated")

Functions

func ClearInvalidTasksFromListView

func ClearInvalidTasksFromListView(multivCenterCSITopologyEnabled bool)

func ClearTaskInfoObjects

func ClearTaskInfoObjects()

ClearTaskInfoObjects is a go routine which runs in the background to clean up expired taskInfo objects from volumeTaskMap.

func ExtractFaultTypeFromErr

func ExtractFaultTypeFromErr(ctx context.Context, err error) string

ExtractFaultTypeFromErr extracts the fault type from err. Return the vim fault type if the input err is a SoapFault, and can exract the fault type of VimFault. Otherwise, it returns fault type as "csi.fault.Internal".

func ExtractFaultTypeFromVolumeResponseResult

func ExtractFaultTypeFromVolumeResponseResult(ctx context.Context,
	resp *cnstypes.CnsVolumeOperationResult) string

ExtractFaultTypeFromVolumeResponseResult extracts the fault type from CnsVolumeOperationResult. Return the vim fault type is CnsVolumeOperationResult.Fault is set, and can extract the fault type of VimFault. Return "" if CnsVolumeOperationResult.Fault not set.

func GetAllManagerInstances added in v3.1.0

func GetAllManagerInstances(ctx context.Context) map[string]*defaultManager

GetAllManagerInstances returns all Manager instances

func IsDiskAttached

func IsDiskAttached(ctx context.Context, vm *cnsvsphere.VirtualMachine, volumeID string,
	checkNVMeController bool) (string, error)

IsDiskAttached checks if the volume is attached to the VM. If the volume is attached to the VM, return disk uuid of the volume, else return empty string.

func IsDiskAttachedToVMs

func IsDiskAttachedToVMs(ctx context.Context, volumeID string, vms []*cnsvsphere.VirtualMachine,
	checkNVMeController bool) (string, error)

IsDiskAttachedToVMs checks if the volume is attached to any of the input VMs. If the volume is attached to the VM, return disk uuid of the volume, else return empty string.

func IsNotFoundFault added in v3.1.0

func IsNotFoundFault(ctx context.Context, faultType string) bool

IsNotFoundFault returns true if a given faultType value is vim.fault.NotFound

func IsTaskPending added in v3.1.0

func IsTaskPending(volumeOperationDetails *cnsvolumeoperationrequest.VolumeOperationRequestDetails) bool

IsTaskPending returns true in two cases - 1. if the task status was in progress 2. if the status was an error but the error was for adding the task to the listview (as we don't know the status of the task on CNS)

func RemoveTasksMarkedForDeletion

func RemoveTasksMarkedForDeletion(l *ListViewImpl)

RemoveTasksMarkedForDeletion goes over the list of tasks in the map and removes tasks that have been marked for deletion

Types

type CnsSnapshotInfo

type CnsSnapshotInfo struct {
	SnapshotID                string
	SourceVolumeID            string
	SnapshotDescription       string
	SnapshotCreationTimestamp time.Time
}

type CnsVolumeInfo

type CnsVolumeInfo struct {
	DatastoreURL string
	VolumeID     cnstypes.CnsVolumeId
}

CnsVolumeInfo hold information related to volume created by CNS.

type CreateVolumeExtraParams added in v3.2.0

type CreateVolumeExtraParams struct {
	VolSizeBytes                         int64
	StorageClassName                     string
	Namespace                            string
	IsPodVMOnStretchSupervisorFSSEnabled bool
}

CreateVolumeExtraParams consist of values required by the CreateVolume interface and are not present in the CNS CreateVolume spec.

type ExpandVolumeExtraParams added in v3.2.0

type ExpandVolumeExtraParams struct {
	StorageClassName string
	StoragePolicyID  string
	Namespace        string
	// Capacity stores the original volume size which is from CNSVolumeInfo
	Capacity                             *resource.Quantity
	IsPodVMOnStretchSupervisorFSSEnabled bool
}

ExpandVolumeExtraParams consist of values required by the ExpandVolume interface and are not present in the CNS ExpandVolume spec

type InMemoryMapIf

type InMemoryMapIf interface {
	// Upsert : if task exists in the map, the taskDetails will be overwritten.
	// if the task doesn't exist, the taskDetails will be stored
	Upsert(types.ManagedObjectReference, TaskDetails)
	// Delete task from map
	Delete(types.ManagedObjectReference)
	// Get retrieves a single item from a map
	Get(types.ManagedObjectReference) (TaskDetails, bool)
	// GetAll retrieves all map items
	GetAll() []TaskDetails
	// Count returns the count of all items present in the map
	Count() int
}

InMemoryMapIf is used to not provide direct access to internal mutex or map to methods in the same pkg

func NewTaskMap

func NewTaskMap() InMemoryMapIf

NewTaskMap returns a new instance of TaskMap

type ListViewIf

type ListViewIf interface {
	// AddTask adds task to listView and the internal map
	AddTask(ctx context.Context, taskMoRef types.ManagedObjectReference, ch chan TaskResult) error
	// RemoveTask removes task from listview and the internal map
	RemoveTask(ctx context.Context, taskMoRef types.ManagedObjectReference) error
	// SetVirtualCenter is a setter method for the reference to the global vcenter object.
	// use case: ReloadConfiguration
	SetVirtualCenter(ctx context.Context, virtualCenter *cnsvsphere.VirtualCenter)
	// LogoutSession logout the vCenter Session
	LogoutSession(ctx context.Context) error
	// MarkTaskForDeletion marks a given task MoRef for deletion by a cleanup goroutine
	// use case: failure to remove task due to a vc issue
	MarkTaskForDeletion(ctx context.Context, taskMoRef types.ManagedObjectReference) error
}

ListViewIf provides methods to start and modify a listView object to monitor CNS tasks. NewListViewImpl satisfies ListViewIf and should be initialized to use the interface methods

type ListViewImpl

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

ListViewImpl is the struct used to manage a single listView instance.

func NewListViewImpl

func NewListViewImpl(ctx context.Context, virtualCenter *cnsvsphere.VirtualCenter,
	client *govmomi.Client) (*ListViewImpl, error)

NewListViewImpl creates a new listView object and starts a goroutine to listen to property collector task updates

func (*ListViewImpl) AddTask

func (l *ListViewImpl) AddTask(ctx context.Context, taskMoRef types.ManagedObjectReference, ch chan TaskResult) error

AddTask adds task to listView and the internal map

func (*ListViewImpl) LogoutSession added in v3.1.0

func (l *ListViewImpl) LogoutSession(ctx context.Context) error

LogoutSession is a setter method to logout vcenter session created

func (*ListViewImpl) MarkTaskForDeletion

func (l *ListViewImpl) MarkTaskForDeletion(ctx context.Context, taskMoRef types.ManagedObjectReference) error

MarkTaskForDeletion marks a given task MoRef for deletion by setting a boolean flag in the TaskDetails object

func (*ListViewImpl) RemoveTask

func (l *ListViewImpl) RemoveTask(ctx context.Context, taskMoRef types.ManagedObjectReference) error

RemoveTask removes task from listview and the internal map

func (*ListViewImpl) SetVirtualCenter

func (l *ListViewImpl) SetVirtualCenter(ctx context.Context, virtualCenter *cnsvsphere.VirtualCenter)

SetVirtualCenter is a setter method for vc. use case: ReloadConfiguration

type Manager

type Manager interface {
	// CreateVolume creates a new volume given its spec.
	// When CreateVolume failed, the second return value (faultType) and third return value(error) need to be set, and
	// should not be nil.
	// extraParams can be used to send in any values not present in the CnsVolumeCreateSpec param.
	CreateVolume(ctx context.Context, spec *cnstypes.CnsVolumeCreateSpec, extraParams interface{}) (
		*CnsVolumeInfo, string, error)
	// AttachVolume attaches a volume to a virtual machine given the spec.
	// When AttachVolume failed, the second return value (faultType) and third return value(error) need to be set, and
	// should not be nil.
	AttachVolume(ctx context.Context, vm *cnsvsphere.VirtualMachine,
		volumeID string, checkNVMeController bool) (string, string, error)
	// DetachVolume detaches a volume from the virtual machine given the spec.
	// When DetachVolume failed, the first return value (faultType) and second return value(error) need to be set, and
	// should not be nil.
	DetachVolume(ctx context.Context, vm *cnsvsphere.VirtualMachine, volumeID string) (string, error)
	// DeleteVolume deletes a volume given its spec.
	// When DeleteVolume failed, the first return value (faultType) and second return value(error) need to be set, and
	// should not be nil.
	DeleteVolume(ctx context.Context, volumeID string, deleteDisk bool) (string, error)
	// UpdateVolumeMetadata updates a volume metadata given its spec.
	UpdateVolumeMetadata(ctx context.Context, spec *cnstypes.CnsVolumeMetadataUpdateSpec) error
	// QueryVolumeInfo calls the CNS QueryVolumeInfo API and return a task, from
	// which CnsQueryVolumeInfoResult is extracted.
	QueryVolumeInfo(ctx context.Context, volumeIDList []cnstypes.CnsVolumeId) (*cnstypes.CnsQueryVolumeInfoResult, error)
	// QueryAllVolume returns all volumes matching the given filter and selection.
	QueryAllVolume(ctx context.Context, queryFilter cnstypes.CnsQueryFilter,
		querySelection cnstypes.CnsQuerySelection) (*cnstypes.CnsQueryResult, error)
	// QueryVolumeAsync returns CnsQueryResult matching the given filter by using
	// CnsQueryAsync API. QueryVolumeAsync takes querySelection spec, which helps
	// to specify which fields have to be returned for the query entities. All
	// volume fields would be returned as part of the CnsQueryResult, if the
	// querySelection parameters are not specified.
	QueryVolumeAsync(ctx context.Context, queryFilter cnstypes.CnsQueryFilter,
		querySelection *cnstypes.CnsQuerySelection) (*cnstypes.CnsQueryResult, error)
	// QueryVolume returns volumes matching the given filter.
	QueryVolume(ctx context.Context, queryFilter cnstypes.CnsQueryFilter) (*cnstypes.CnsQueryResult, error)
	// RelocateVolume migrates volumes to their target datastore as specified in relocateSpecList.
	RelocateVolume(ctx context.Context, relocateSpecList ...cnstypes.BaseCnsVolumeRelocateSpec) (*object.Task, error)
	// ExpandVolume expands a volume to a new size.
	// When ExpandVolume failed, the first return value (faultType) and second return value(error) need to be set, and
	// should not be nil.
	ExpandVolume(ctx context.Context, volumeID string, size int64, extraParams interface{}) (string, error)
	// ResetManager helps set new manager instance and VC configuration.
	ResetManager(ctx context.Context, vcenter *cnsvsphere.VirtualCenter) error
	// ConfigureVolumeACLs configures net permissions for a given CnsVolumeACLConfigureSpec.
	ConfigureVolumeACLs(ctx context.Context, spec cnstypes.CnsVolumeACLConfigureSpec) error
	// RegisterDisk registers virtual disks as FCDs using Vslm endpoint.
	RegisterDisk(ctx context.Context, path string, name string) (string, error)
	// RetrieveVStorageObject helps in retreiving virtual disk information for a given volume id.
	RetrieveVStorageObject(ctx context.Context, volumeID string) (*vim25types.VStorageObject, error)
	// ProtectVolumeFromVMDeletion sets keepAfterDeleteVm control flag on migrated volume
	ProtectVolumeFromVMDeletion(ctx context.Context, volumeID string) error
	// CreateSnapshot helps create a snapshot for a block volume
	CreateSnapshot(ctx context.Context, volumeID string, desc string) (*CnsSnapshotInfo, error)
	// DeleteSnapshot helps delete a snapshot for a block volume
	DeleteSnapshot(ctx context.Context, volumeID string, snapshotID string) error
	// QuerySnapshots retrieves the list of snapshots based on the query filter.
	QuerySnapshots(ctx context.Context, snapshotQueryFilter cnstypes.CnsSnapshotQueryFilter) (
		*cnstypes.CnsSnapshotQueryResult, error)
	// MonitorCreateVolumeTask monitors the CNS task which is created for volume creation
	// as part of volume idempotency feature
	MonitorCreateVolumeTask(ctx context.Context,
		volumeOperationDetails **cnsvolumeoperationrequest.VolumeOperationRequestDetails, task *object.Task,
		volNameFromInputSpec, clusterID string) (*CnsVolumeInfo,
		string, error)
	// GetOperationStore returns the VolumeOperationRequest interface
	GetOperationStore() cnsvolumeoperationrequest.VolumeOperationRequest
	// LogoutListViewVCSession logout current vCenter session for list-view
	LogoutListViewVCSession(ctx context.Context) error
}

Manager provides functionality to manage volumes.

func GetManager

func GetManager(ctx context.Context, vc *cnsvsphere.VirtualCenter,
	operationStore cnsvolumeoperationrequest.VolumeOperationRequest,
	idempotencyHandlingEnabled, multivCenterEnabled, multivCenterTopologyDeployment, tasksListViewEnabled bool,
	clusterFlavor cnstypes.CnsClusterFlavor) (Manager, error)

GetManager returns the Manager instance.

type TaskDetails

type TaskDetails struct {
	Reference types.ManagedObjectReference
	// MarkedForRemoval helps in retrying the removal of tasks in case of failures
	MarkedForRemoval bool
	// channel to return results. the caller (CSI op) is waiting on this channel
	ResultCh chan TaskResult
}

TaskDetails is used to hold state for a task

type TaskMap

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

TaskMap binds together the task details map and a mutex to guard it

func (*TaskMap) Count

func (t *TaskMap) Count() int

Count returns the number of tasks present in the map

func (*TaskMap) Delete

func (t *TaskMap) Delete(task types.ManagedObjectReference)

Delete deletes items from the map and requires an exclusive write lock

func (*TaskMap) Get

Get retrieves a single item from the map and requires a read lock

func (*TaskMap) GetAll

func (t *TaskMap) GetAll() []TaskDetails

GetAll retrieves all tasks from the map and requires a read lock

func (*TaskMap) Upsert

func (t *TaskMap) Upsert(task types.ManagedObjectReference, taskDetails TaskDetails)

Upsert adds/updates items and requires an exclusive write lock

type TaskResult

type TaskResult struct {
	TaskInfo *types.TaskInfo
	Err      error
}

Jump to

Keyboard shortcuts

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