util

package
v1.30.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: Apache-2.0 Imports: 55 Imported by: 2,199

Documentation

Overview

Package util contains utility code for use by volume plugins.

Index

Constants

View Source
const (
	// EBSVolumeLimitKey resource name that will store volume limits for EBS
	EBSVolumeLimitKey = "attachable-volumes-aws-ebs"
	// EBSNitroLimitRegex finds nitro instance types with different limit than EBS defaults
	EBSNitroLimitRegex = "^[cmr]5.*|t3|z1d"
	// DefaultMaxEBSVolumes is the limit for volumes attached to an instance.
	// Amazon recommends no more than 40; the system root volume uses at least one.
	// See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/volume_limits.html#linux-specific-volume-limits
	DefaultMaxEBSVolumes = 39
	// DefaultMaxEBSNitroVolumeLimit is default EBS volume limit on m5 and c5 instances
	DefaultMaxEBSNitroVolumeLimit = 25
	// AzureVolumeLimitKey stores resource name that will store volume limits for Azure
	AzureVolumeLimitKey = "attachable-volumes-azure-disk"
	// GCEVolumeLimitKey stores resource name that will store volume limits for GCE node
	GCEVolumeLimitKey = "attachable-volumes-gce-pd"

	// CinderVolumeLimitKey contains Volume limit key for Cinder
	CinderVolumeLimitKey = "attachable-volumes-cinder"
	// DefaultMaxCinderVolumes defines the maximum number of PD Volumes for Cinder
	// For Openstack we are keeping this to a high enough value so as depending on backend
	// cluster admins can configure it.
	DefaultMaxCinderVolumes = 256

	// CSIAttachLimitPrefix defines prefix used for CSI volumes
	CSIAttachLimitPrefix = "attachable-volumes-csi-"

	// ResourceNameLengthLimit stores maximum allowed Length for a ResourceName
	ResourceNameLengthLimit = 63
)
View Source
const (
	// PVCProtectionFinalizer is the name of finalizer on PVCs that have a running pod.
	PVCProtectionFinalizer = "kubernetes.io/pvc-protection"

	// PVProtectionFinalizer is the name of finalizer on PVs that are bound by PVCs
	PVProtectionFinalizer = "kubernetes.io/pv-protection"
)
View Source
const (
	// isDefaultStorageClassAnnotation represents a StorageClass annotation that
	// marks a class as the default StorageClass
	IsDefaultStorageClassAnnotation = "storageclass.kubernetes.io/is-default-class"

	// betaIsDefaultStorageClassAnnotation is the beta version of IsDefaultStorageClassAnnotation.
	// TODO: remove Beta when no longer used
	BetaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class"
)
View Source
const (

	// ControllerManagedAttachAnnotation is the key of the annotation on Node
	// objects that indicates attach/detach operations for the node should be
	// managed by the attach/detach controller
	ControllerManagedAttachAnnotation string = "volumes.kubernetes.io/controller-managed-attach-detach"

	// KeepTerminatedPodVolumesAnnotation is the key of the annotation on Node
	// that decides if pod volumes are unmounted when pod is terminated
	KeepTerminatedPodVolumesAnnotation string = "volumes.kubernetes.io/keep-terminated-pod-volumes"

	// MountsInGlobalPDPath is name of the directory appended to a volume plugin
	// name to create the place for volume mounts in the global PD path.
	MountsInGlobalPDPath = "mounts"

	// VolumeGidAnnotationKey is the of the annotation on the PersistentVolume
	// object that specifies a supplemental GID.
	VolumeGidAnnotationKey = "pv.beta.kubernetes.io/gid"

	// VolumeDynamicallyCreatedByKey is the key of the annotation on PersistentVolume
	// object created dynamically
	VolumeDynamicallyCreatedByKey = "kubernetes.io/createdby"
)
View Source
const (
	// AlphaIsDefaultVolumeAttributesClassAnnotation is the alpha version of IsDefaultVolumeAttributesClassAnnotation.
	AlphaIsDefaultVolumeAttributesClassAnnotation = "volumeattributesclass.alpha.kubernetes.io/is-default-class"
)

Variables

