utils

package
v4.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package utils to provide utils for CSI

Index

Constants

View Source
const (
	DoradoV6Prefix    = "V600"
	OceanStorV5Prefix = "V500"
)

Variables

View Source
var ExecShellCmd = func(ctx context.Context, format string, args ...interface{}) (string, error) {
	return execShellCmdTimeout(ctx, execShellCmd, format, false, args...)
}

ExecShellCmd execs the command without filters the result log

View Source
var PathExist = func(path string) (bool, error) {
	_, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return false, nil
		} else {
			return false, err
		}
	}

	return true, nil
}

Functions

func AtoiWithDefault

func AtoiWithDefault(s string, defaultResult int) int

AtoiWithDefault Atoi without error

func CheckExistCode

func CheckExistCode(err error, checkExitCode []string) error

CheckExistCode if the error code exist in ExitCode, return err

func ChmodFsPermission

func ChmodFsPermission(ctx context.Context, targetPath, fsPermission string)

ChmodFsPermission used for change target path permission

func Contains

func Contains[T comparable](sources []T, target T) bool

Contains sources contains target

func ConvertMapToStruct

func ConvertMapToStruct[T any](params map[string]any) (*T, error)

ConvertMapToStruct converts map[string]any to struct

func CopyMap

func CopyMap(srcMap interface{}) map[string]interface{}
func CreateSymlink(ctx context.Context, source string, target string) error

CreateSymlink between source and target

func Errorf

func Errorf(ctx context.Context, format string, a ...interface{}) error

Errorf used to create and print formatted error messages.

func Errorln

func Errorln(ctx context.Context, msg string) error

Errorln used to create and print error messages.

func ExecShellCmdFilterLog

func ExecShellCmdFilterLog(ctx context.Context, format string, args ...interface{}) (string, error)

ExecShellCmdFilterLog execs the command and filters the result log

func GetAccessModeType

func GetAccessModeType(accessMode csi.VolumeCapability_AccessMode_Mode) string

func GetAlua

func GetAlua(ctx context.Context, alua map[string]interface{}, host string) map[string]interface{}

func GetCertFromSecret

func GetCertFromSecret(ctx context.Context, SecretName, SecretNamespace string) ([]byte, error)

GetCertFromSecret used to get cert from secret

func GetDtreeSharePath

func GetDtreeSharePath(name string) string

func GetFSSharePath

func GetFSSharePath(name string) string

func GetFSSnapshotName

func GetFSSnapshotName(name string) string

func GetFileSystemName

func GetFileSystemName(name string) string

func GetForbiddenMultipath

func GetForbiddenMultipath(ctx context.Context,
	multipathConfig map[string]interface{},
	backendConfigs []map[string]interface{}) []string

GetForbiddenMultipath used to get forbidden multipath service by configuration and backend info.

func GetFusionStorageLunName

func GetFusionStorageLunName(name string) string

func GetFusionStorageSnapshotName

func GetFusionStorageSnapshotName(name string) string

func GetHostName

func GetHostName(ctx context.Context) (string, error)

func GetLunUniqueId

func GetLunUniqueId(ctx context.Context, protocol string, lun map[string]interface{}) (string, error)

func GetOriginSharePath

func GetOriginSharePath(name string) string

func GetPasswordFromSecret

func GetPasswordFromSecret(ctx context.Context, SecretName, SecretNamespace string) (string, error)

GetPasswordFromSecret used to get password from secret

func GetProductVersion

func GetProductVersion(systemInfo map[string]interface{}) (string, error)

GetProductVersion is to get the oceanStorage version by get info from the system

func GetRequiredMultipath

func GetRequiredMultipath(ctx context.Context,
	multipathConfig map[string]interface{},
	backendConfigs []map[string]interface{}) ([]string, error)

GetRequiredMultipath used to get required multipath service by configuration and backend info.

func GetSharePath

func GetSharePath(name string) string

func GetSnapshotName

func GetSnapshotName(name string) string

func GetValueByRegexp

func GetValueByRegexp(sourceString string, patternString string, valueIndex int) string

GetValueByRegexp used to get value by regular expression

func IgnoreExistCode

func IgnoreExistCode(err error, checkExitCode []string) error

IgnoreExistCode if the error code exist in ExitCode, return nil

func IsCapacityAvailable

func IsCapacityAvailable(volumeSizeBytes int64, allocationUnitBytes int64) bool

IsCapacityAvailable indicates whether the volume size is an integer multiple of 512.

func IsContain

func IsContain[T constants.FileType | string](target T, list []T) bool

IsContain used to determine whether list contains target. type support FileType, string now and can be extended

func IsDebugLog

func IsDebugLog(method, url string, debugLogMap map[string]map[string]bool, regLogs map[string][]string) bool

IsDebugLog is used to determine whether debug log are required.

func IsPathSymlink(targetPath string) (symlink bool, err error)

IsPathSymlink checks weather this targetPath is symlink

func IsPathSymlinkWithTimeout

func IsPathSymlinkWithTimeout(targetPath string, duration time.Duration) (bool, error)

IsPathSymlinkWithTimeout checks weather this targetPath is symlink

