osutils

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package osutils provides methods to perform os specific operations

Index

Constants

View Source
const (
	UUIDPrefix = "VMware-"
)

Variables

This section is empty.

Functions

func GetMounter

func GetMounter(ctx context.Context, osUtils *OsUtils) (mounter.CSIProxyMounter, error)

Types

type Device

type Device struct {
	FullPath string // full path where device is mounted
	Name     string // name of device
	RealDev  string // in windows it represents volumeID and in linux it represents device path
}

Device is a struct for holding details about a block device.

type NodePublishParams

type NodePublishParams struct {
	// volID is the identifier for the underlying volume.
	VolID string
	// Target path is used to bind-mount a staged volume to the pod.
	Target string
	// Staging Target path is used to mount the volume to the node.
	StagingTarget string
	// diskID is the identifier for the disk.
	DiskID string
	// volumePath represents the sym-linked block volume full path.
	VolumePath string
	// device represents the actual path of the block volume.
	Device string
	// Read-only flag.
	Ro bool
}

struct to hold params required for NodePublish operation

type NodeStageParams

type NodeStageParams struct {
	// volID is the identifier for the underlying volume.
	VolID string
	// fsType is the file system type - ext3, ext4, nfs, nfs4.
	FsType string
	// Staging Target path is used to mount the volume to the node.
	StagingTarget string
	// Mount flags/options intended to be used while running the mount command.
	MntFlags []string
	// Read-only flag.
	Ro bool
}

struct to hold params required for NodeStage operation

type OsUtils

type OsUtils struct {
	Mounter *mount.SafeFormatAndMount
}

func NewOsUtils

func NewOsUtils(ctx context.Context) (*OsUtils, error)

NewOsUtils creates OsUtils with a linux specific mounter

func (*OsUtils) CleanupPublishPath

func (osUtils *OsUtils) CleanupPublishPath(ctx context.Context, target string, volID string) error

CleanupPublishPath will unmount and remove publish path

func (*OsUtils) CleanupStagePath

func (osUtils *OsUtils) CleanupStagePath(ctx context.Context, stagingTarget string, volID string) error

CleanupStagePath will unmount the volume from node and remove the stage directory

func (*OsUtils) ConvertUUID

func (osUtils *OsUtils) ConvertUUID(uuid string) (string, error)

convertUUID helps convert UUID to vSphere format, for example, Input uuid: VMware-42 02 e9 7e 3d ad 2a 49-22 86 7f f9 89 c6 64 ef Returned uuid: 4202e97e-3dad-2a49-2286-7ff989c664ef

func (*OsUtils) EnsureMountVol

func (osUtils *OsUtils) EnsureMountVol(ctx context.Context, log *zap.SugaredLogger,
	volCap *csi.VolumeCapability) (string, []string, error)

EnsureMountVol ensures that VolumeCapability has mount option and returns fstype, mount flags

func (*OsUtils) GetBlockSizeBytes

func (osUtils *OsUtils) GetBlockSizeBytes(ctx context.Context, devicePath string) (int64, error)

GetBlockSizeBytes returns the Block size in bytes

func (*OsUtils) GetDevFromMount

func (osUtils *OsUtils) GetDevFromMount(ctx context.Context, target string) (*Device, error)

GetDevFromMount returns device info mounted on the target dir

func (*OsUtils) GetDevice

func (osUtils *OsUtils) GetDevice(ctx context.Context, path string) (*Device, error)

GetDevice returns a Device struct with info about the given device, or an error if it doesn't exist or is not a block device.

func (*OsUtils) GetDiskID

func (osUtils *OsUtils) GetDiskID(pubCtx map[string]string, log *zap.SugaredLogger) (string, error)

GetDiskID returns the diskID of the disk attached

func (*OsUtils) GetMetrics

func (osUtils *OsUtils) GetMetrics(ctx context.Context, path string) (*k8svol.Metrics, error)