View Source
var (

	// AnnPreResizeCapacity annotation is added to a PV when expanding volume.
	// Its value is status capacity of the PVC prior to the volume expansion
	// Its value will be set by the external-resizer when it deems that filesystem resize is required after resizing volume.
	// Its value will be used by pv_controller to determine pvc's status capacity when binding pvc and pv.
	AnnPreResizeCapacity = "volume.alpha.kubernetes.io/pre-resize-capacity"
)
View Source
var StorageOperationMetric = metrics.NewHistogramVec(
	&metrics.HistogramOpts{
		Name:           "storage_operation_duration_seconds",
		Help:           "Storage operation duration",
		Buckets:        []float64{.1, .25, .5, 1, 2.5, 5, 10, 15, 25, 50, 120, 300, 600},
		StabilityLevel: metrics.ALPHA,
	},
	[]string{"volume_plugin", "operation_name", "status", "migrated"},
)

Functions

func AddAnnPreResizeCapacity added in v1.21.0

func AddAnnPreResizeCapacity(
	pv *v1.PersistentVolume,
	oldCapacity resource.Quantity,
	kubeClient clientset.Interface) error

AddAnnPreResizeCapacity adds volume.alpha.kubernetes.io/pre-resize-capacity from the pv

func AddSELinuxMountOption added in v1.25.0

func AddSELinuxMountOption(options []string, seLinuxContext string) []string

AddSELinuxMountOption adds -o context="XYZ" mount option to a given list

func CalculateTimeoutForVolume added in v1.10.0

func CalculateTimeoutForVolume(minimumTimeout, timeoutIncrement int, pv *v1.PersistentVolume) int64

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 CheckPersistentVolumeClaimModeBlock added in v1.11.0

func CheckPersistentVolumeClaimModeBlock(pvc *v1.PersistentVolumeClaim) bool

CheckPersistentVolumeClaimModeBlock checks VolumeMode. If the mode is Block, return true otherwise return false.

func CheckVolumeModeFilesystem added in v1.10.0

func CheckVolumeModeFilesystem(volumeSpec *volume.Spec) (bool, error)

CheckVolumeModeFilesystem checks VolumeMode. If the mode is Filesystem, return true otherwise return false.

func ContainsAccessMode added in v1.22.0

func ContainsAccessMode(modes []v1.PersistentVolumeAccessMode, mode v1.PersistentVolumeAccessMode) bool

ContainsAccessMode returns whether the requested mode is contained by modes

func ContainsAllAccessModes added in v1.22.0

func ContainsAllAccessModes(indexedModes []v1.PersistentVolumeAccessMode, requestedModes []v1.PersistentVolumeAccessMode) bool

ContainsAllAccessModes returns whether all of the requested modes are contained by modes

func DeleteAnnPreResizeCapacity added in v1.21.0

func DeleteAnnPreResizeCapacity(
	pv *v1.PersistentVolume,
	kubeClient clientset.Interface) error

DeleteAnnPreResizeCapacity deletes volume.alpha.kubernetes.io/pre-resize-capacity from the pv

func FSGroupCompleteHook added in v1.20.0

func FSGroupCompleteHook(plugin volume.VolumePlugin, spec *volume.Spec) func(types.CompleteFuncParam)

FSGroupCompleteHook returns a hook to call when volume recursive permission is changed

func FsUserFrom added in v1.19.0

func FsUserFrom(pod *v1.Pod) *int64

FsUserFrom returns FsUser of pod, which is determined by the runAsUser attributes.

func GenerateVolumeName added in v1.10.0

func GenerateVolumeName(clusterName, pvName string, maxLength int) string

GenerateVolumeName returns a PV name with clusterName prefix. The function should be used to generate a name of GCE PD or Cinder volume. It basically adds "<clusterName>-dynamic-" before the PV name, making sure the resulting string fits given length and cuts "dynamic" if not.

func GenericResizeFS added in v1.13.0

func GenericResizeFS(host volume.VolumeHost, pluginName, devicePath, deviceMountPath string) (bool, error)

GenericResizeFS : call generic filesystem resizer for plugins that don't have any special filesystem resize requirements

func GetCSIAttachLimitKey added in v1.12.0

func GetCSIAttachLimitKey(driverName string) string

