utils

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DiskAttachDetach ...
	DiskAttachDetach = "diskAttachDetach"
	// DiskProvision ...
	DiskProvision = "diskProvision"
	// DiskMount ...
	DiskMount = "diskMount"
	// DiskDelete ...
	DiskDelete = "diskDelete"
	// NasFilesystemCreate ...
	NasFilesystemCreate = "nasFilesystemCreate"
	// NasFilesystemDelete ...
	NasFilesystemDelete = "nasFilesystemDelete"
	// NasMountTargetCreate ...
	NasMountTargetCreate = "nasMountTargetCreate"
	// NasMountTargetDelete ...
	NasMountTargetDelete = "nasMountTargetDelete"
)
View Source
const (
	// MetadataURL is metadata url
	MetadataURL = "http://100.100.100.200/latest/meta-data/"
	// ECS worker role resource url in metadata server
	WorkerRoleResource = "ram/security-credentials/"
	// RegionIDTag is region id
	RegionIDTag = "region-id"
	// InstanceIDTag is instance id
	InstanceIDTag = "instance-id"
	// DefaultRegion is default region
	DefaultRegion = "cn-hangzhou"
	// CsiPluginRunTimeFlagFile tag
	CsiPluginRunTimeFlagFile = "../alibabacloudcsiplugin.json"
	// RuncRunTimeTag tag
	RuncRunTimeTag = "runc"
	// RunvRunTimeTag tag
	RunvRunTimeTag = "runv"
	// RunvRunTimeTag tag
	RundRunTimeTag = "rund"
	// ServiceType tag
	ServiceTypeEnv = "SERVICE_TYPE"
	// PluginService represents the csi-plugin type.
	PluginService = "plugin"
	// ProvisionerService represents the csi-provisioner type.
	ProvisionerService = "provisioner"
	// MetadataMaxRetryCount ...
	MetadataMaxRetryCount = 4
	// VolDataFileName file
	VolDataFileName = "vol_data.json"

	// GiB ...
	GiB = 1024 * 1024 * 1024

	PodNameKey      = "csi.storage.k8s.io/pod.name"
	PodNamespaceKey = "csi.storage.k8s.io/pod.namespace"
)
View Source
const CGROUPFS_MOUNT_PATH = "/host/sys/fs/cgroup"

CGROUPFS_MOUNT_PATH is the path to the host cgroupfs mounted in the container

View Source
const (
	// ConfigPath the secret mount file
	ConfigPath = "/var/addon/token-config"
)

Variables

View Source
var DiskAttachDetachErrors = map[string]*errorInfo{
	"had volume node affinity conflict": {
		// contains filtered or unexported fields
	},
	"can't find disk:": {
		// contains filtered or unexported fields
	},
	"instance does not support this disk category.": {
		// contains filtered or unexported fields
	},
	"The specified disk is not a portable disk.": {
		// contains filtered or unexported fields
	},
}

DiskAttachDetachErrors are errors throwed by disk attach

View Source
var DiskDeleteErrors = map[string]*errorInfo{}

DiskDeleteErrors are errors throwed by disk delete

View Source
var DiskMountErrors = map[string]*errorInfo{}

DiskMountErrors are errors throwed by disk mount

View Source
var DiskProvisionErrors = map[string]*errorInfo{
	"disk size is not supported.": {
		// contains filtered or unexported fields
	},
	"The specified AZone inventory is insufficient": {
		// contains filtered or unexported fields
	},
}

DiskProvisionErrors are errors throwed by ecs create disk api

View Source
var KubeletRootDir = "/var/lib/kubelet"

KubeletRootDir kubelet root dir;

View Source
var MountPathWithTLS = "/tls"

MountPathWithTLS tls mount path;

View Source
var NasFilesystemCreateErrors = map[string]*errorInfo{}

NasFilesystemCreateErrors are errors throwed by nas create

View Source
var NasFilesystemDeleteErrors = map[string]*errorInfo{}

NasFilesystemDeleteErrors are errors throwed by nas filesystem delete

View Source
var NasMountTargetCreateErrors = map[string]*errorInfo{}

NasMountTargetCreateErrors are errors throwed by nas mount target create

