utils

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MountCmdName                        = "mount"
	UMountCmdName                       = "umount"
	MountPointCmdName                   = "mountpoint"
	IsNotMountPoint                     = "is not a mountpoint"
	IsNotMountPointZhCN                 = "不是一个挂载点"
	ErrEndpointNotConnected             = "transport endpoint is not connected"
	TransportEndpointIsNotConnected     = "Transport endpoint is not connected"
	SocketNotConnected                  = "Socket not connected"
	TransportEndpointIsNotConnectedZhCN = "传输端点尚未连接"
	DirectoryNotEmpty                   = "directory not empty"
	DirectoryNotEmptyZhCN               = "目录非空"
	NotMounted                          = "not mounted"

	CmdTimeoutEnv            = "CMD_TIMEOUT_IN_SECOND"
	DefaultCmdTimoutInSecond = 60
	KillPGroupCmd            = "kill -9 -%d"
)
View Source
const (
	VolumePluginName = "kubernetes.io~csi"

	KubeletDataPathEnv        = "KUBELET_DATA_PATH"
	NotRootUserEnableEnv      = "NOT_ROOT_USER_ENABLE"
	MountPointIntervalTimeEnv = "MOUNT_POINT_INTERVAL_TIME"
	PodsHandleConcurrencyEnv  = "PODS_HANDLE_CONCURRENCY"
	PodUpdateIntervalTimeEnv  = "POD_UPDATE_INTERVAL_TIME"
	DefaultUIDEnv             = "DEFAULT_UID_ENV"
	DefaultGIDEnv             = "DEFAULT_GID_ENV"
	K8SConfigPathEnv          = "K8S_CONFIG_PATH"
	K8SClientTimeoutEnv       = "K8S_CLIENT_TIMEOUT"

	DefaultKubeletDataPath       = "/var/lib/kubelet"
	DefaultCheckIntervalTime     = 15
	DefaultK8SClientTimeout      = 0
	DefaultPodsHandleConcurrency = 10
	DefaultUpdateIntervalTime    = 15
	DefaultUID                   = 601
	DefaultGID                   = 601
)

Variables

This section is empty.

Functions

func CleanUpMountPoint

func CleanUpMountPoint(path string) error

func CleanUpMountPoints

func CleanUpMountPoints(paths []string) error

func ExecCmdWithTimeout

func ExecCmdWithTimeout(name string, args []string) ([]byte, error)

func ExecMount

func ExecMount(sourcePath, targetPath string, args []string) ([]byte, error)

func ExecMountBind

func ExecMountBind(sourcePath, targetPath string, ReadOnly bool) ([]byte, error)

func Exist

func Exist(path string) (bool, error)

func ForceUnmount

func ForceUnmount(path string) error

func ForceUnmountAndRemove

func ForceUnmountAndRemove(path string) error

func FsIDToFsNameUsername

func FsIDToFsNameUsername(fsID string) (fsName, username string)

func GetCmdTimeout

func GetCmdTimeout() time.Duration

func GetDefaultGID

func GetDefaultGID() int

func GetDefaultUID

func GetDefaultUID() int

func GetDiskPercent added in v0.14.6

func GetDiskPercent() float64

func GetFileInode

func GetFileInode(path string) (uint64, error)

func GetFsNameAndUserNameByFsID

func GetFsNameAndUserNameByFsID(fsID string) (fsName, username string, err error)

func GetK8SConfigPathEnv

func GetK8SConfigPathEnv() string

func GetK8STimeoutEnv

func GetK8STimeoutEnv() int

func GetKubeletDataPath

func GetKubeletDataPath() string

func GetMountPointCheckIntervalTime

func GetMountPointCheckIntervalTime() int

func GetPodUIDFromTargetPath

func GetPodUIDFromTargetPath(targetPath string) string

func GetPodsHandleConcurrency

func GetPodsHandleConcurrency() int

func GetPodsUpdateIntervalTime

func GetPodsUpdateIntervalTime() int

func GetProcessCPUPercent added in v0.14.6

func GetProcessCPUPercent() float64

func GetProcessMemPercent added in v0.14.6

func GetProcessMemPercent() float32

func GetRandID

func GetRandID(randNum int) string

func GetRootToken

func GetRootToken(ctx *logger.RequestContext) (string, error)

func GetSourceMountPath added in v0.14.4

func GetSourceMountPath(pathPrefix string) string

default value: /var/lib/kubelet/pods/{podUID}/volumes/{volumePluginName}/{volumeName}/source

func GetSourceMountPathByPod