GetCSIAttachLimitKey returns limit key used for CSI volumes

func GetClassForVolume added in v1.5.0

func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error)

GetClassForVolume locates storage class by persistent volume

func GetDefaultClass added in v1.25.0

GetDefaultClass returns the default StorageClass from the store, or nil.

func GetDefaultVolumeAttributesClass added in v1.29.0

func GetDefaultVolumeAttributesClass(lister storagev1alpha1listers.VolumeAttributesClassLister, driverName string) (*storagev1alpha1.VolumeAttributesClass, error)

GetDefaultVolumeAttributesClass returns the default VolumeAttributesClass from the store, or nil.

func GetFullQualifiedPluginNameForVolume added in v1.13.0

func GetFullQualifiedPluginNameForVolume(pluginName string, spec *volume.Spec) string

GetFullQualifiedPluginNameForVolume returns full qualified plugin name for given volume. For CSI plugin, it appends plugin driver name at the end of plugin name, e.g. kubernetes.io/csi:csi-hostpath. It helps to distinguish between metrics emitted for CSI volumes which may be handled by different CSI plugin drivers.

func GetLocalPersistentVolumeNodeNames added in v1.27.0

func GetLocalPersistentVolumeNodeNames(pv *v1.PersistentVolume) []string

GetLocalPersistentVolumeNodeNames returns the node affinity node name(s) for local PersistentVolumes. nil is returned if the PV does not have any specific node affinity node selector terms and match expressions. PersistentVolume with node affinity has select and match expressions in the form of:

nodeAffinity:
  required:
    nodeSelectorTerms:
    - matchExpressions:
      - key: kubernetes.io/hostname
        operator: In
        values:
        - <node1>
        - <node2>

func GetPath added in v1.10.0

func GetPath(mounter volume.Mounter) (string, error)

GetPath checks if the path from the mounter is empty.

func GetPersistentVolumeClaimQualifiedName added in v1.12.0

func GetPersistentVolumeClaimQualifiedName(claim *v1.PersistentVolumeClaim) string

GetPersistentVolumeClaimQualifiedName returns a qualified name for pvc.

func GetPluginMountDir added in v1.15.0

func GetPluginMountDir(host volume.VolumeHost, name string) string

GetPluginMountDir returns the global mount directory name appended to the given plugin name's plugin directory

func GetPodVolumeNames added in v1.16.0

func GetPodVolumeNames(pod *v1.Pod) (mounts sets.String, devices sets.String, seLinuxContainerContexts map[string][]*v1.SELinuxOptions)

GetPodVolumeNames returns names of volumes that are used in a pod, either as filesystem mount or raw block device, together with list of all SELinux contexts of all containers that use the volumes.

func GetReliableMountRefs added in v1.21.7

func GetReliableMountRefs(mounter mount.Interface, mountPath string) ([]string, error)

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 GetSecretForPV added in v1.5.0

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 added in v1.5.0

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 GetUniquePodName added in v1.10.0

func GetUniquePodName(pod *v1.Pod) types.UniquePodName

GetUniquePodName returns a unique identifier to reference a pod by

func GetUniqueVolumeName added in v1.10.0

func GetUniqueVolumeName(pluginName, volumeName string) v1.UniqueVolumeName

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 GetUniqueVolumeNameFromSpec added in v1.10.0

func GetUniqueVolumeNameFromSpec(
	volumePlugin volume.VolumePlugin,
	volumeSpec *volume.Spec) (v1.UniqueVolumeName, error)

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 GetUniqueVolumeNameFromSpecWithPod added in v1.12.5

func GetUniqueVolumeNameFromSpecWithPod(
	podName types.UniquePodName, volumePlugin volume.VolumePlugin, volumeSpec *volume.Spec) 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 GetVolumeMode added in v1.10.0

func GetVolumeMode(volumeSpec *volume.Spec) (v1.PersistentVolumeMode, error)

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 GetWindowsPath added in v1.10.0

func GetWindowsPath(path string) string

GetWindowsPath get a windows path

func HasMountRefs added in v1.16.0

func HasMountRefs(mountPath string, mountRefs []string) bool

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 IsAttachableVolume added in v1.20.0

