common

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Kib int64 = 1024
	Mib int64 = Kib * 1024
	Gib int64 = Mib * 1024
	Tib int64 = Gib * 1024
)
View Source
const (
	Version              string = "v1.2.0"
	DefaultProvisionName string = "disk.csi.zenlayer.com"
	NodeDriverType       string = "node"
	ControllerDriverType string = "controller"
)
View Source
const (
	FileSystemExt3    string = "ext3"
	FileSystemExt4    string = "ext4"
	FileSystemXfs     string = "xfs"
	DefaultFileSystem string = FileSystemExt4
)
View Source
const (
	ZEC_PLATFORM            string = "Zenlayer Elastic Compute"
	ZEC_SYS_VENDOR_PATH     string = "/sys/class/dmi/id/sys_vendor"     //Vm platform
	ZEC_PRODUCT_FAMILY_PATH string = "/sys/class/dmi/id/product_family" //Vm zone
	ZEC_PRODUCT_SERIAL_PATH string = "/sys/class/dmi/id/product_serial" //Vm console ID
)
View Source
const DefaultTimeFormat = "2006-01-02 15:04:05"
View Source
const FEAT_MOUNTOPT_ENABLE = "enable_mount_opt"
View Source
const Int64Max = int64(^uint64(0) >> 1)
View Source
const KubeletRootDir = "/var/lib/kubelet"
View Source
const KubernetesPluginPathPrefix = "/plugins/kubernetes.io/"
View Source
const (
	OperationPendingFmt = "already an operation for the specified resource %s"
)
View Source
const ZECVMID_LEN = 19 //zec VmID len			example:1455441132925494374
View Source
const ZECVOLID_LEN = 19 //zec DiskId len 		example:1440908808376556310
View Source
const ZECVOLSERIAL_LEN = 20 //zec Disk Serial len 	example:d100om84ggf2oqdh05eg

Variables

View Source
var DefaultResourceGroup string
View Source
var DefaultZone string
View Source
var FeatureGates []string
View Source
var MixDriver bool

Functions

func ByteCeilToGib

func ByteCeilToGib(nByte int64) int

ByteCeilToGib Convert Byte to Gib

func EntryFunction

func EntryFunction(functionName string) (info string, hash string)

func ExitFunction

func ExitFunction(functionName, hash string) (info string)

func FormatAndMount

func FormatAndMount(diskMounter *k8smount.SafeFormatAndMount, source string, target string, fstype string, mkfsOptions []string, mountOptions []string, omitFsCheck bool) error

func FormatNewDisk

func FormatNewDisk(readOnly bool, source, fstype, target string, mkfsOptions, mountOptions []string, diskMounter *k8smount.SafeFormatAndMount) error

func GenCsiVolId

func GenCsiVolId(volid, serial string) (csivolId string)

func GenerateHashInEightBytes

func GenerateHashInEightBytes(input string) string

func GetDiskFStypePTtype

func GetDiskFStypePTtype(disk string) (fstype string, pttype string, err error)

GetDiskFStypePTtype uses 'blkid' to see if the given disk is unformatted

func GetRequestSizeBytes

func GetRequestSizeBytes(capRange *csi.CapacityRange) (int64, error)

GetRequestSizeBytes get minimal required bytes and not exceed limit bytes.

func GetZecEnv

func GetZecEnv() (vmid string, vm_zone string, err error)

func GetZecSecret

func GetZecSecret(akpath string, skpath string) (ak string, pw string, err error)

func GibToByte

func GibToByte(nGib int) int64

GibToByte Convert GiB to Byte

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

IsDirEmpty check whether the given directory is empty

func IsFileExisting

func IsFileExisting(filename string) bool

IsFileExisting check file exist in volume driver

func IsValidCapacityBytes

func IsValidCapacityBytes(cur int64, capRange *csi.CapacityRange) bool

Valid capacity bytes in capacity range

func NewSafeMounter

func NewSafeMounter() *k8smount.SafeFormatAndMount

func ParseCsiVolId

func ParseCsiVolId(csivolId string) (volid string, serial string, err error)

ParseCsiVolId 把 GenCsiVolId 生成的 csi volume id 还原成云盘 id 和 serial。

id 只会以 "<diskId>-<serial>" 的形式生成, 且 diskId 是纯数字不含 "-", 所以在第一个 "-" 处切分总能正确还原两段(用 strings.Cut 而不是 Split 取首尾, 后者在 serial 含 "-" 时会错位)。

形状不符的 id 不可能对应任何 ZEC 云盘, 因此这里返回错误, 而不是像之前那样只打一条 日志、把截断出来的垃圾 volid 继续发给云 API(那样云端只会回一个语义无关的错误)。 调用方必须按各自 RPC 的规范要求映射这个错误:

  • 卸载/删除类 RPC 要求幂等, 应视作"目标已不存在"直接返回成功;
  • 其余 RPC 应返回 NotFound —— 这个 id 对 CO 而言格式合法, 只是不由本驱动发出, 即该卷在本驱动这里不存在。

func RetryOnError

func RetryOnError(backoff wait.Backoff, fn func() error) error

func VerifyEnv

func VerifyEnv() (platform string, err error)

Types

type ResourceLocks

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

func NewResourceLocks

func NewResourceLocks() *ResourceLocks

func (*ResourceLocks) Release

func (lock *ResourceLocks) Release(resourceID string)

func (*ResourceLocks) TryAcquire

func (lock *ResourceLocks) TryAcquire(resourceID string) bool

Jump to

Keyboard shortcuts

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