GetMetrics helps get volume metrics using k8s fsInfo strategy.

func (*OsUtils) GetSystemUUID

func (osUtils *OsUtils) GetSystemUUID(ctx context.Context) (string, error)

GetSystemUUID returns the UUID used to identify node vm

func (*OsUtils) GetVolumeCapabilityFsType

func (osUtils *OsUtils) GetVolumeCapabilityFsType(ctx context.Context, capability *csi.VolumeCapability) string

GetVolumeCapabilityFsType retrieves fstype from VolumeCapability. Defaults to nfs4 for file volume and ntfs for block volume when empty string is observed. This function also ignores default ext4 fstype supplied by external-provisioner when none is specified in the StorageClass

func (*OsUtils) IsTargetInMounts

func (osUtils *OsUtils) IsTargetInMounts(ctx context.Context, path string) (bool, error)

IsTargetInMounts checks if a path exists in the mounts this check is no op for windows

func (*OsUtils) NodeStageBlockVolume

func (osUtils *OsUtils) NodeStageBlockVolume(
	ctx context.Context,
	req *csi.NodeStageVolumeRequest,
	params NodeStageParams) (
	*csi.NodeStageVolumeResponse, error)

NodeStageBlockVolume mounts mount volume or file volume to staging target

func (*OsUtils) PreparePublishPath

func (osUtils *OsUtils) PreparePublishPath(ctx context.Context, path string) error

preparePublishPath - In case of windows, the publish code path creates a soft link from global stage path to the publish path. But kubelet creates the directory in advance. We work around this issue by deleting the publish path then recreating the link.

func (*OsUtils) PublishBlockVol

func (osUtils *OsUtils) PublishBlockVol(
	ctx context.Context,
	req *csi.NodePublishVolumeRequest,
	dev *Device,
	params NodePublishParams) (
	*csi.NodePublishVolumeResponse, error)

PublishBlockVol mounts raw block device to publish target

func (*OsUtils) PublishFileVol

func (osUtils *OsUtils) PublishFileVol(
	ctx context.Context,
	req *csi.NodePublishVolumeRequest,
	params NodePublishParams) (
	*csi.NodePublishVolumeResponse, error)

PublishBlockVol mounts file volume to publish target

func (*OsUtils) PublishMountVol

func (osUtils *OsUtils) PublishMountVol(
	ctx context.Context,
	req *csi.NodePublishVolumeRequest,
	dev *Device,
	params NodePublishParams) (
	*csi.NodePublishVolumeResponse, error)

PublishBlockVol mounts block volume to publish target

func (*OsUtils) RescanDevice

func (osUtils *OsUtils) RescanDevice(ctx context.Context, dev *Device) error

RescanDevice rescans the device

func (*OsUtils) ResizeVolume

func (osUtils *OsUtils) ResizeVolume(ctx context.Context, devicePath, volumePath string, reqVolSizeBytes int64) error

ResizeVolume resizes the volume

func (*OsUtils) ShouldContinue

func (osUtils *OsUtils) ShouldContinue(ctx context.Context)

decides if node should continue

func (*OsUtils) VerifyTargetDir

func (osUtils *OsUtils) VerifyTargetDir(ctx context.Context, target string, targetShouldExist bool) (bool, error)

VerifyTargetDir checks if the target path is not empty, exists and is a directory. If targetShouldExist is set to false, then verifyTargetDir returns (false, nil) if the path does not exist. If targetShouldExist is set to true, then verifyTargetDir returns (false, err) if the path does not exist.

func (*OsUtils) VerifyVolumeAttachedAndFillParams

func (osUtils *OsUtils) VerifyVolumeAttachedAndFillParams(ctx context.Context,
	pubCtx map[string]string, params *NodePublishParams, dev **Device) error

VerifyVolumeAttachedFillParams is a noop for windows

Jump to

Keyboard shortcuts

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