common

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

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

	// GbInBytes is the number of bytes in one gibibyte.
	GbInBytes = int64(1024 * 1024 * 1024)

	// DefaultGbDiskSize is the default disk size in gibibytes.
	// TODO: will make the DefaultGbDiskSize configurable in the future.
	DefaultGbDiskSize = int64(10)

	// DiskTypeBlockVolume is the value for PersistentVolume's attribute "type".
	DiskTypeBlockVolume = "vSphere CNS Block Volume"

	// DiskTypeFileVolume is the value for PersistentVolume's attribute "type".
	DiskTypeFileVolume = "vSphere CNS File Volume"

	// AttributeDiskType is a PersistentVolume's attribute.
	AttributeDiskType = "type"

	// AttributeDatastoreURL represents URL of the datastore in the StorageClass.
	// For Example: DatastoreURL: "ds:///vmfs/volumes/5c9bb20e-009c1e46-4b85-0200483b2a97/".
	AttributeDatastoreURL = "datastoreurl"

	// AttributeStoragePolicyName represents name of the Storage Policy in the
	// Storage Class.
	// For Example: StoragePolicy: "vSAN Default Storage Policy".
	AttributeStoragePolicyName = "storagepolicyname"

	// AttributeStoragePolicyID represents Storage Policy Id in the Storage Classs.
	// For Example: StoragePolicyId: "251bce41-cb24-41df-b46b-7c75aed3c4ee".
	AttributeStoragePolicyID = "storagepolicyid"

	// AttributeSupervisorStorageClass represents name of the Storage Class.
	// For example: StorageClassName: "silver".
	AttributeSupervisorStorageClass = "svstorageclass"

	// AttributeStorageTopologyType is a storageClass parameter.
	// It represents a zonal or a crossZonal volume provisioning.
	// For example: StorageTopologyType: "zonal"
	AttributeStorageTopologyType = "storagetopologytype"

	// AttributeFsType represents filesystem type in the Storage Classs.
	// For Example: FsType: "ext4".
	AttributeFsType = "fstype"

	// AttributeStoragePool represents name of the StoragePool on which to place
	// the PVC. For example: StoragePool: "storagepool-vsandatastore".
	AttributeStoragePool = "storagepool"

	// AttributeHostLocal represents the presence of HostLocal functionality in
	// the given storage policy. For Example: HostLocal: "True".
	AttributeHostLocal = "hostlocal"

	// HostMoidAnnotationKey represents the Node annotation key that has the value
	// of VC's ESX host moid of this node.
	HostMoidAnnotationKey = "vmware-system-esxi-node-moid"

	// Ext4FsType represents the default filesystem type for block volume.
	Ext4FsType = "ext4"

	// NfsV4FsType represents nfs4 mount type.
	NfsV4FsType = "nfs4"

	//NTFSFsType represents ntfs
	NTFSFsType = "ntfs"

	// NfsFsType represents nfs mount type.
	NfsFsType = "nfs"

	// ProviderPrefix is the prefix used for the ProviderID set on the node.
	// Example: vsphere://4201794a-f26b-8914-d95a-edeb7ecc4a8f
	ProviderPrefix = "vsphere://"

	// AttributeFirstClassDiskUUID is the SCSI Disk Identifier.
	AttributeFirstClassDiskUUID = "diskUUID"

	// AttributeVmUUID is the vmUUID to which volume is attached to.
	AttributeVmUUID = "vmUUID"

	// AttributeFakeAttached is the flag that indicates if a volume is fake
	// attached.
	AttributeFakeAttached = "fake-attach"

	// BlockVolumeType is the VolumeType for CNS Volume.
	BlockVolumeType = "BLOCK"

	// FileVolumeType is the VolumeType for CNS File Share Volume.
	FileVolumeType = "FILE"

	// UnknownVolumeType is assigned to CNS volumes whose type couldn't be determined.
	UnknownVolumeType = "UNKNOWN"

	// Nfsv4AccessPointKey is the key for NFSv4 access point.
	Nfsv4AccessPointKey = "NFSv4.1"

	// Nfsv4AccessPoint is the access point of file volume.
	Nfsv4AccessPoint = "Nfsv4AccessPoint"

	// MinSupportedVCenterMajor is the minimum, major version of vCenter
	// on which CNS is supported.
	MinSupportedVCenterMajor int = 6

	// MinSupportedVCenterMinor is the minimum, minor version of vCenter
	// on which CNS is supported.
	MinSupportedVCenterMinor int = 7

	// MinSupportedVCenterPatch is the minimum patch version of vCenter
	// on which CNS is supported.
	MinSupportedVCenterPatch int = 3

	// SnapshotSupportedVCenterMajor is the minimum major version of vCenter
	// on which Snapshot feature is supported.
	SnapshotSupportedVCenterMajor int = 7

	// SnapshotSupportedVCenterMinor is the minimum minor version of vCenter
	// on which Snapshot feature is supported.
	SnapshotSupportedVCenterMinor int = 0

	// SnapshotSupportedVCenterPatch is the minimum patch version of vCenter
	// on which Snapshot feature is supported.
	SnapshotSupportedVCenterPatch int = 3

	// VSphere67u3Version is the minimum vSphere version to use Vslm APIs
	// to support volume migration feature.
	VSphere67u3Version string = "6.7.3"

	// VSphere7Version is the maximum vSphere version to use Vslm APIs
	// to support volume migration feature.
	VSphere7Version string = "7.0.0"

	// VSphere8VersionMajorInt indicates the major version value in integer
	VSphere8VersionMajorInt int = 8

	// VSphere67u3lBuildInfo is the build number for vCenter in 6.7 Update 3l
	// GA bits.
	VSphere67u3lBuildInfo int = 17137327

	// VsanAffinityKey is the profile param key to indicate which node the FCD
	// should be affinitized to.
	VsanAffinityKey string = "VSAN/affinity/affinity"

	// VsanAffinityMandatory is the profile param key to turn on affinity of
	// the volume to a specific ESX host.
	VsanAffinityMandatory string = "VSAN/affinityMandatory/affinityMandatory"

	// VsanMigrateForDecom is the profile param key to set the migrate mode
	// for the volume.
	VsanMigrateForDecom string = "VSAN/migrateForDecom/migrateForDecom"

	// VsanDatastoreType is the string to identify datastore type as vsan.
	VsanDatastoreType string = "vsan"

	// CSIMigrationParams helps identify if volume creation is requested by
	// in-tree storageclass or CSI storageclass.
	CSIMigrationParams = "csimigration"

	// AttributeInitialVolumeFilepath represents the path of volume where volume
	// is created.
	AttributeInitialVolumeFilepath = "initialvolumefilepath"

	// DatastoreMigrationParam is used to supply datastore name for Volume
	// provisioning.
	DatastoreMigrationParam = "datastore-migrationparam"

	// DiskFormatMigrationParam supplies disk foramt (thin, thick, zeoredthick)
	// for Volume provisioning.
	DiskFormatMigrationParam = "diskformat-migrationparam"

	// HostFailuresToTolerateMigrationParam is raw vSAN Policy Parameter.
	HostFailuresToTolerateMigrationParam = "hostfailurestotolerate-migrationparam"

	// ForceProvisioningMigrationParam is raw vSAN Policy Parameter.
	ForceProvisioningMigrationParam = "forceprovisioning-migrationparam"

	// CacheReservationMigrationParam is raw vSAN Policy Parameter.
	CacheReservationMigrationParam = "cachereservation-migrationparam"

	// DiskstripesMigrationParam is raw vSAN Policy Parameter.
	DiskstripesMigrationParam = "diskstripes-migrationparam"

	// ObjectspacereservationMigrationParam is raw vSAN Policy Parameter.
	ObjectspacereservationMigrationParam = "objectspacereservation-migrationparam"

	// IopslimitMigrationParam is raw vSAN Policy Parameter.
	IopslimitMigrationParam = "iopslimit-migrationparam"

	// AnnMigratedTo annotation is added to a PVC and PV that is supposed to be
	// provisioned/deleted by its corresponding CSI driver.
	AnnMigratedTo = "pv.kubernetes.io/migrated-to"

	// AnnBetaStorageProvisioner annotation is added to a PVC that is supposed to
	// be dynamically provisioned. Its value is name of volume plugin that is
	// supposed to provision a volume for this PVC.
	AnnBetaStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"

	// AnnStorageProvisioner annotation is added to a PVC that is supposed to
	// be dynamically provisioned. Its value is name of volume plugin that is
	// supposed to provision a volume for this PVC.
	AnnStorageProvisioner = "volume.kubernetes.io/storage-provisioner"

	// vSphereCSIDriverName vSphere CSI driver name
	VSphereCSIDriverName = "csi.vsphere.vmware.com"

	// AnnDynamicallyProvisioned annotation is added to a PV that has been
	// dynamically provisioned by Kubernetes. Its value is name of volume plugin
	// that created the volume. It serves both user (to show where a PV comes
	// from) and Kubernetes (to recognize dynamically provisioned PVs in its
	// decisions).
	AnnDynamicallyProvisioned = "pv.kubernetes.io/provisioned-by"

	// InTreePluginName is the name of vsphere cloud provider in kubernetes.
	InTreePluginName = "kubernetes.io/vsphere-volume"

	// DsPriv is the privilege need to write on that datastore.
	DsPriv = "Datastore.FileManagement"

	// SysReadPriv is the privilege to view an entity.
	SysReadPriv = "System.Read"

	// HostConfigStoragePriv is the privilege for file volumes.
	HostConfigStoragePriv = "Host.Config.Storage"

	// AnnVolumeHealth is the key for HealthStatus annotation on volume claim.
	AnnVolumeHealth = "volumehealth.storage.kubernetes.io/health"

	// AnnFakeAttached is the key for fake attach annotation on volume claim.
	AnnFakeAttached = "csi.vmware.com/fake-attached"

	// VolHealthStatusAccessible is volume health status for accessible volume.
	VolHealthStatusAccessible = "accessible"

	// VolHealthStatusInaccessible is volume health status for inaccessible volume.
	VolHealthStatusInaccessible = "inaccessible"

	// AnnIgnoreInaccessiblePV is annotation key on volume claim to indicate
	// if inaccessible PV can be fake attached.
	AnnIgnoreInaccessiblePV = "pv.attach.kubernetes.io/ignore-if-inaccessible"

	// TriggerCsiFullSyncCRName is the instance name of TriggerCsiFullSync
	// All other names will be rejected by TriggerCsiFullSync controller.
	TriggerCsiFullSyncCRName = "csifullsync"

	// QuerySnapshotLimit is the maximum number of snapshots that can be retrieved per QuerySnapshot call.
	// The 128 size limit is specified by CNS QuerySnapshot API.
	QuerySnapshotLimit = int64(128)

	// VSphereCSISnapshotIdDelimiter is the delimiter for concatenating CNS VolumeID and CNS SnapshotID
	VSphereCSISnapshotIdDelimiter = "+"

	// TopologyLabelsDomain is the domain name used to identify user-defined
	// topology labels applied on the node by vSphere CSI driver.
	TopologyLabelsDomain = "topology.csi.vmware.com"

	//AnnGuestClusterRequestedTopology is the key for guest cluster requested topology
	AnnGuestClusterRequestedTopology = "csi.vsphere.volume-requested-topology"

	//AnnVolumeAccessibleTopology is the annotation set by the supervisor cluster on PVC
	AnnVolumeAccessibleTopology = "csi.vsphere.volume-accessible-topology"

	// PVtoBackingDiskObjectIdSupportedVCenterMajor is the minimum major version of vCenter
	// on which PV to BackingDiskObjectId mapping feature is supported.
	PVtoBackingDiskObjectIdSupportedVCenterMajor int = 7

	// PVtoBackingDiskObjectIdSupportedVCenterMinor is the minimum minor version of vCenter
	// on which PV to BackingDiskObjectId mapping feature is supported.
	PVtoBackingDiskObjectIdSupportedVCenterMinor int = 0

	// PVtoBackingDiskObjectIdSupportedVCenterPatch is the minimum patch version of vCenter
	// on which PV to BackingDiskObjectId mapping feature is supported.
	PVtoBackingDiskObjectIdSupportedVCenterPatch int = 2

	// PreferredDatastoresCategory points to the vSphere Category
	// created to tag preferred datastores in a topology-aware environment.
	PreferredDatastoresCategory = "cns.vmware.topology-preferred-datastores"

	// VolumeSnapshotNameKey represents the volumesnapshot CR name within
	// the request parameters
	VolumeSnapshotNameKey = "csi.storage.k8s.io/volumesnapshot/name"

	// VolumeSnapshotNamespaceKey represents the volumesnapshot CR namespace within
	// the request parameters
	VolumeSnapshotNamespaceKey = "csi.storage.k8s.io/volumesnapshot/namespace"

	// VolumeSnapshotInfoKey represents the annotation key of the fcd-id + snapshot-id
	// on the VolumeSnapshot CR
	VolumeSnapshotInfoKey = "csi.vsphere.volume/snapshot"

	// AttributeSupervisorVolumeSnapshotClass represents name of VolumeSnapshotClass
	AttributeSupervisorVolumeSnapshotClass = "svvolumesnapshotclass"

	// VolumeSnapshotApiGroup represents the VolumeSnapshot API Group name
	VolumeSnapshotApiGroup = "snapshot.storage.k8s.io"

	// VolumeSnapshotKind represents the VolumeSnapshot Kind name
	VolumeSnapshotKind = "VolumeSnapshot"
)
View Source
const (
	// Default interval to check if the feature is enabled or not.
	DefaultFeatureEnablementCheckInterval = 1 * time.Minute
	// VolumeHealth is the feature flag name for volume health.
	VolumeHealth = "volume-health"
	// VolumeExtend is feature flag name for volume expansion.
	VolumeExtend = "volume-extend"
	// OnlineVolumeExtend guards the feature for online volume expansion.
	OnlineVolumeExtend = "online-volume-extend"
	// CSIMigration is feature flag for migrating in-tree vSphere volumes to CSI.
	CSIMigration = "csi-migration"
	// CSIAuthCheck is feature flag for auth check.
	CSIAuthCheck = "csi-auth-check"
	// AsyncQueryVolume is feature flag for using async query volume API.
	AsyncQueryVolume = "async-query-volume"
	// CSISVFeatureStateReplication is feature flag for SV feature state
	// replication feature.
	CSISVFeatureStateReplication = "csi-sv-feature-states-replication"
	// VSANDirectDiskDecommission is feature flag for vsanD disk decommission.
	VSANDirectDiskDecommission = "vsan-direct-disk-decommission"
	// FileVolume is feature flag name for file volume support in WCP.
	FileVolume = "file-volume"
	// FakeAttach is the feature flag for fake attach support in WCP.
	FakeAttach = "fake-attach"
	// TriggerCSIFullSyync is feature flag to trigger full sync.
	TriggerCsiFullSync = "trigger-csi-fullsync"
	// CSIVolumeManagerIdempotency is the feature flag for idempotency handling
	// in CSI volume manager.
	CSIVolumeManagerIdempotency = "improved-csi-idempotency"
	// ImprovedVolumeTopology is the feature flag used to make the following
	// improvements to topology feature:
	// 1. Avoid taking in VC credentials in node daemonset.
	ImprovedVolumeTopology = "improved-volume-topology"
	// BlockVolumeSnapshot is the feature to support CSI Snapshots for block
	// volume on vSphere CSI driver.
	BlockVolumeSnapshot = "block-volume-snapshot"
	// SiblingReplicaBoundPvcCheck is the feature to check whether a PVC of
	// a given replica can be placed on a node such that it does not have PVCs
	// of any of its sibling replicas.
	SiblingReplicaBoundPvcCheck = "sibling-replica-bound-pvc-check"
	// CSIWindowsSupport is the feature to support csi block volumes for windows
	// node.
	CSIWindowsSupport = "csi-windows-support"
	// UseCSINodeId is the feature to make sure CSI will no longer use
	// ProviderID on K8s Node API object set by CPI. If not set, CSI
	// will continue to use the Provider ID from K8s Node API object.
	UseCSINodeId = "use-csinode-id"
	// TKGsHA is the feature gate to check whether TKGS HA feature
	// is enabled.
	TKGsHA = "tkgs-ha"
	// ListVolumes is the feature to support list volumes API
	ListVolumes = "list-volumes"
	// PVtoBackingDiskObjectIdMapping is the feature to support pv to backingDiskObjectId mapping on vSphere CSI driver.
	PVtoBackingDiskObjectIdMapping = "pv-to-backingdiskobjectid-mapping"
	// Block Create Volume for datastores that are in suspended mode
	CnsMgrSuspendCreateVolume = "cnsmgr-suspend-create-volume"
	// TopologyPreferentialDatastores is the feature gate for preferential
	// datastore deployment in topology aware environments.
	TopologyPreferentialDatastores = "topology-preferential-datastores"
	// MaxPVSCSITargetsPerVM enables support for 255 volumes per node vm
	MaxPVSCSITargetsPerVM = "max-pvscsi-targets-per-vm"
)

