util

package
v0.0.0-...-cdf4e82 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GB - GigaByte size
	GB = 1000 * 1000 * 1000
	// GIB - GibiByte size
	GIB = 1024 * 1024 * 1024

	// 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"

	// 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"
)

Variables

This section is empty.

Functions

func AccessModesContainedInAll

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

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

func AccessModesContains

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

AccessModesContains returns whether the requested mode is contained by modes

func CalculateTimeoutForVolume

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 CheckVolumeModeFilesystem

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

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

func ChooseZoneForVolume

func ChooseZoneForVolume(zones sets.String, pvcName string) string

ChooseZoneForVolume implements our heuristics for choosing a zone for volume creation based on the volume name Volumes are generally round-robin-ed across all active zones, using the hash of the PVC Name. However, if the PVCName ends with `-<integer>`, we will hash the prefix, and then add the integer to the hash. This means that a StatefulSet's volumes (`claimname-statefulsetname-id`) will spread across available zones, assuming the id values are consecutive.

func ChooseZonesForVolume

func ChooseZonesForVolume(zones sets.String, pvcName string, numZones uint32) sets.String

ChooseZonesForVolume is identical to ChooseZoneForVolume, but selects a multiple zones, for multi-zone disks.

func GenerateVolumeName

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 GetClassForVolume

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

func GetPath

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

GetPath checks if the path from the mounter is empty.

func GetPersistentVolumeClaimVolumeMode

func GetPersistentVolumeClaimVolumeMode(claim *v1.PersistentVolumeClaim) (v1.PersistentVolumeMode, error)

GetPersistentVolumeClaimVolumeMode retrieves VolumeMode from pvc.

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 GetUniquePodName

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

GetUniquePodName returns a unique identifier to reference a pod by

func GetUniqueVolumeName

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 GetUniqueVolumeNameForNonAttachableVolume

func GetUniqueVolumeNameForNonAttachableVolume(
	podName types.UniquePodName, volumePlugin volume.VolumePlugin, volumeSpec *volume.Spec) v1.UniqueVolumeName

GetUniqueVolumeNameForNonAttachableVolume returns the unique volume name for a non-attachable volume.

func GetUniqueVolumeNameFromSpec

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 GetVolumeMode

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

func GetWindowsPath(path string) string

GetWindowsPath get a windows path

func IsPodTerminated

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 JoinMountOptions

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

JoinMountOptions joins mount options eliminating duplicates

func LabelZonesToSet

func LabelZonesToSet(labelZonesValue string) (sets.String, error)

LabelZonesToSet converts a PV label value from string containing a delimited list of zones to set

func LoadPodFromFile

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

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

func MountOptionFromSpec

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

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

func NewDanglingError

func NewDanglingError(msg string, node k8stypes.NodeName, devicePath string) error

func NewSafeFormatAndMountFromHost

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

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

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if the specified path exists.

func RoundUpSize

func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64

RoundUpSize calculates how many allocation units are needed to accommodate a volume of given size. E.g. when user wants 1500MiB volume, while AWS EBS allocates volumes in gibibyte-sized chunks, RoundUpSize(1500 * 1024*1024, 1024*1024*1024) returns '2' (2 GiB is the smallest allocatable volume that can hold 1500MiB)

func RoundUpToGB

func RoundUpToGB(size resource.Quantity) int64

RoundUpToGB rounds up given quantity to chunks of GB

func RoundUpToGiB

func RoundUpToGiB(size resource.Quantity) int64

RoundUpToGiB rounds up given quantity upto chunks of GiB

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

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 fromat 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 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

func UnmountPath(mountPath string, mounter mount.Interface) error

UnmountPath is a common unmount routine that unmounts the given path and deletes the remaining directory if successful.

func UnmountViaEmptyDir

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 ValidateZone

func ValidateZone(zone string) error

ValidateZone returns: - an error in case zone is an empty string or contains only any combination of spaces and tab characters - nil otherwise

func ZonesSetToLabelValue

func ZonesSetToLabelValue(strSet sets.String) string

func ZonesToSet

func ZonesToSet(zonesString string) (sets.String, error)

ZonesToSet converts a string containing a comma separated list of zones to set

Types

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

Jump to

Keyboard shortcuts

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