const readyFileName … const ControllerManagedAttachAnnotation … const MountsInGlobalPDPath … const VolumeGidAnnotationKey … const VolumeDynamicallyCreatedByKey … const kubernetesPluginPathPrefix … // IsReady checks for the existence of a regular file // called 'ready' in the given directory and returns // true if that file exists. func IsReady(dir string) bool { … } // SetReady creates a file called 'ready' in the given // directory. It logs an error if the file cannot be // created. func SetReady(dir string) { … } // GetSecretForPV locates secret by name and namespace, verifies the secret type, and returns secret map func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeClient clientset.Interface) (map[string]string, error) { … } // LoadPodFromFile will read, decode, and return a Pod from a file. func LoadPodFromFile(filePath string) (*v1.Pod, error) { … } // CalculateTimeoutForVolume calculates time for a Recycler pod to complete a // recycle operation. The calculation and return value is either the // minimumTimeout or the timeoutIncrement per Gi of storage size, whichever is // greater. func CalculateTimeoutForVolume(minimumTimeout, timeoutIncrement int, pv *v1.PersistentVolume) int64 { … } // GetPath checks if the path from the mounter is empty. func GetPath(mounter volume.Mounter) (string, error) { … } // UnmountViaEmptyDir delegates the tear down operation for secret, configmap, git_repo and downwardapi // to empty_dir func UnmountViaEmptyDir(dir string, host volume.VolumeHost, volName string, volSpec volume.Spec, podUID utypes.UID) error { … } // MountOptionFromSpec extracts and joins mount options from volume spec with supplied options func MountOptionFromSpec(spec *volume.Spec, options ...string) []string { … } // JoinMountOptions joins mount options eliminating duplicates func JoinMountOptions(userOptions []string, systemOptions []string) []string { … } // ContainsAccessMode returns whether the requested mode is contained by modes func ContainsAccessMode(modes []v1.PersistentVolumeAccessMode, mode v1.PersistentVolumeAccessMode) bool { … } // ContainsAllAccessModes returns whether all of the requested modes are contained by modes func ContainsAllAccessModes(indexedModes []v1.PersistentVolumeAccessMode, requestedModes []v1.PersistentVolumeAccessMode) bool { … } // GetWindowsPath get a windows path func GetWindowsPath(path string) string { … } // GetUniquePodName returns a unique identifier to reference a pod by func GetUniquePodName(pod *v1.Pod) types.UniquePodName { … } // GetUniqueVolumeName returns a unique name representing the volume/plugin. // Caller should ensure that volumeName is a name/ID uniquely identifying the // actual backing device, directory, path, etc. for a particular volume. // The returned name can be used to uniquely reference the volume, for example, // to prevent operations (attach/detach or mount/unmount) from being triggered // on the same volume. func GetUniqueVolumeName(pluginName, volumeName string) v1.UniqueVolumeName { … } // GetUniqueVolumeNameFromSpecWithPod returns a unique volume name with pod // name included. This is useful to generate different names for different pods // on same volume. func GetUniqueVolumeNameFromSpecWithPod( podName types.UniquePodName, volumePlugin volume.VolumePlugin, volumeSpec *volume.Spec) v1.UniqueVolumeName { … } // GetUniqueVolumeNameFromSpec uses the given VolumePlugin to generate a unique // name representing the volume defined in the specified volume spec. // This returned name can be used to uniquely reference the actual backing // device, directory, path, etc. referenced by the given volumeSpec. // If the given plugin does not support the volume spec, this returns an error. func GetUniqueVolumeNameFromSpec( volumePlugin volume.VolumePlugin, volumeSpec *volume.Spec) (v1.UniqueVolumeName, error) { … } // IsPodTerminated checks if pod is terminated func IsPodTerminated(pod *v1.Pod, podStatus v1.PodStatus) bool { … } // notRunning returns true if every status is terminated or waiting, or the status list // is empty. func notRunning(statuses []v1.ContainerStatus) bool { … } // SplitUniqueName splits the unique name to plugin name and volume name strings. It expects the uniqueName to follow // the format plugin_name/volume_name and the plugin name must be namespaced as described by the plugin interface, // i.e. namespace/plugin containing exactly one '/'. This means the unique name will always be in the form of // plugin_namespace/plugin/volume_name, see k8s.io/kubernetes/pkg/volume/plugins.go VolumePlugin interface // description and pkg/volume/util/volumehelper/volumehelper.go GetUniqueVolumeNameFromSpec that constructs // the unique volume names. func SplitUniqueName(uniqueName v1.UniqueVolumeName) (string, string, error) { … } // NewSafeFormatAndMountFromHost creates a new SafeFormatAndMount with Mounter // and Exec taken from given VolumeHost. func NewSafeFormatAndMountFromHost(pluginName string, host volume.VolumeHost) *mount.SafeFormatAndMount { … } // GetVolumeMode retrieves VolumeMode from pv. // If the volume doesn't have PersistentVolume, it's an inline volume, // should return volumeMode as filesystem to keep existing behavior. func GetVolumeMode(volumeSpec *volume.Spec) (v1.PersistentVolumeMode, error) { … } // GetPersistentVolumeClaimQualifiedName returns a qualified name for pvc. func GetPersistentVolumeClaimQualifiedName(claim *v1.PersistentVolumeClaim) string { … } // CheckVolumeModeFilesystem checks VolumeMode. // If the mode is Filesystem, return true otherwise return false. func CheckVolumeModeFilesystem(volumeSpec *volume.Spec) (bool, error) { … } // CheckPersistentVolumeClaimModeBlock checks VolumeMode. // If the mode is Block, return true otherwise return false. func CheckPersistentVolumeClaimModeBlock(pvc *v1.PersistentVolumeClaim) bool { … } // IsWindowsUNCPath checks if path is prefixed with \\ // This can be used to skip any processing of paths // that point to SMB shares, local named pipes and local UNC path func IsWindowsUNCPath(goos, path string) bool { … } // IsWindowsLocalPath checks if path is a local path // prefixed with "/" or "\" like "/foo/bar" or "\foo\bar" func IsWindowsLocalPath(goos, path string) bool { … } // MakeAbsolutePath convert path to absolute path according to GOOS func MakeAbsolutePath(goos, path string) string { … } // MapBlockVolume is a utility function to provide a common way of mapping // block device path for a specified volume and pod. This function should be // called by volume plugins that implements volume.BlockVolumeMapper.Map() method. func MapBlockVolume( blkUtil volumepathhandler.BlockVolumePathHandler, devicePath, globalMapPath, podVolumeMapPath, volumeMapName string, podUID utypes.UID, ) error { … } // UnmapBlockVolume is a utility function to provide a common way of unmapping // block device path for a specified volume and pod. This function should be // called by volume plugins that implements volume.BlockVolumeMapper.Map() method. func UnmapBlockVolume( blkUtil volumepathhandler.BlockVolumePathHandler, globalUnmapPath, podDeviceUnmapPath, volumeMapName string, podUID utypes.UID, ) error { … } // IsLocalEphemeralVolume determines whether the argument is a local ephemeral // volume vs. some other type // Local means the volume is using storage from the local disk that is managed by kubelet. // Ephemeral means the lifecycle of the volume is the same as the Pod. func IsLocalEphemeralVolume(volume v1.Volume) bool { … } // GetPodVolumeNames returns names of volumes that are used in a pod, // either as filesystem mount or raw block device. // To save another sweep through containers, SELinux options are optionally collected too. func GetPodVolumeNames(pod *v1.Pod, collectSELinuxOptions bool) (mounts sets.Set[string], devices sets.Set[string], seLinuxContainerContexts map[string][]*v1.SELinuxOptions) { … } // FsUserFrom returns FsUser of pod, which is determined by the runAsUser // attributes. func FsUserFrom(pod *v1.Pod) *int64 { … } // HasMountRefs checks if the given mountPath has mountRefs. // TODO: this is a workaround for the unmount device issue caused by gci mounter. // In GCI cluster, if gci mounter is used for mounting, the container started by mounter // script will cause additional mounts created in the container. Since these mounts are // irrelevant to the original mounts, they should be not considered when checking the // mount references. The current solution is to filter out those mount paths that contain // the k8s plugin suffix of original mount path. func HasMountRefs(mountPath string, mountRefs []string) bool { … } // IsMultiAttachAllowed checks if attaching this volume to multiple nodes is definitely not allowed/possible. // In its current form, this function can only reliably say for which volumes it's definitely forbidden. If it returns // false, it is not guaranteed that multi-attach is actually supported by the volume type and we must rely on the // attacher to fail fast in such cases. // Please see https://github.com/kubernetes/kubernetes/issues/40669 and https://github.com/kubernetes/kubernetes/pull/40148#discussion_r98055047 func IsMultiAttachAllowed(volumeSpec *volume.Spec) bool { … } // IsAttachableVolume checks if the given volumeSpec is an attachable volume or not func IsAttachableVolume(volumeSpec *volume.Spec, volumePluginMgr *volume.VolumePluginMgr) bool { … } // IsDeviceMountableVolume checks if the given volumeSpec is an device mountable volume or not func IsDeviceMountableVolume(volumeSpec *volume.Spec, volumePluginMgr *volume.VolumePluginMgr) bool { … } // GetReliableMountRefs calls mounter.GetMountRefs and retries on IsInconsistentReadError. // To be used in volume reconstruction of volume plugins that don't have any protection // against mounting a single volume on multiple nodes (such as attach/detach). func GetReliableMountRefs(mounter mount.Interface, mountPath string) ([]string, error) { … }