Constants related to Feature state

View Source
const (
	// Default container orchestrator for TKC, Supervisor Cluster and Vanilla K8s.
	Kubernetes = iota
)

Supported container orchestrators.

Variables

View Source
var (
	// BlockVolumeCaps represents how the block volume could be accessed.
	// CNS block volumes support only SINGLE_NODE_WRITER where the volume is
	// attached to a single node at any given time.
	BlockVolumeCaps = []csi.VolumeCapability_AccessMode{
		{
			Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
		},
	}

	// FileVolumeCaps represents how the file volume could be accessed.
	// CNS file volumes supports MULTI_NODE_READER_ONLY, MULTI_NODE_SINGLE_WRITER
	// and MULTI_NODE_MULTI_WRITER
	FileVolumeCaps = []csi.VolumeCapability_AccessMode{
		{
			Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY,
		},
		{
			Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER,
		},
		{
			Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
		},
	}

	// ErrNotFound represents not found error
	ErrNotFound = errors.New("not found")
)
View Source
var ErrAvailabilityZoneCRNotRegistered = errors.New("AvailabilityZone custom resource not registered")

Functions

func AttachVolumeUtil

func AttachVolumeUtil(ctx context.Context, manager *Manager,
	vm *vsphere.VirtualMachine,
	volumeID string, checkNVMeController bool) (string, string, error)