View Source
var NasMountTargetDeleteErrors = map[string]*errorInfo{}

NasMountTargetDeleteErrors are errors throwed by nas mount target delete

View Source
var NsenterArgs = []string{"--target=1", "--mount", "--ipc", "--net", "--uts", "--"}

Functions

func AppendJSONData added in v1.1.7

func AppendJSONData(dataFilePath string, appData map[string]string) error

AppendJSONData append map data to json file.

func Bytes2GiB added in v1.2.1

func Bytes2GiB(volumeSizeBytes int64) int64

BytesToGiB converts Bytes to GiB

func CommandOnNode added in v1.2.1

func CommandOnNode(args ...string) *exec.Cmd

func ConnectorRun added in v1.1.7

func ConnectorRun(cmd ...string) (string, error)

ConnectorRun Run shell command with host connector host connector is daemon running in host.

func CreateDest

func CreateDest(dest string) error

CreateDest create de destination dir

func CreateEvent added in v1.1.1

func CreateEvent(recorder record.EventRecorder, objectRef *v1.ObjectReference, eventType string, reason string, err string)

CreateEvent is create events

func FindSuggestionByErrorMessage added in v1.1.0

func FindSuggestionByErrorMessage(errMsg, errorType string) string

FindSuggestionByErrorMessage get new error message by error type & error message

func FormatAndMount added in v1.1.7

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

formatAndMount uses unix utils to format and mount the given disk

func FormatNewDisk added in v1.2.0

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

func Fsync added in v1.1.5

func Fsync(f *os.File) error

Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform.

func GetAccessModes added in v1.2.1

func GetAccessModes(caps []*csi.VolumeCapability) *[]string

GetAccessModes returns a slice containing all of the access modes defined in the passed in VolumeCapabilities.

func GetCredentialV2 added in v1.4.0

func GetCredentialV2() (crev2.Credential, error)

func GetDiskFStypePTtype added in v1.6.0

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

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

func GetFileContent added in v1.0.4

func GetFileContent(fileName string) string

GetFileContent get file content

func GetMetaData

func GetMetaData(resource string) (string, error)

GetMetaData get metadata from ecs meta-server

func GetMetrics added in v1.0.3

func GetMetrics(path string) (*csi.NodeGetVolumeStatsResponse, error)

GetMetrics get path metric

func GetNvmeDeviceByVolumeID added in v1.3.0

func GetNvmeDeviceByVolumeID(volumeID string) (device string, err error)

Get NVME device name by diskID; /dev/nvme0n1 0: means device index, 1: means namespace for nvme device; udevadm info --query=all --name=/dev/nvme0n1 | grep ID_SERIAL_SHORT | awk -F= '{print $2}' bp1bcfmvsobfauvxb3ow

func GetPodFromContextOrK8s added in v1.6.0

func GetPodFromContextOrK8s(ctx context.Context, client kubernetes.Interface, req *csi.NodePublishVolumeRequest) (*v1.Pod, error)

func GetPodRunTime added in v1.0.4

func GetPodRunTime(ctx context.Context, req *csi.NodePublishVolumeRequest, clientSet kubernetes.Interface) string

GetPodRunTime Get Pod runtimeclass config Default as runc.

func GetPvNameFormPodMnt added in v1.1.5

func GetPvNameFormPodMnt(mntPath string) string

GetPvNameFormPodMnt get pv name

func GetRegionID added in v1.3.0

func GetRegionID() (string, error)

GetRegionID Get RegionID from Environment Variables or Metadata

func Gi2Bytes added in v1.1.7

func Gi2Bytes(gb int64) int64

func HasSpecificTagKey added in v1.1.7

func HasSpecificTagKey(tagKey string, disk *ecs.Disk) (bool, string)

func IsDir added in v1.0.2

func IsDir(path string) bool

IsDir check file is directory

func IsDirEmpty added in v1.0.1

func IsDirEmpty(name string) (bool, error)

IsDirEmpty return status of dir empty or not

func IsDirTmpfs added in v1.1.5

func IsDirTmpfs(mounter k8smount.Interface, path string) (bool, error)