func GetSourceMountPathByPod(podUID, volumeName string) string

GetSourceMountPathByPod default value: /var/lib/kubelet/pods/{podUID}/volumes/{volumePluginName}/{volumeName}/source

func GetSubPathSourcePath added in v0.14.4

func GetSubPathSourcePath(volumePath, subpath string) string

func GetSubPathTargetPath added in v0.14.4

func GetSubPathTargetPath(podUID string, volumeName string, containerName string, volumeMountIndex int) string

default value: /var/lib/kubelet/pods/{podUID}/volumes-subpaths/{volumeName}/{containerName}/{volumeMountIndex}

func GetSysCpuPercent added in v0.14.6

func GetSysCpuPercent() float64

func GetSysMemPercent added in v0.14.6

func GetSysMemPercent() (uint64, float64)

func GetVolumeBindMountPathByPod

func GetVolumeBindMountPathByPod(podUID, volumeName string) string

GetVolumeBindMountPathByPod default value: /var/lib/kubelet/pods/{podUID}/volumes/{volumePluginName}/{volumeName}/mount

func GetVolumeMountPath

func GetVolumeMountPath(pathPrefix string) string

GetVolumeMountPath default value: /var/lib/kubelet/pods/{podUID}/volumes/{volumePluginName}/{volumeName}/mount

func GetVolumeSourceMountPath

func GetVolumeSourceMountPath(pathPrefix string) string

GetVolumeSourceMountPath default value: /var/lib/kubelet/pods/{podUID}/volumes/{volumePluginName}/{volumeName}/source

func IsEmptyDir

func IsEmptyDir(path string) (bool, error)

func IsLikelyMountPoint

func IsLikelyMountPoint(path string) (bool, error)

func IsMountPoint

func IsMountPoint(path string) (bool, error)

func ManualUnmount

func ManualUnmount(path string) error

func New

func New(k8sConfigPath string, k8sClientTimeout int) (*k8sClient, error)

func Open

func Open(path string) (io.ReadCloser, error)

func ProcessCacheConfig

func ProcessCacheConfig(fsCacheBase64 string) (model.FSCacheConfig, error)

func ProcessFSInfo

func ProcessFSInfo(fsInfoBase64 string) (model.FileSystem, error)

func Readdirnames

func Readdirnames(path string) ([]string, error)

Readdirnames reads the contents of the directory associated with file and returns a slice of up to n names of files in the directory.

The ioutil.ReadDir function will get the directory name and call lstat to get the directory FileInfo. but when mount point is not connected, lstat function will return error

Types

type Client

type Client interface {
	// pod
	ProxyGetPods(nodeID string) (result *corev1.PodList, err error)
	CreatePod(pod *corev1.Pod) (*corev1.Pod, error)
	GetPod(namespace, name string) (*corev1.Pod, error)
	PatchPod(namespace, name string, data []byte) error
	UpdatePod(namespace string, pod *corev1.Pod) (*corev1.Pod, error)
	DeletePod(pod *corev1.Pod) error
	GetPodLog(namespace, podName, containerName string) (string, error)
	PatchPodAnnotation(pod *corev1.Pod) error
	PatchPodLabel(pod *corev1.Pod) error
	// pv
	CreatePersistentVolume(pv *corev1.PersistentVolume) (*corev1.PersistentVolume, error)
	DeletePersistentVolume(name string, deleteOptions metav1.DeleteOptions) error
	GetPersistentVolume(name string, getOptions metav1.GetOptions) (*corev1.PersistentVolume, error)
	ListPersistentVolume(listOptions metav1.ListOptions) (*corev1.PersistentVolumeList, error)
	// pvc
	CreatePersistentVolumeClaim(namespace string, pvc *corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaim, error)
	DeletePersistentVolumeClaim(namespace, name string, deleteOptions metav1.DeleteOptions) error
	GetPersistentVolumeClaim(namespace, name string, getOptions metav1.GetOptions) (*corev1.PersistentVolumeClaim, error)
	// ns
	GetNamespace(namespace string, getOptions metav1.GetOptions) (*corev1.Namespace, error)
	ListNamespaces(listOptions metav1.ListOptions) (*corev1.NamespaceList, error)
}

func GetFakeK8sClient

func GetFakeK8sClient() Client

func GetK8sClient

func GetK8sClient() (Client, error)

type PatchMapValue

type PatchMapValue struct {
	Op    string            `json:"op"`
	Path  string            `json:"path"`
	Value map[string]string `json:"value"`
}

Jump to

Keyboard shortcuts

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