AttachVolumeUtil is the helper function to attach CNS volume to specified vm.

func CheckAPI

func CheckAPI(ctx context.Context,
	versionToCheck string,
	minSupportedVCenterMajor int,
	minSupportedVCenterMinor int,
	minSupportedVCenterPatch int) error

CheckAPI checks if specified version against the specified minimum support version.

func CheckPVtoBackingDiskObjectIdSupport added in v2.5.0

func CheckPVtoBackingDiskObjectIdSupport(ctx context.Context, vc *cnsvsphere.VirtualCenter) bool

CheckPVtoBackingDiskObjectIdSupport internally checks if the vCenter version is 7.0.2. Support both vsan and vvol.

func ComputeDatastoreMapForBlockVolumes

func ComputeDatastoreMapForBlockVolumes(authManager *AuthManager, authCheckInterval int)

ComputeDatastoreMapForBlockVolumes refreshes DatastoreMapForBlockVolumes periodically.

func ComputeFSEnabledClustersToDsMap

func ComputeFSEnabledClustersToDsMap(authManager *AuthManager, authCheckInterval int)

ComputeFSEnabledClustersToDsMap refreshes fsEnabledClusterToDsMap periodically.

func Contains

func Contains(list []string, item string) bool

Contains check if item exist in list

func ConvertVolumeHealthStatus

