Documentation ¶
Overview ¶
Contains utility code for use by volume plugins.
Index ¶
- Constants
- func CheckNodeAffinity(pv *v1.PersistentVolume, nodeLabels map[string]string) error
- func ClaimToClaimKey(claim *v1.PersistentVolumeClaim) string
- func Du(path string) (*resource.Quantity, error)
- func Find(path string) (int64, error)
- func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error)
- func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error)
- func GetSecretForPV(secretNamespace, secretName, volumePluginName string, ...) (map[string]string, error)
- func GetSecretForPod(pod *v1.Pod, secretName string, kubeClient clientset.Interface) (map[string]string, error)
- func IsReady(dir string) bool
- func LabelZonesToSet(labelZonesValue string) (sets.String, error)
- func LoadPodFromFile(filePath string) (*v1.Pod, error)
- func MarkFSResizeFinished(pvc *v1.PersistentVolumeClaim, capacity v1.ResourceList, ...) error
- func MergeResizeConditionOnPVC(pvc *v1.PersistentVolumeClaim, ...) *v1.PersistentVolumeClaim
- func NewDanglingError(msg string, node k8stypes.NodeName, devicePath string) error
- func OperationCompleteHook(plugin, operationName string) func(*error)
- func PatchPVCStatus(oldPVC *v1.PersistentVolumeClaim, newPVC *v1.PersistentVolumeClaim, ...) (*v1.PersistentVolumeClaim, error)
- func PathExists(path string) (bool, error)
- func SetReady(dir string)
- func UnmountMountPoint(mountPath string, mounter mount.Interface, extensiveMountPointCheck bool) error
- func UnmountPath(mountPath string, mounter mount.Interface) error
- func ZonesSetToLabelValue(strSet sets.String) string
- func ZonesToSet(zonesString string) (sets.String, error)
- type AtomicWriter
- type BlockVolumePathHandler
- type DanglingAttachError
- type DeviceUtil
- type FileProjection
- type IoUtil
- type VolumePathHandler
- func (v VolumePathHandler) AttachFileDevice(path string) (string, error)
- func (v VolumePathHandler) FindGlobalMapPathUUIDFromPod(pluginDir, mapPath string, podUID types.UID) (string, error)
- func (v VolumePathHandler) GetDeviceSymlinkRefs(devPath string, mapPath string) ([]string, error)
- func (v VolumePathHandler) GetLoopDevice(path string) (string, error)
- func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error)
- func (v VolumePathHandler) MapDevice(devicePath string, mapPath string, linkName string) error
- func (v VolumePathHandler) RemoveLoopDevice(device string) error
- func (v VolumePathHandler) RemoveMapPath(mapPath string) error
- func (v VolumePathHandler) UnmapDevice(mapPath string, linkName string) error
Constants ¶
const ( // Name of finalizer on PVCs that have a running pod. PVCProtectionFinalizer = "kubernetes.io/pvc-protection" // Name of finalizer on PVs that are bound by PVCs PVProtectionFinalizer = "kubernetes.io/pv-protection" )
const ( ErrDeviceNotFound = "device not found" ErrDeviceNotSupported = "device not supported" )
Variables ¶
This section is empty.
Functions ¶
func CheckNodeAffinity ¶
func CheckNodeAffinity(pv *v1.PersistentVolume, nodeLabels map[string]string) error
CheckNodeAffinity looks at the PV node affinity, and checks if the node has the same corresponding labels This ensures that we don't mount a volume that doesn't belong to this node
func ClaimToClaimKey ¶
func ClaimToClaimKey(claim *v1.PersistentVolumeClaim) string
ClaimToClaimKey return namespace/name string for pvc
func Find ¶
Find uses the equivalent of the command `find <path> -dev -printf '.' | wc -c` to count files and directories. While this is not an exact measure of inodes used, it is a very good approximation.
func FsInfo ¶
FSInfo linux returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error) for the filesystem that path resides upon.
func GetClassForVolume ¶
func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error)
func GetSecretForPV ¶
func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeClient clientset.Interface) (map[string]string, error)
GetSecretForPV locates secret by name and namespace, verifies the secret type, and returns secret map
func GetSecretForPod ¶
func GetSecretForPod(pod *v1.Pod, secretName string, kubeClient clientset.Interface) (map[string]string, error)
GetSecretForPod locates secret by name in the pod's namespace and returns secret map
func IsReady ¶
IsReady checks for the existence of a regular file called 'ready' in the given directory and returns true if that file exists.
func LabelZonesToSet ¶
LabelZonesToSet converts a PV label value from string containing a delimited list of zones to set
func LoadPodFromFile ¶
LoadPodFromFile will read, decode, and return a Pod from a file.
func MarkFSResizeFinished ¶
func MarkFSResizeFinished( pvc *v1.PersistentVolumeClaim, capacity v1.ResourceList, kubeClient clientset.Interface) error
MarkFSResizeFinished marks file system resizing as done
func MergeResizeConditionOnPVC ¶
func MergeResizeConditionOnPVC( pvc *v1.PersistentVolumeClaim, resizeConditions []v1.PersistentVolumeClaimCondition) *v1.PersistentVolumeClaim
MergeResizeConditionOnPVC updates pvc with requested resize conditions leaving other conditions untouched.
func NewDanglingError ¶
func OperationCompleteHook ¶
OperationCompleteHook returns a hook to call when an operation is completed
func PatchPVCStatus ¶
func PatchPVCStatus( oldPVC *v1.PersistentVolumeClaim, newPVC *v1.PersistentVolumeClaim, kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)
PatchPVCStatus updates PVC status using PATCH verb
func PathExists ¶
PathExists returns true if the specified path exists.
func SetReady ¶
func SetReady(dir string)
SetReady creates a file called 'ready' in the given directory. It logs an error if the file cannot be created.
func UnmountMountPoint ¶
func UnmountMountPoint(mountPath string, mounter mount.Interface, extensiveMountPointCheck bool) error
UnmountMountPoint is a common unmount routine that unmounts the given path and deletes the remaining directory if successful. if extensiveMountPointCheck is true IsNotMountPoint will be called instead of IsLikelyNotMountPoint. IsNotMountPoint is more expensive but properly handles bind mounts.
func UnmountPath ¶
UnmountPath is a common unmount routine that unmounts the given path and deletes the remaining directory if successful.
func ZonesSetToLabelValue ¶
Types ¶
type AtomicWriter ¶
type AtomicWriter struct {
// contains filtered or unexported fields
}
AtomicWriter handles atomically projecting content for a set of files into a target directory.
Note:
- AtomicWriter reserves the set of pathnames starting with `..`.
- AtomicWriter offers no concurrency guarantees and must be synchronized by the caller.
The visible files in this volume are symlinks to files in the writer's data directory. Actual files are stored in a hidden timestamped directory which is symlinked to by the data directory. The timestamped directory and data directory symlink are created in the writer's target dir. This scheme allows the files to be atomically updated by changing the target of the data directory symlink.
Consumers of the target directory can monitor the ..data symlink using inotify or fanotify to receive events when the content in the volume is updated.
func NewAtomicWriter ¶
func NewAtomicWriter(targetDir string, logContext string) (*AtomicWriter, error)
NewAtomicWriter creates a new AtomicWriter configured to write to the given target directory, or returns an error if the target directory does not exist.
func (*AtomicWriter) Write ¶
func (w *AtomicWriter) Write(payload map[string]FileProjection) error
Write does an atomic projection of the given payload into the writer's target directory. Input paths must not begin with '..'.
The Write algorithm is:
The payload is validated; if the payload is invalid, the function returns 2. The current timestamped directory is detected by reading the data directory symlink
The old version of the volume is walked to determine whether any portion of the payload was deleted and is still present on disk.
The data in the current timestamped directory is compared to the projected data to determine if an update is required. 5. A new timestamped dir is created
The payload is written to the new timestamped directory 7. Symlinks and directory for new user-visible files are created (if needed).
For example, consider the files: <target-dir>/podName <target-dir>/user/labels <target-dir>/k8s/annotations
The user visible files are symbolic links into the internal data directory: <target-dir>/podName -> ..data/podName <target-dir>/usr -> ..data/usr <target-dir>/k8s -> ..data/k8s
The data directory itself is a link to a timestamped directory with the real data: <target-dir>/..data -> ..2016_02_01_15_04_05.12345678/ 8. A symlink to the new timestamped directory ..data_tmp is created that will become the new data directory 9. The new data directory symlink is renamed to the data directory; rename is atomic
10. Old paths are removed from the user-visible portion of the target directory 11. The previous timestamped directory is removed, if it exists
type BlockVolumePathHandler ¶
type BlockVolumePathHandler interface { // MapDevice creates a symbolic link to block device under specified map path MapDevice(devicePath string, mapPath string, linkName string) error // UnmapDevice removes a symbolic link to block device under specified map path UnmapDevice(mapPath string, linkName string) error // RemovePath removes a file or directory on specified map path RemoveMapPath(mapPath string) error // IsSymlinkExist retruns true if specified symbolic link exists IsSymlinkExist(mapPath string) (bool, error) // GetDeviceSymlinkRefs searches symbolic links under global map path GetDeviceSymlinkRefs(devPath string, mapPath string) ([]string, error) // FindGlobalMapPathUUIDFromPod finds {pod uuid} symbolic link under globalMapPath // corresponding to map path symlink, and then return global map path with pod uuid. FindGlobalMapPathUUIDFromPod(pluginDir, mapPath string, podUID types.UID) (string, error) // AttachFileDevice takes a path to a regular file and makes it available as an // attached block device. AttachFileDevice(path string) (string, error) // GetLoopDevice returns the full path to the loop device associated with the given path. GetLoopDevice(path string) (string, error) // RemoveLoopDevice removes specified loopback device RemoveLoopDevice(device string) error }
BlockVolumePathHandler defines a set of operations for handling block volume-related operations
func NewBlockVolumePathHandler ¶
func NewBlockVolumePathHandler() BlockVolumePathHandler
NewBlockVolumePathHandler returns a new instance of BlockVolumeHandler.
type DanglingAttachError ¶
type DanglingAttachError struct { CurrentNode k8stypes.NodeName DevicePath string // contains filtered or unexported fields }
This error on attach indicates volume is attached to a different node than we expected.
func (*DanglingAttachError) Error ¶
func (err *DanglingAttachError) Error() string
type DeviceUtil ¶
type DeviceUtil interface { FindMultipathDeviceForDevice(disk string) string FindSlaveDevicesOnMultipath(disk string) []string }
DeviceUtil is a util for common device methods
func NewDeviceHandler ¶
func NewDeviceHandler(io IoUtil) DeviceUtil
NewDeviceHandler Create a new IoHandler implementation
type FileProjection ¶
type IoUtil ¶
type IoUtil interface { ReadDir(dirname string) ([]os.FileInfo, error) Lstat(name string) (os.FileInfo, error) EvalSymlinks(path string) (string, error) }
IoUtil is a mockable util for common IO operations
type VolumePathHandler ¶
type VolumePathHandler struct { }
VolumePathHandler is path related operation handlers for block volume
func (VolumePathHandler) AttachFileDevice ¶
func (v VolumePathHandler) AttachFileDevice(path string) (string, error)
AttachFileDevice takes a path to a regular file and makes it available as an attached block device.
func (VolumePathHandler) FindGlobalMapPathUUIDFromPod ¶
func (v VolumePathHandler) FindGlobalMapPathUUIDFromPod(pluginDir, mapPath string, podUID types.UID) (string, error)
FindGlobalMapPathUUIDFromPod finds {pod uuid} symbolic link under globalMapPath corresponding to map path symlink, and then return global map path with pod uuid. ex. mapPath symlink: pods/{podUid}}/{DefaultKubeletVolumeDevicesDirName}/{escapeQualifiedPluginName}/{volumeName} -> /dev/sdX
globalMapPath/{pod uuid}: plugins/kubernetes.io/{PluginName}/{DefaultKubeletVolumeDevicesDirName}/{volumePluginDependentPath}/{pod uuid} -> /dev/sdX
func (VolumePathHandler) GetDeviceSymlinkRefs ¶
func (v VolumePathHandler) GetDeviceSymlinkRefs(devPath string, mapPath string) ([]string, error)
GetDeviceSymlinkRefs searches symbolic links under global map path
func (VolumePathHandler) GetLoopDevice ¶
func (v VolumePathHandler) GetLoopDevice(path string) (string, error)
GetLoopDevice returns the full path to the loop device associated with the given path.
func (VolumePathHandler) IsSymlinkExist ¶
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error)
IsSymlinkExist returns true if specified file exists and the type is symbolik link. If file doesn't exist, or file exists but not symbolick link, return false with no error. On other cases, return false with error from Lstat().
func (VolumePathHandler) MapDevice ¶
func (v VolumePathHandler) MapDevice(devicePath string, mapPath string, linkName string) error
MapDevice creates a symbolic link to block device under specified map path
func (VolumePathHandler) RemoveLoopDevice ¶
func (v VolumePathHandler) RemoveLoopDevice(device string) error
RemoveLoopDevice removes specified loopback device
func (VolumePathHandler) RemoveMapPath ¶
func (v VolumePathHandler) RemoveMapPath(mapPath string) error
RemoveMapPath removes a file or directory on specified map path
func (VolumePathHandler) UnmapDevice ¶
func (v VolumePathHandler) UnmapDevice(mapPath string, linkName string) error
UnmapDevice removes a symbolic link associated to block device under specified map path
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package nestedpendingoperations is a modified implementation of pkg/util/goroutinemap.
|
Package nestedpendingoperations is a modified implementation of pkg/util/goroutinemap. |
Package operationexecutor implements interfaces that enable execution of attach, detach, mount, and unmount operations with a nestedpendingoperations so that more than one operation is never triggered on the same volume for the same pod.
|
Package operationexecutor implements interfaces that enable execution of attach, detach, mount, and unmount operations with a nestedpendingoperations so that more than one operation is never triggered on the same volume for the same pod. |
Package types defines types used only by volume components
|
Package types defines types used only by volume components |
Package volumehelper contains consts and helper methods used by various volume components (attach/detach controller, kubelet, etc.).
|
Package volumehelper contains consts and helper methods used by various volume components (attach/detach controller, kubelet, etc.). |