func IsAttachableVolume(volumeSpec *volume.Spec, volumePluginMgr *volume.VolumePluginMgr) bool

IsAttachableVolume checks if the given volumeSpec is an attachable volume or not

func IsDefaultAnnotation added in v1.25.0

func IsDefaultAnnotation(obj metav1.ObjectMeta) bool

IsDefaultAnnotation returns a boolean if the default storage class annotation is set TODO: remove Beta when no longer needed

func IsDefaultVolumeAttributesClassAnnotation added in v1.29.0

func IsDefaultVolumeAttributesClassAnnotation(obj metav1.ObjectMeta) bool

IsDefaultVolumeAttributesClassAnnotation returns a boolean if the default volume attributes class annotation is set

func IsDeviceMountableVolume added in v1.20.0

func IsDeviceMountableVolume(volumeSpec *volume.Spec, volumePluginMgr *volume.VolumePluginMgr) bool

IsDeviceMountableVolume checks if the given volumeSpec is an device mountable volume or not

func IsLocalEphemeralVolume added in v1.15.0

func IsLocalEphemeralVolume(volume v1.Volume) bool

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 IsMultiAttachAllowed added in v1.15.12

func IsMultiAttachAllowed(volumeSpec *volume.Spec) 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 IsPodTerminated added in v1.10.0

func IsPodTerminated(pod *v1.Pod, podStatus v1.PodStatus) bool

IsPodTerminated checks if pod is terminated

func IsReady

func IsReady(dir string) bool

IsReady checks for the existence of a regular file called 'ready' in the given directory and returns true if that file exists.

func IsWindowsLocalPath added in v1.13.0

func IsWindowsLocalPath(goos, path string) bool

IsWindowsLocalPath checks if path is a local path prefixed with "/" or "\" like "/foo/bar" or "\foo\bar"

func IsWindowsUNCPath added in v1.13.0

func IsWindowsUNCPath(goos, path string) 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 JoinMountOptions added in v1.10.0

func JoinMountOptions(userOptions []string, systemOptions []string) []string

JoinMountOptions joins mount options eliminating duplicates

func LoadPodFromFile added in v1.8.0

func LoadPodFromFile(filePath string) (*v1.Pod, error)

LoadPodFromFile will read, decode, and return a Pod from a file.

func MakeAbsolutePath added in v1.10.3

func MakeAbsolutePath(goos, path string) string

MakeAbsolutePath convert path to absolute path according to GOOS

func MakeNestedMountpoints added in v1.7.14

func MakeNestedMountpoints(name, baseDir string, pod v1.Pod) error

MakeNestedMountpoints creates mount points in baseDir for volumes mounted beneath name

func MapBlockVolume added in v1.11.0

func MapBlockVolume(
	blkUtil volumepathhandler.BlockVolumePathHandler,
	devicePath,
	globalMapPath,
	podVolumeMapPath,
	volumeMapName string,
	podUID utypes.UID,
) error

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 MarkControllerReisizeInProgress added in v1.23.0