func ConvertVolumeHealthStatus(ctx context.Context, volID string, volHealthStatus string) (string, error)

ConvertVolumeHealthStatus convert the volume health status into accessible/inaccessible status.

func CreateBlockVolumeUtil

func CreateBlockVolumeUtil(ctx context.Context, clusterFlavor cnstypes.CnsClusterFlavor, manager *Manager,
	spec *CreateVolumeSpec, sharedDatastores []*vsphere.DatastoreInfo,
	filterSuspendedDatastores bool, useSupervisorId bool) (*cnsvolume.CnsVolumeInfo, string, error)

CreateBlockVolumeUtil is the helper function to create CNS block volume.

func CreateFileVolumeUtil

func CreateFileVolumeUtil(ctx context.Context, clusterFlavor cnstypes.CnsClusterFlavor,
	manager *Manager, spec *CreateVolumeSpec, datastores []*vsphere.DatastoreInfo,
	filterSuspendedDatastores bool, useSupervisorId bool) (string, string, error)

CreateFileVolumeUtil is the helper function to create CNS file volume with datastores.

func CreateFileVolumeUtilOld

func CreateFileVolumeUtilOld(ctx context.Context, clusterFlavor cnstypes.CnsClusterFlavor,
	manager *Manager, spec *CreateVolumeSpec,
	filterSuspendedDatastores bool, useSupervisorId bool) (string, string, error)