IsDirTmpfs check path is tmpfs mounted or not

func IsFileExisting

func IsFileExisting(filename string) bool

IsFileExisting check file exist in volume driver or not

func IsMountPointRunv added in v1.0.4

func IsMountPointRunv(mountPoint string) bool

IsMountPointRunv check the mountpoint is runv style. Remember to check this is not a regular mountpoint before calling this function.

func IsPathAvailiable added in v1.1.7

func IsPathAvailiable(path string) error

IsPathAvailiable

func IsPrivateCloud added in v1.1.7

func IsPrivateCloud() bool

func LoadJSONData added in v1.1.7

func LoadJSONData(dataFileName string) (map[string]string, error)

LoadJSONData loads json info from specified json file

func NewEcsClient added in v1.0.1

func NewEcsClient(ac AccessControl) (ecsClient *ecs.Client)

NewEcsClient create a ecsClient object

func NewEventRecorder added in v1.1.0

func NewEventRecorder() record.EventRecorder

NewEventRecorder is create snapshots event recorder

func NewStsClient added in v1.4.0

func NewStsClient(ac AccessControl) (stsClient *sts.Client)

NewStsClient create a stsClient object TODO: The current region is set to the default value. Need to obtain the actual region.

func Ping added in v1.1.1

func Ping(ipAddress string) (*ping.Statistics, error)

Ping check network like shell ping command

func ReadJSONFile added in v1.0.1

func ReadJSONFile(file string) (map[string]string, error)

ReadJSONFile return a json object

func RetryGetMetaData added in v1.1.5

func RetryGetMetaData(resource string) string

RetryGetMetaData ...

func RoundUpBytes added in v1.2.1

func RoundUpBytes(volumeSizeBytes int64) int64

RoundUpBytes rounds up the volume size in bytes upto multiplications of GiB in the unit of Bytes

func ValidatePath added in v1.1.7

func ValidatePath(path string) (bool, error)

ValidatePath is check path string is valid

func WithPodInfo added in v1.6.0

func WriteAndSyncFile added in v1.1.5

func WriteAndSyncFile(filename string, data []byte, perm os.FileMode) error

WriteAndSyncFile behaves just like ioutil.WriteFile in the standard library, but calls Sync before closing the file. WriteAndSyncFile guarantees the data is synced if there is no error returned.

func WriteJSONFile added in v1.0.1

func WriteJSONFile(obj interface{}, file string) error

WriteJSONFile save json data to file

func WriteMetricsInfo added in v1.1.7

func WriteMetricsInfo(metricsPathPrefix string, req *csi.NodePublishVolumeRequest, metricsTop string, clientName string, storageBackendName string, fsName string)

func WriteSharedMetricsInfo added in v1.4.0

func WriteSharedMetricsInfo(metricsPathPrefix string, req *csi.NodePublishVolumeRequest, clientName string, storageBackendName string, fsName string, sharedPath string)

Types

type AKInfo added in v1.0.5

type AKInfo struct {
	// AccessKeyId access key id
	AccessKeyID string `json:"access.key.id"`
	// AccessKeySecret access key secret
	AccessKeySecret string `json:"access.key.secret"`
	// SecurityToken security token
	SecurityToken string `json:"security.token"`
	// Expiration expiration duration
	Expiration string `json:"expiration"`
	// Keyring key ring
	Keyring string `json:"keyring"`
	// RoleAccessKeyId key
	RoleAccessKeyID string `json:"role.access.key.id"`
	// RoleAccessKeySecret key
	RoleAccessKeySecret string `json:"role.access.key.secret"`
	// RoleArn key
	RoleArn string `json:"role.arn"`
}

AKInfo access key info

type AccessControl added in v1.1.6

type AccessControl struct {
	AccessKeyID     string
	AccessKeySecret string
	StsToken        string
	RoleArn         string
	Config          *sdk.Config
	Credential      auth.Credential
	UseMode         AccessControlMode
}

AccessControl is access control option

func GetAccessControl added in v1.1.6

func GetAccessControl() AccessControl

GetAccessControl 1、Read default ak from local file. 2、If local default ak is not exist, then read from STS.