func MarkControllerReisizeInProgress(pvc *v1.PersistentVolumeClaim, resizerName string, newSize resource.Quantity, kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

func MarkFSResizeFinished added in v1.10.0

func MarkFSResizeFinished(
	pvc *v1.PersistentVolumeClaim,
	newSize resource.Quantity,
	kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

MarkFSResizeFinished marks file system resizing as done

func MarkForFSResize added in v1.15.0

func MarkForFSResize(
	pvc *v1.PersistentVolumeClaim,
	kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

MarkForFSResize marks file system resizing as pending

func MarkNodeExpansionFailed added in v1.23.0

func MarkNodeExpansionFailed(pvc *v1.PersistentVolumeClaim, kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

MarkNodeExpansionFailed marks a PVC for node expansion as failed. Kubelet should not retry expansion of volumes which are in failed state.

func MarkNodeExpansionInProgress added in v1.23.0

func MarkNodeExpansionInProgress(pvc *v1.PersistentVolumeClaim, kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

MarkNodeExpansionInProgress marks pvc expansion in progress on node

func MarkResizeFinished added in v1.15.0

func MarkResizeFinished(
	pvc *v1.PersistentVolumeClaim,
	newSize resource.Quantity,
	kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

MarkResizeFinished marks all resizing as done

func MarkResizeInProgressWithResizer added in v1.15.0

func MarkResizeInProgressWithResizer(
	pvc *v1.PersistentVolumeClaim,
	resizerName string,
	kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

MarkResizeInProgressWithResizer marks cloudprovider resizing as in progress and also annotates the PVC with the name of the resizer.

func MergeResizeConditionOnPVC added in v1.10.0

func MergeResizeConditionOnPVC(
	pvc *v1.PersistentVolumeClaim,
	resizeConditions []v1.PersistentVolumeClaimCondition) *v1.PersistentVolumeClaim

MergeResizeConditionOnPVC updates pvc with requested resize conditions leaving other conditions untouched.

func MountOptionFromSpec added in v1.10.0

func MountOptionFromSpec(spec *volume.Spec, options ...string) []string

MountOptionFromSpec extracts and joins mount options from volume spec with supplied options

func NewSafeFormatAndMountFromHost added in v1.10.0

func NewSafeFormatAndMountFromHost(pluginName string, host volume.VolumeHost) *mount.SafeFormatAndMount

NewSafeFormatAndMountFromHost creates a new SafeFormatAndMount with Mounter and Exec taken from given VolumeHost.

func OperationCompleteHook added in v1.8.0

func OperationCompleteHook(plugin, operationName string) func(types.CompleteFuncParam)

OperationCompleteHook returns a hook to call when an operation is completed

func PatchPV added in v1.21.0

func PatchPV(
	oldPV *v1.PersistentVolume,
	newPV *v1.PersistentVolume,
	kubeClient clientset.Interface) (*v1.PersistentVolume, error)

PatchPV creates and executes a patch for pv

func PatchPVCStatus added in v1.10.0

func PatchPVCStatus(
	oldPVC *v1.PersistentVolumeClaim,
	newPVC *v1.PersistentVolumeClaim,
	kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

PatchPVCStatus updates PVC status using PATCH verb Don't use Update because this can be called from kubelet and if kubelet has an older client its Updates will overwrite new fields. And to avoid writing to a stale object, add ResourceVersion to the patch so that Patch will fail if the patch's RV != actual up-to-date RV like Update would

func RecordCSIOperationLatencyMetrics added in v1.21.0

func RecordCSIOperationLatencyMetrics(driverName string,
	operationName string,
	operationErr error,
	operationDuration time.Duration,
	migrated string)

RecordCSIOperationLatencyMetrics records the CSI operation latency and grpc status into metric csi_kubelet_operations_seconds

func RecordOperationLatencyMetric added in v1.15.0

func RecordOperationLatencyMetric(plugin, operationName string, secondsTaken float64)

RecordOperationLatencyMetric records the end to end latency for certain operation into metric volume_operation_total_seconds

func SetClaimResizer added in v1.15.0

func SetClaimResizer(
	pvc *v1.PersistentVolumeClaim,
	resizerName string,
	kubeClient clientset.Interface) (*v1.PersistentVolumeClaim, error)

SetClaimResizer sets resizer annotation on PVC

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 SplitUniqueName added in v1.10.0

func SplitUniqueName(uniqueName v1.UniqueVolumeName) (string, string, error)

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 SupportsSELinuxContextMount added in v1.25.0

func SupportsSELinuxContextMount(volumeSpec *volume.Spec, volumePluginMgr *volume.VolumePluginMgr) (bool, error)

SupportsSELinuxContextMount checks if the given volumeSpec supports with mount -o context

func UnmapBlockVolume added in v1.17.0

func UnmapBlockVolume(
	blkUtil volumepathhandler.BlockVolumePathHandler,
	globalUnmapPath,
	podDeviceUnmapPath,
	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 UnmountViaEmptyDir added in v1.10.0

func UnmountViaEmptyDir(dir string, host volume.VolumeHost, volName string, volSpec volume.Spec, podUID utypes.UID) error

UnmountViaEmptyDir delegates the tear down operation for secret, configmap, git_repo and downwardapi to empty_dir

func UpdatePVSize added in v1.15.0

func UpdatePVSize(
	pv *v1.PersistentVolume,
	newSize resource.Quantity,
	kubeClient clientset.Interface) (*v1.PersistentVolume, error)

UpdatePVSize updates just pv size after cloudprovider resizing is successful

func VolumeSupportsSELinuxMount added in v1.25.0

func VolumeSupportsSELinuxMount(volumeSpec *volume.Spec) bool

VolumeSupportsSELinuxMount returns true if given volume access mode can support mount with SELinux mount options.

func WriteVolumeCache added in v1.15.6

func WriteVolumeCache(deviceMountPath string, exec utilexec.Interface) error

WriteVolumeCache flush disk data given the specified mount path

Types

type AtomicWriter added in v1.2.0

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

AtomicWriter handles atomically projecting content for a set of files into a target directory.

Note:

  1. AtomicWriter reserves the set of pathnames starting with `..`.
  2. 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 added in v1.2.0

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 added in v1.2.0

func (w *AtomicWriter) Write(payload map[string]FileProjection, setPerms func(subPath string) error) error

Write does an atomic projection of the given payload into the writer's target directory. Input paths must not begin with '..'. setPerms is an optional pointer to a function that caller can provide to set the permissions of the newly created files before they are published. The function is passed subPath which is the name of the timestamped directory that was created under target directory.

The Write algorithm is:

  1. 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

  3. The old version of the volume is walked to determine whether any portion of the payload was deleted and is still present on disk.

  4. The data in the current timestamped directory is compared to the projected data to determine if an update to data directory is required.

  5. A new timestamped dir is created if an update is required.

  6. The payload is written to the new timestamped directory.

  7. Permissions are set (if setPerms is not nil) on the new timestamped directory and files.

  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. 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/ NOTE(claudiub): We need to create these symlinks AFTER we've finished creating and linking everything else. On Windows, if a target does not exist, the created symlink will not work properly if the target ends up being a directory.

  11. Old paths are removed from the user-visible portion of the target directory.

  12. The previous timestamped directory is removed, if it exists.

type DeviceUtil added in v1.3.0

type DeviceUtil interface {
	FindMultipathDeviceForDevice(disk string) string
	FindSlaveDevicesOnMultipath(disk string) []string
	GetISCSIPortalHostMapForTarget(targetIqn string) (map[string]int, error)
	FindDevicesForISCSILun(targetIqn string, lun int) ([]string, error)
}

DeviceUtil is a util for common device methods

func NewDeviceHandler added in v1.3.0

func NewDeviceHandler(io IoUtil) DeviceUtil

NewDeviceHandler Create a new IoHandler implementation

type FileProjection added in v1.4.0

type FileProjection struct {
	Data   []byte
	Mode   int32
	FsUser *int64
}

FileProjection contains file Data and access Mode

type IoUtil added in v1.3.0

type IoUtil interface {
	ReadFile(filename string) ([]byte, error)
	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

func NewIOHandler added in v1.3.0

func NewIOHandler() IoUtil

NewIOHandler Create a new IoHandler implementation

type SELinuxLabelTranslator added in v1.25.0

type SELinuxLabelTranslator interface {
	// SELinuxOptionsToFileLabel returns SELinux file label for given SELinuxOptions
	// of a container process.
	// When Role, User or Type are empty, they're read from the system defaults.
	// It returns "" and no error on platforms that do not have SELinux enabled
	// or don't support SELinux at all.
	SELinuxOptionsToFileLabel(opts *v1.SELinuxOptions) (string, error)

	// SELinuxEnabled returns true when the OS has enabled SELinux support.
	SELinuxEnabled() bool
}

SELinuxLabelTranslator translates v1.SELinuxOptions of a process to SELinux file label.

func NewFakeSELinuxLabelTranslator added in v1.25.0

func NewFakeSELinuxLabelTranslator() SELinuxLabelTranslator

NewFakeSELinuxLabelTranslator returns a fake translator for unit tests. It imitates a real translator on platforms that do not have SELinux enabled or don't support SELinux at all.

func NewSELinuxLabelTranslator added in v1.25.0

func NewSELinuxLabelTranslator() SELinuxLabelTranslator

NewSELinuxLabelTranslator returns new SELinuxLabelTranslator for the platform.

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

Jump to

Keyboard shortcuts

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