CreateFileVolumeUtilOld is the helper function to create CNS file volume with datastores from TargetvSANFileShareDatastoreURLs in vsphere conf.

func CreateSnapshotUtil

func CreateSnapshotUtil(ctx context.Context, manager *Manager, volumeID string, snapshotName string) (string,
	*time.Time, error)

CreateSnapshotUtil is the helper function to create CNS snapshot for given volumeId

The desc parameter denotes the snapshot description required by CNS CreateSnapshot API. This parameter is expected to be filled with the CSI CreateSnapshotRequest Name, which is generated by the CSI snapshotter sidecar.

The returned string is a combination of CNS VolumeID and CNS SnapshotID concatenated by the "+" sign. The returned *time.Time denotes the creation time of snapshot from the storage system, i.e., CNS.

func DeleteSnapshotUtil

func DeleteSnapshotUtil(ctx context.Context, manager *Manager, csiSnapshotID string) error

DeleteSnapshotUtil is the helper function to delete CNS snapshot for given snapshotId

func DeleteVolumeUtil

func DeleteVolumeUtil(ctx context.Context, volManager cnsvolume.Manager, volumeID string,
	deleteDisk bool) (string, error)

DeleteVolumeUtil is the helper function to delete CNS volume for given volumeId.

func DetachVolumeUtil

