utils

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: Apache-2.0 Imports: 33 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 (
	// UserAKID is user AK ID
	UserAKID = "/etc/.volumeak/akId"
	// UserAKSecret is user AK Secret
	UserAKSecret = "/etc/.volumeak/akSecret"
	// MetadataURL is metadata url
	MetadataURL = "http://100.100.100.200/latest/meta-data/"
	// 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"
	// ServiceType tag
	ServiceType = "SERVICE_TYPE"
	// PluginService represents the csi-plugin type.
	PluginService = "plugin"
	// ProvisionerService represents the csi-provisioner type.
	ProvisionerService = "provisioner"
)
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
	},
}

DiskProvisionErrors are errors throwed by ecs create disk api

View Source
var KubernetesAlicloudIdentity = fmt.Sprintf("Kubernetes.Alicloud/CsiPlugin")

KubernetesAlicloudIdentity set a identity label

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

Functions

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 Decrypt added in v1.0.5

func Decrypt(s string, keyring []byte) ([]byte, error)

Decrypt secret Decrypt

func FindSuggestionByErrorMessage added in v1.1.0

func FindSuggestionByErrorMessage(errMsg, errorType string) string

FindSuggestionByErrorMessage get new error message by error type & error message

func GetDefaultAK

func GetDefaultAK() (string, string, string)

GetDefaultAK read default ak from local file or from STS

func GetFileContent added in v1.0.4

func GetFileContent(fileName string) string

GetFileContent get file content

func GetLocalAK

func GetLocalAK() (string, string)

GetLocalAK read ossfs ak from local or from secret file

func GetManagedToken added in v1.0.5

func GetManagedToken() (string, string, string)

GetManagedToken get ak from csi secret

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 GetPodRunTime added in v1.0.4

func GetPodRunTime(req *csi.NodePublishVolumeRequest, clientSet *kubernetes.Clientset) (string, error)

GetPodRunTime Get Pod runtimeclass config Default as runc.

func GetRegionAndInstanceID added in v1.0.1

func GetRegionAndInstanceID() (string, string, error)

GetRegionAndInstanceID get region and instanceID object

func GetRegionIDAndInstanceID added in v1.0.1

func GetRegionIDAndInstanceID(nodeName string) (string, string, error)

GetRegionIDAndInstanceID get regionID and instanceID object

func GetSTSAK

func GetSTSAK() (string, string, string)

GetSTSAK get STS AK and token from ecs meta server

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

func IsMounted

func IsMounted(mountPath string) bool

IsMounted return status of mount operation

func NewEcsClient added in v1.0.1

func NewEcsClient(accessKeyID, accessKeySecret, accessToken string) (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 PKCS5UnPadding added in v1.0.5

func PKCS5UnPadding(origData []byte) []byte

PKCS5UnPadding get pkc

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 Run

func Run(cmd string) (string, error)

Run run shell command

func RunTimeout added in v1.1.4

func RunTimeout(cmd string, timeout int) error

RunTimeout tag

func Umount

func Umount(mountPath string) error

Umount do an unmount operation

func WriteJSONFile added in v1.0.1

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

WriteJSONFile write a json object

func WriteJosnFile

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

WriteJosnFile save json data to file

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"`
}

AKInfo access key info

type CommandRunFunc added in v1.1.1

type CommandRunFunc func(cmd string) (string, error)

CommandRunFunc define the run function in utils for ut

type DefaultOptions

type DefaultOptions struct {
	Global struct {
		KubernetesClusterTag string
		AccessKeyID          string `json:"accessKeyID"`
		AccessKeySecret      string `json:"accessKeySecret"`
		Region               string `json:"region"`
	}
}

DefaultOptions used for global ak

type Mounter added in v1.0.1

type Mounter interface {
	// If the folder doesn't exist, it will call 'mkdir -p'
	EnsureFolder(target string) error
	// 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

	// IsFormatted checks whether the source device is formatted or not. It
	// returns true if the source device is already formatted.
	IsFormatted(source string) (bool, error)

	// IsMounted checks whether the target path is a correct mount (i.e:
	// propagated). It returns true if it's mounted. An error is returned in
	// case of system errors or if it's mounted incorrectly.
	IsMounted(target string) (bool, error)

	SafePathRemove(target string) error

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

Mounter is responsible for formatting and mounting volumes

func NewMounter added in v1.0.1

func NewMounter() Mounter

NewMounter returns a new mounter instance

type Result

type Result struct {
	Status  string `json:"status"`
	Message string `json:"message,omitempty"`
	Device  string `json:"device,omitempty"`
}

Result struct definition

func Fail

func Fail(a ...interface{}) Result

Fail return a Fail Result

func NotSupport

func NotSupport(a ...interface{}) Result

NotSupport return a NotSupport Result

func Succeed

func Succeed(a ...interface{}) Result

Succeed return a Succeed Result

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

Jump to

Keyboard shortcuts

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