common

package
v3.0.2-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 39 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"

	// Ext3FsType represents the ext3 filesystem type for block volume.
	Ext3FsType = "ext3"

	// XFSType represents the xfs filesystem type for block volume.
	XFSType = "xfs"

	// 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"
	// 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"
	// 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"
	// MultiVCenterCSITopology is the feature gate for enabling multi vCenter topology support for vSphere CSI driver.
	MultiVCenterCSITopology = "multi-vcenter-csi-topology"
	// CSIInternalGeneratedClusterID enables support to generate unique cluster
	// ID internally if user doesn't provide it in vSphere config secret.
	CSIInternalGeneratedClusterID = "csi-internal-generated-cluster-id"
	// ListViewPerf uses govmomi ListView to wait for CNS tasks
	ListViewPerf = "listview-tasks"
)

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")
View Source
var (

	// PreferredDatastoresExist signifies if preferred datastores are present in the cluster.
	PreferredDatastoresExist bool
)

Functions

func AddLabelsToTopologyVCMap

func AddLabelsToTopologyVCMap(ctx context.Context, nodeTopoObj csinodetopologyv1alpha1.CSINodeTopology)

AddLabelsToTopologyVCMap adds topology label to VC mapping for given CSINodeTopology instance in the topologyVCMap variable.

func AddNodeToDomainNodeMapNew

func AddNodeToDomainNodeMapNew(ctx context.Context, nodeTopoObj csinodetopologyv1alpha1.CSINodeTopology)

AddNodeToDomainNodeMapNew adds the CR instance name in the domainNodeMap wherever appropriate.

func AttachVolumeUtil

func AttachVolumeUtil(ctx context.Context, volumeManager cnsvolume.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

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,
	checkCompatibleDataStores bool) (*cnsvolume.CnsVolumeInfo, string, error)

CreateBlockVolumeUtil is the helper function to create CNS block volume.

func CreateBlockVolumeUtilForMultiVC

func CreateBlockVolumeUtilForMultiVC(ctx context.Context, reqParams interface{}) (
	*cnsvolume.CnsVolumeInfo, string, error)

CreateBlockVolumeUtilForMultiVC is the helper function to create CNS block volume when multi-VC FSS is enabled.

func CreateFileVolumeUtil

func CreateFileVolumeUtil(ctx context.Context, clusterFlavor cnstypes.CnsClusterFlavor,
	vc *vsphere.VirtualCenter, volumeManager cnsvolume.Manager, cnsConfig *config.Config, spec *CreateVolumeSpec,
	datastores []*vsphere.DatastoreInfo,
	filterSuspendedDatastores bool, useSupervisorId,
	checkCompatibleDataStores bool) (string, string, error)

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

func CreateSnapshotUtil

func CreateSnapshotUtil(ctx context.Context, volumeManager cnsvolume.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, volumeManager cnsvolume.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, volumeManager cnsvolume.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, vCenterManager vsphere.VirtualCenterManager,
	vCenterHost string, volumeManager cnsvolume.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 GetAccessibilityRequirementsByVC

func GetAccessibilityRequirementsByVC(ctx context.Context, topoReq *csi.TopologyRequirement) (
	map[string][]map[string]string, error)

GetAccessibilityRequirementsByVC clubs the accessibility requirements by the VC they belong to.

func GetAuthorizationServices

func GetAuthorizationServices(ctx context.Context, vcs []*cnsvsphere.VirtualCenter) (map[string]*AuthManager, error)

GetAuthorizationServices returns the AuthManager instances for supplied vCenter servers

func GetCSINamespace

func GetCSINamespace() string

GetCSINamespace returns the namespace in which CSI driver is installed

func GetClusterComputeResourceMoIds

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

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

func GetCnsVolumeType

func GetCnsVolumeType(ctx context.Context, volumeManager cnsvolume.Manager, volumeId string) (string, error)

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

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 GetPreferredDatastoresInSegments

func GetPreferredDatastoresInSegments(ctx context.Context, segments map[string]string,
	vcHost string) map[string]struct{}

GetPreferredDatastoresInSegments fetches preferred datastores in given topology segments as a map for faster retrieval.

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 GetVCenterFromVCHost

func GetVCenterFromVCHost(ctx context.Context, vCenterManager cnsvsphere.VirtualCenterManager,
	vCenterHost string) (*cnsvsphere.VirtualCenter, error)

GetVCenterFromVCHost returns VirtualCenter object from specified VC host. Before returning VirtualCenter objects, vcenter connection is established if session doesn't exist.

func GetVCenters

func GetVCenters(ctx context.Context, managers *Managers) ([]*cnsvsphere.VirtualCenter, error)

GetVCenters returns VirtualCenter object from specified Managers object. Before returning VirtualCenter objects, vcenter connection is established if session doesn't exist.

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

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

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

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,
	querySelection *cnstypes.CnsQuerySelection) (*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 RefreshPreferentialDatastoresForMultiVCenter

func RefreshPreferentialDatastoresForMultiVCenter(ctx context.Context) error

RefreshPreferentialDatastoresForMultiVCenter refreshes the preferredDatastoresMap variable with the latest information on the preferential datastores for each topology domain across all vCenter Servers

func RemoveLabelsFromTopologyVCMap

func RemoveLabelsFromTopologyVCMap(ctx context.Context, nodeTopoObj csinodetopologyv1alpha1.CSINodeTopology)

RemoveLabelsFromTopologyVCMap removes the topology label to VC mapping for given CSINodeTopology instance in the topologyVCMap variable.

func RemoveNodeFromDomainNodeMapNew

func RemoveNodeFromDomainNodeMapNew(ctx context.Context, nodeTopoObj csinodetopologyv1alpha1.CSINodeTopology)

RemoveNodeFromDomainNodeMapNew removes the CR instance name from the domainNodeMap.

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.

func VerifyAllNodesInTopologyAccessibleToDatastore

func VerifyAllNodesInTopologyAccessibleToDatastore(ctx context.Context, nodeNames []string,
	datastoreURL string, topologySegments []map[string]string) ([]map[string]string, error)

VerifyAllNodesInTopologyAccessibleToDatastore verifies whether all the nodes present in a topology segment have access to the given datastore.

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

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

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 Managers

type Managers struct {
	// map of VC Host to *VirtualCenterConfig
	VcenterConfigs map[string]*cnsvsphere.VirtualCenterConfig
	CnsConfig      *config.Config
	// map of VC Host to Volume Manager
	VolumeManagers map[string]cnsvolume.Manager
	VcenterManager cnsvsphere.VirtualCenterManager
}

Managers type comprises VirtualCenterConfigs, CnsConfig, VolumeManagers and VirtualCenterManager If k8s cluster is deployed on single vCenter server VcenterConfigs and VolumeManagers will hold single entry if k8s cluster is deployed on multi vCenter server, we will have VirtualCenterConfig and VolumeManagers for each participating vCenter server.

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.

type VanillaCreateBlockVolParamsForMultiVC

type VanillaCreateBlockVolParamsForMultiVC struct {
	Vcenter                   *vsphere.VirtualCenter
	VolumeManager             cnsvolume.Manager
	CNSConfig                 *config.Config
	StoragePolicyID           string
	Spec                      *CreateVolumeSpec
	SharedDatastores          []*vsphere.DatastoreInfo
	SnapshotDatastoreURL      string
	ClusterFlavor             cnstypes.CnsClusterFlavor
	FilterSuspendedDatastores bool
}

VanillaCreateBlockVolParamsForMultiVC stores the parameters required to call CreateBlockVolumeUtilForMultiVC function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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