func DetachVolumeUtil(ctx context.Context, manager *Manager,
	vm *vsphere.VirtualMachine,
	volumeID string) (string, error)

DetachVolumeUtil is the helper function to detach CNS volume from specified vm.

func ExpandVolumeUtil

func ExpandVolumeUtil(ctx context.Context, manager *Manager, volumeID string, capacityInMb int64,
	useAsyncQueryVolume bool) (string, error)

ExpandVolumeUtil is the helper function to extend CNS volume for given volumeId.

func FormatDiskUUID

func FormatDiskUUID(uuid string) string

FormatDiskUUID removes any spaces and hyphens in UUID. Example UUID input is 42375390-71f9-43a3-a770-56803bcd7baa and output after format is 4237539071f943a3a77056803bcd7baa.

func GenerateDatastoreMapForBlockVolumes

func GenerateDatastoreMapForBlockVolumes(ctx context.Context,
	vc *cnsvsphere.VirtualCenter) (map[string]*cnsvsphere.DatastoreInfo, error)

GenerateDatastoreMapForBlockVolumes scans all datastores in Vcenter and do privilege check on those datastoes. It will return datastores which has the privileges for creating block volume.

func GenerateFSEnabledClustersToDsMap

func GenerateFSEnabledClustersToDsMap(ctx context.Context,
	vc *cnsvsphere.VirtualCenter) (map[string][]*cnsvsphere.DatastoreInfo, error)

GenerateFSEnabledClustersToDsMap scans all clusters in VC and do privilege check on them. It will return a map of cluster id to the list of datastore objects. The key is cluster moid with vSAN FS enabled and Host.Config.Storage privilege. The value is a list of vSAN datastoreInfo objects for the cluster.

func GetClusterComputeResourceMoIds added in v2.5.0

func GetClusterComputeResourceMoIds(ctx context.Context) ([]string, error)

GetClusterComputeResourceMoIds helps find ClusterComputeResourceMoIds from AvailabilityZone CRs on the supervisor cluster.

func GetCnsVolumeType added in v2.5.0

func GetCnsVolumeType(ctx context.Context, manager *Manager, volumeId string) (string, error)

GetCnsVolumeType is the helper function that determines the volume type based on the volume-id

func GetConfig

func GetConfig(ctx context.Context) (*cnsconfig.Config, error)

GetConfig loads configuration from secret and returns config object.

func GetConfigPath

func GetConfigPath(ctx context.Context) string

GetConfigPath returns ConfigPath depending on the environment variable specified and the cluster flavor set.

func GetK8sCloudOperatorServicePort

func GetK8sCloudOperatorServicePort(ctx context.Context) int

GetK8sCloudOperatorServicePort return the port to connect the K8sCloudOperator gRPC service. If environment variable POD_LISTENER_SERVICE_PORT is set and valid, return the interval value read from environment variable. Otherwise, use the default port.

func GetLabelsMapFromKeyValue

func GetLabelsMapFromKeyValue(labels []types.KeyValue) map[string]string

GetLabelsMapFromKeyValue creates a map object from given parameter.

func GetNodeVMsWithAccessToDatastore

func GetNodeVMsWithAccessToDatastore(ctx context.Context, vc *vsphere.VirtualCenter, dsURL string,
	allNodeVMs []*vsphere.VirtualMachine) ([]*object.VirtualMachine, error)

GetNodeVMsWithAccessToDatastore finds out NodeVMs which have access to the given datastore URL by using the moref approach.

func GetUUIDFromProviderID

func GetUUIDFromProviderID(providerID string) string

GetUUIDFromProviderID Returns VM UUID from Node's providerID.

func GetVCenter

func GetVCenter(ctx context.Context, manager *Manager) (*cnsvsphere.VirtualCenter, error)

GetVCenter returns VirtualCenter object from specified Manager object. Before returning VirtualCenter object, vcenter connection is established if session doesn't exist.

func GetVolumeCapabilityFsType

func GetVolumeCapabilityFsType(ctx context.Context, capability *csi.VolumeCapability) string

GetVolumeCapabilityFsType retrieves fstype from VolumeCapability. Defaults to nfs4 for file volume and ext4 for block volume when empty string is observed. This function also ignores default ext4 fstype supplied by external-provisioner when none is specified in the StorageClass

func InitConfigInfo

func InitConfigInfo(ctx context.Context) (*cnsconfig.ConfigurationInfo, error)

InitConfigInfo initializes the ConfigurationInfo struct.

func IsFileServiceEnabled

func IsFileServiceEnabled(ctx context.Context, datastoreUrls []string,
	vc *cnsvsphere.VirtualCenter, datacenters []*cnsvsphere.Datacenter) (map[string]bool, error)