func IsSupportFeature

func IsSupportFeature(features map[string]int, feature string) bool

func MaskConnSensitiveInfo

func MaskConnSensitiveInfo(info interface{}) string

func MaskSensitiveInfo

func MaskSensitiveInfo(info interface{}) string

func MergeMap

func MergeMap(args ...map[string]interface{}) map[string]interface{}

func NewContextWithRequestID

func NewContextWithRequestID() context.Context

NewContextWithRequestID new a context

func ParseIntWithDefault

func ParseIntWithDefault(s string, base int, bitSize int, defaultResult int64) int64

ParseIntWithDefault parseInt without error

func RandomInt

func RandomInt(n int) int

func ReadWwnFile

func ReadWwnFile(ctx context.Context, volumeId string) (string, error)

ReadWwnFile read the wwn info file.

func RecoverPanic

func RecoverPanic(ctx context.Context)

RecoverPanic used to recover panic

func ReflectCall

func ReflectCall(obj interface{}, method string, args ...interface{}) []reflect.Value

func RemoveDir

func RemoveDir(filePath, dir string)

RemoveDir delete directory from filePath

func RemoveString

func RemoveString(slice []string, s string) []string

RemoveString returns a newly created []string that contains all items from slice that are not equal to s.

func RemoveSymlink(ctx context.Context, target string) error

RemoveSymlink from target path

func RemoveWwnFile

func RemoveWwnFile(ctx context.Context, volumeId string) error

RemoveWwnFile remove the wwn info file.

func ResCodeExist

func ResCodeExist(code interface{}) bool

ResCodeExist if code not 0 then return error

func RoundUpSize

func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64

func SplitSnapshotId

func SplitSnapshotId(snapshotId string) (string, string, string)

func SplitVolumeId

func SplitVolumeId(volumeId string) (string, string)

func StrToBool

func StrToBool(ctx context.Context, str string) bool

func StringContain

func StringContain(strPrefix string, stringList []string) bool

StringContain return the string prefix whether in the target string list

func ToStringSafe

func ToStringSafe(i interface{}) string

ToStringSafe convert to string with default "" safe

func ToStringWithFlag

func ToStringWithFlag(i interface{}) (string, bool)

ToStringWithFlag if success return true, or return false

func TransK8SCapacity

func TransK8SCapacity(volumeSizeSectors, allocationUnitBytes int64) int64

TransK8SCapacity trans volume size from Sector to Bytes

func TransToInt

func TransToInt(v interface{}) (int, error)

TransToInt is to trans different type to int type.

func TransToIntStrict

func TransToIntStrict(ctx context.Context, val interface{}) (int, error)

TransToIntStrict only trans int type.

func TransVolumeCapacity

func TransVolumeCapacity(size int64, unit int64) int64

func WaitUntil

func WaitUntil(f func() (bool, error), timeout time.Duration, interval time.Duration) error

func WriteWWNFile

func WriteWWNFile(ctx context.Context, wwn, volumeId string) error

WriteWWNFile write the wwn info for use in unstage call.

func WriteWWNFileIfNotExist

func WriteWWNFileIfNotExist(ctx context.Context, wwn, volumeId string) error

WriteWWNFileIfNotExist write new's wwn to file if the file doesn't exist in disk, or wwn file exist but content is empty.

Types

type Semaphore

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

func NewSemaphore

func NewSemaphore(permits int) *Semaphore

func (*Semaphore) Acquire

func (s *Semaphore) Acquire()

func (*Semaphore) AvailablePermits

func (s *Semaphore) AvailablePermits() int

func (*Semaphore) GetChannel

func (s *Semaphore) GetChannel() chan int

func (*Semaphore) Release

func (s *Semaphore) Release()

type Volume

type Volume interface {
	GetVolumeName() string
	GetLunWWN() (string, error)
	SetLunWWN(string)
	SetSize(int64)
	GetSize() (int64, error)
	SetDTreeParentName(string)
	GetDTreeParentName() string
	GetFilesystemMode() string
	SetFilesystemMode(string)
	GetID() string
	SetID(string)
}

Volume interface is a perform operations on volume object

func NewVolume

func NewVolume(name string) Volume

NewVolume creates volume object for the name

type VolumeMetrics

type VolumeMetrics struct {
	Available  *resource.Quantity
	Capacity   *resource.Quantity
	InodesUsed *resource.Quantity
	Inodes     *resource.Quantity
	InodesFree *resource.Quantity
	Used       *resource.Quantity
}

func GetVolumeMetrics

func GetVolumeMetrics(path string) (*VolumeMetrics, error)

Directories

Path Synopsis
Package concurrent used to process concurrent request
Package concurrent used to process concurrent request
Package k8sutils provides Kubernetes utilities
Package k8sutils provides Kubernetes utilities
Package log output logged entries to respective logging hooks
Package log output logged entries to respective logging hooks
Package notify offers a wait and notify mechanism
Package notify offers a wait and notify mechanism
Package taskflow offers task flow operations
Package taskflow offers task flow operations
Package version offers version inits options
Package version offers version inits options

Jump to

Keyboard shortcuts

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