func GetDefaultRoleAK added in v1.1.5

func GetDefaultRoleAK() AccessControl

GetDefaultRoleAK 返回角色扮演账号AK, SK, role arn

func GetEnvAK added in v1.1.7

func GetEnvAK() AccessControl

GetEnvAK read ak from local ENV

type AccessControlMode added in v1.1.6

type AccessControlMode int

AccessControlMode is int, represents different modes

const (
	AccessKey AccessControlMode = iota
	ManagedToken
	EcsRAMRole
	Credential
	RoleArnToken
	OIDCToken
)

AccessControlMode includes AccessKey, ManagedToken, EcsRamRole, Credential, RoleArnToken, five types of access control

type Config added in v1.3.0

type Config struct {
	ConfigMap map[string]string
}

func (*Config) Get added in v1.3.0

func (c *Config) Get(configKey, env, defaultValue string) string

func (*Config) GetBool added in v1.3.0

func (c *Config) GetBool(configKey, env string, defaultValue bool) bool

func (*Config) GetInt added in v1.6.0

func (c *Config) GetInt(configKey, env string, defaultValue int) int

type ManageTokens added in v1.1.5

type ManageTokens struct {
	// AccessKeyId key
	AccessKeyID string
	// AccessKeySecret key
	AccessKeySecret string
	// SecurityToken key
	SecurityToken string

	// RoleAccessKeyId key
	RoleAccessKeyID string
	// RoleAccessKeySecret key
	RoleAccessKeySecret string
	// RoleArn key
	RoleArn string

	// expire time
	ExpireAt time.Time
}

ManageTokens 定义资源账号 和 角色扮演账号

type MountPoint added in v1.1.7

type MountPoint struct {
	Device string
	Path   string
	Type   string
	Opts   []string // Opts may contain sensitive mount options (like passwords) and MUST be treated as such (e.g. not logged).
	Freq   int
	Pass   int
}

MountPoint represents a single line in /proc/mounts or /etc/fstab.

type Mounter added in v1.0.1

type Mounter interface {
	// If the block doesn't exist, create it
	EnsureBlock(target string) error
	// Format formats the source with the given filesystem type
	Format(source, fsType string) error

	// Mount mounts source to target with the given fstype and options.
	Mount(source, target, fsType string, options ...string) error

	// Mount mounts source to target for block file.
	MountBlock(source, target string, options ...string) error
	// Unmount unmounts the given target
	Unmount(target string) error

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

Mounter is responsible for formatting and mounting volumes

func NewFakeMounter added in v1.6.0

func NewFakeMounter() Mounter

func NewMounter added in v1.0.1

func NewMounter() Mounter

NewMounter returns a new mounter instance

type PodCGroup added in v1.5.0

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

func NewPodCGroup added in v1.5.0

func NewPodCGroup() (*PodCGroup, error)

func (*PodCGroup) ApplyConfig added in v1.5.0

func (cg *PodCGroup) ApplyConfig(devicePath string, req *csi.NodePublishVolumeRequest) error

type RoleAuth added in v1.0.1

type RoleAuth struct {
	AccessKeyID     string
	AccessKeySecret string
	Expiration      time.Time
	SecurityToken   string
	LastUpdated     time.Time
	Code            string
}

RoleAuth define STS Token Response

type ServiceType added in v1.1.1

type ServiceType int
const (
	Controller ServiceType = 1 << iota
	Node
)

func GetServiceType added in v1.6.0

func GetServiceType(runAsController, runControllerService, runNodeService bool) ServiceType

type VolumeLocks added in v1.3.0

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

func NewVolumeLocks added in v1.3.0

func NewVolumeLocks() *VolumeLocks

func (*VolumeLocks) Release added in v1.3.0

func (lock *VolumeLocks) Release(volumeID string)

Release releases lock in volume level

func (*VolumeLocks) TryAcquire added in v1.3.0

func (lock *VolumeLocks) TryAcquire(volumeID string) bool

TryAcquire tries to acquire the lock for operating on resourceID and returns true if successful. If another operation is already using resourceID, returns false.

Directories

Path Synopsis
kata
rund

Jump to

Keyboard shortcuts

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