IsFileServiceEnabled checks if file service is enabled on the specified datastoreUrls.

func IsFileVolumeRequest

func IsFileVolumeRequest(ctx context.Context, capabilities []*csi.VolumeCapability) bool

IsFileVolumeRequest checks whether the request is to create a CNS file volume.

func IsOnlineExpansion

func IsOnlineExpansion(ctx context.Context, volumeID string, nodes []*cnsvsphere.VirtualMachine) error

IsOnlineExpansion verifies if the input volume is attached to any of the given VirutalMachines, to prevent online expansion of volumes. Returns an error if the volume is attached.

func IsValidVolumeCapabilities

func IsValidVolumeCapabilities(ctx context.Context, volCaps []*csi.VolumeCapability) error

IsValidVolumeCapabilities helps validate the given volume capabilities based on volume type.

func IsVolumeReadOnly

func IsVolumeReadOnly(capability *csi.VolumeCapability) bool

IsVolumeReadOnly checks the access mode in Volume Capability and decides if volume is readonly or not.

func IsVolumeSnapshotReady added in v2.7.0

func IsVolumeSnapshotReady(ctx context.Context, client snapshotterClientSet.Interface,
	supervisorVolumeSnapshotName string, namespace string, timeout time.Duration) (bool, *snap.VolumeSnapshot, error)

IsVolumeSnapshotReady return true if the VolumeSnapshot is ReadyToUse

func IsvSphere8AndAbove added in v2.5.0

func IsvSphere8AndAbove(ctx context.Context, aboutInfo vim25types.AboutInfo) (bool, error)

IsvSphere8AndAbove returns true if vSphere version if 8.0 and above

func ListSnapshotsUtil

func ListSnapshotsUtil(ctx context.Context, volManager cnsvolume.Manager, volumeID string, snapshotID string,
	token string, maxEntries int64) ([]*csi.Snapshot, string, error)

func MergeMaps added in v2.7.0

func MergeMaps(first map[string]string, second map[string]string) map[string]string

MergeMaps merges two maps to create a new one, the key-value pair from first are replaced with key-value pair of second

func ParseCSISnapshotID

func ParseCSISnapshotID(csiSnapshotID string) (string, string, error)

ParseCSISnapshotID parses the SnapshotID from CSI RPC such as DeleteSnapshot, CreateVolume from snapshot into a pair of CNS VolumeID and CNS SnapshotID.

func QueryAllVolumeSnapshots

func QueryAllVolumeSnapshots(ctx context.Context, volManager cnsvolume.Manager, token string, maxEntries int64) (
	[]*csi.Snapshot, string, error)

func QueryVolumeByID

func QueryVolumeByID(ctx context.Context, volManager cnsvolume.Manager, volumeID string) (*cnstypes.CnsVolume, error)

QueryVolumeByID is the helper function to query volume by volumeID.

func QueryVolumeSnapshot

func QueryVolumeSnapshot(ctx context.Context, volManager cnsvolume.Manager, volID string, snapID string,
	maxEntries int64) ([]*csi.Snapshot, error)

func QueryVolumeSnapshotsByVolumeID

func QueryVolumeSnapshotsByVolumeID(ctx context.Context, volManager cnsvolume.Manager, volumeID string,
	maxEntries int64) ([]*csi.Snapshot, string, error)

func RoundUpSize

func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64

RoundUpSize calculates how many allocation units are needed to accommodate a volume of given size.

func UseVslmAPIs

func UseVslmAPIs(ctx context.Context, aboutInfo vim25types.AboutInfo) (bool, error)

UseVslmAPIs checks if specified version is between 6.7 Update 3l and 7.0. The method takes aboutInfo{} as input which contains details about VC version, build number and so on. If the version is between the upper and lower bounds, the method returns true, else returns false and appropriate errors during failure cases.

func ValidateControllerExpandVolumeRequest

func ValidateControllerExpandVolumeRequest(ctx context.Context, req *csi.ControllerExpandVolumeRequest) error

ValidateControllerExpandVolumeRequest is the helper function to validate ControllerExpandVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

func ValidateControllerPublishVolumeRequest

func ValidateControllerPublishVolumeRequest(ctx context.Context, req *csi.ControllerPublishVolumeRequest) error

ValidateControllerPublishVolumeRequest is the helper function to validate ControllerPublishVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

func ValidateControllerUnpublishVolumeRequest

func ValidateControllerUnpublishVolumeRequest(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) error

ValidateControllerUnpublishVolumeRequest is the helper function to validate ControllerUnpublishVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

func ValidateCreateVolumeRequest

func ValidateCreateVolumeRequest(ctx context.Context, req *csi.CreateVolumeRequest) error

ValidateCreateVolumeRequest is the helper function to validate CreateVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

func ValidateDeleteVolumeRequest

func ValidateDeleteVolumeRequest(ctx context.Context, req *csi.DeleteVolumeRequest) error

ValidateDeleteVolumeRequest is the helper function to validate DeleteVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

Types

type AuthManager

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

AuthManager maintains an internal map to track the datastores that need to be used by create volume.

func (*AuthManager) GetDatastoreMapForBlockVolumes

func (authManager *AuthManager) GetDatastoreMapForBlockVolumes(
	ctx context.Context) map[string]*cnsvsphere.DatastoreInfo

GetDatastoreMapForBlockVolumes returns a DatastoreMapForBlockVolumes. This map maps datastore url to datastore info which need to be used when creating block volume.

func (*AuthManager) GetFsEnabledClusterToDsMap

func (authManager *AuthManager) GetFsEnabledClusterToDsMap(
	ctx context.Context) map[string][]*cnsvsphere.DatastoreInfo

GetFsEnabledClusterToDsMap returns a map of cluster ID with vSAN file services enabled to its datastore info objects.

func (*AuthManager) ResetvCenterInstance

func (authManager *AuthManager) ResetvCenterInstance(ctx context.Context, vCenter *cnsvsphere.VirtualCenter)

ResetvCenterInstance sets new vCenter instance for AuthorizationService.

type AuthorizationService

type AuthorizationService interface {
	// GetDatastoreMapForBlockVolumes returns a map of datastore URL to datastore
	// info for only those datastores the CSI VC user has Datastore.FileManagement
	// privilege for.
	GetDatastoreMapForBlockVolumes(ctx context.Context) map[string]*cnsvsphere.DatastoreInfo

	// GetFsEnabledClusterToDsMap returns a map of cluster ID to datastores info
	// objects for vSAN clusters with file services enabled. The datastores are
	// those on which the CSI VC user has Host.Config.Storage privilege.
	GetFsEnabledClusterToDsMap(ctx context.Context) map[string][]*cnsvsphere.DatastoreInfo

	// ResetvCenterInstance sets new vCenter instance for AuthorizationService
	ResetvCenterInstance(ctx context.Context, vCenter *cnsvsphere.VirtualCenter)
}

AuthorizationService exposes interfaces to support authorization check on datastores and get datastores which will be used by create volume. It is provided for backward compatibility. For latest vSphere release, this service is redundant.

func GetAuthorizationService

func GetAuthorizationService(ctx context.Context, vc *cnsvsphere.VirtualCenter) (AuthorizationService, error)

GetAuthorizationService returns the singleton AuthorizationService.

type CreateVolumeSpec

type CreateVolumeSpec struct {
	Name     string
	ScParams *StorageClassParams
	// TODO: Move this StorageClassParams
	StoragePolicyID string
	CapacityMB      int64
	// TODO: Move this StorageClassParams
	AffineToHost            string
	VolumeType              string
	VsanDirectDatastoreURL  string // Datastore URL from vSan direct storage pool
	ContentSourceSnapshotID string // SnapshotID from VolumeContentSource in CreateVolumeRequest
}

CreateVolumeSpec is the Volume Spec used by CSI driver

type InvalidTopologyProvisioningError added in v2.6.0

type InvalidTopologyProvisioningError struct {
	ErrMsg string
}

InvalidTopologyProvisioningError is raised when volume provisioning fails on a topology aware setup due to an invalid setting.

func (*InvalidTopologyProvisioningError) Error added in v2.6.0

type Manager

type Manager struct {
	VcenterConfig  *cnsvsphere.VirtualCenterConfig
	CnsConfig      *config.Config
	VolumeManager  cnsvolume.Manager
	VcenterManager cnsvsphere.VirtualCenterManager
}

Manager type comprises VirtualCenterConfig, CnsConfig, VolumeManager and VirtualCenterManager

type StorageClassParams

type StorageClassParams struct {
	DatastoreURL      string
	StoragePolicyName string
	CSIMigration      string
	Datastore         string
}

StorageClassParams represents the storage class parameterss

func ParseStorageClassParams

func ParseStorageClassParams(ctx context.Context, params map[string]string,
	csiMigrationFeatureState bool) (*StorageClassParams, error)

ParseStorageClassParams parses the params in the CSI CreateVolumeRequest API call back to StorageClassParams structure.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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