util

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 42 Imported by: 7

Documentation

Index

Constants

View Source
const (
	VolumeStackPrefix     = "volume-"
	ControllerServiceName = "controller"
	ReplicaServiceName    = "replica"

	HostProcPath                 = "/host/proc"
	ReplicaDirectory             = "/replicas/"
	RegularDeviceDirectory       = "/dev/longhorn/"
	EncryptedDeviceDirectory     = "/dev/mapper/"
	TemporaryMountPointDirectory = "/tmp/mnt/"

	DefaultKubernetesTolerationKey = "kubernetes.io"

	DiskConfigFile = "longhorn-disk.cfg"

	SizeAlignment     = 2 * 1024 * 1024
	MinimalVolumeSize = 10 * 1024 * 1024

	RandomIDLenth = 8
)

Variables

View Source
var (
	APIRetryInterval       = 500 * time.Millisecond
	APIRetryJitterInterval = 50 * time.Millisecond
	APIRetryCounts         = 10
)

Functions

func AddFinalizer

func AddFinalizer(name string, obj runtime.Object) error

func AutoCorrectName added in v1.1.1

func AutoCorrectName(name string, maxLength int) string

AutoCorrectName converts name to lowercase, and correct overlength name by replaces the name suffix with 8 char from its checksum to ensure uniquenedoss.

func Backoff

func Backoff(maxDuration time.Duration, timeoutMessage string, f func() (bool, error)) error

func CapitalizeFirstLetter added in v1.4.0

func CapitalizeFirstLetter(input string) string

func CheckBackupType

func CheckBackupType(backupTarget string) (string, error)

func CmdOutLines

func CmdOutLines(cmd *exec.Cmd, cancel <-chan interface{}) (<-chan string, <-chan error)

func Contains added in v1.2.0

func Contains(list []string, item string) bool

func ConvertSize

func ConvertSize(size interface{}) (int64, error)

func CopyHostDirectoryContent added in v0.8.0

func CopyHostDirectoryContent(src, dest string) (err error)

func CopyReq

func CopyReq(req *http.Request) *http.Request

func CreateDiskPathReplicaSubdirectory added in v0.8.1

func CreateDiskPathReplicaSubdirectory(path string) error

func DeleteDiskPathReplicaSubdirectoryAndDiskCfgFile added in v1.0.0

func DeleteDiskPathReplicaSubdirectoryAndDiskCfgFile(
	nsExec *iscsi_util.NamespaceExecutor, path string) error

func DeleteReplicaDirectoryName added in v1.3.0

func DeleteReplicaDirectoryName(diskPath, replicaDirectoryName string) (err error)

func EncodeToYAMLFile added in v1.4.0

func EncodeToYAMLFile(obj interface{}, path string) (err error)

func Execute

func Execute(envs []string, binary string, args ...string) (string, error)

func ExecuteWithTimeout

func ExecuteWithTimeout(timeout time.Duration, envs []string, binary string, args ...string) (string, error)

func ExecuteWithoutTimeout added in v0.6.0

func ExecuteWithoutTimeout(envs []string, binary string, args ...string) (string, error)

func FilteredLoggingHandler added in v0.4.1

func FilteredLoggingHandler(filteredPaths map[string]struct{}, writer io.Writer, router http.Handler) http.Handler

func FinalizerExists

func FinalizerExists(name string, obj runtime.Object) bool

func FormatLocalTime

func FormatLocalTime(t time.Time, loc *time.Location) string

func FormatTimeZ

func FormatTimeZ(t time.Time) string

func FromMillis

func FromMillis(t int64) time.Time

func GetAnnotation added in v1.1.0

func GetAnnotation(obj runtime.Object, annotationKey string) (string, error)

func GetBackupID

func GetBackupID(backupURL string) (string, error)

func GetChecksumSHA256 added in v1.3.0

func GetChecksumSHA256(data []byte) string

func GetChecksumSHA512

func GetChecksumSHA512(data []byte) string

func GetDistinctTolerations added in v1.1.0

func GetDistinctTolerations(tolerationList []v1.Toleration) []v1.Toleration

func GetLocalIPs

func GetLocalIPs() ([]string, error)

func GetPodIP added in v1.4.0

func GetPodIP(pod *v1.Pod) (string, error)

func GetPossibleReplicaDirectoryNames added in v1.3.0

func GetPossibleReplicaDirectoryNames(diskPath string) (replicaDirectoryNames map[string]string, err error)

func GetRequiredEnv

func GetRequiredEnv(key string) (string, error)

func GetSortedKeysFromMap added in v1.1.2

func GetSortedKeysFromMap(maps interface{}) []string

func GetStringChecksum

func GetStringChecksum(data string) string

func GetStringChecksumSHA256 added in v1.3.0

func GetStringChecksumSHA256(data string) string

func GetStringHash added in v1.2.0

func GetStringHash(data string) string

func GetTolerationChecksum added in v1.1.0

func GetTolerationChecksum(t v1.Toleration) string

func HasLocalStorageInDeployment added in v1.3.0

func HasLocalStorageInDeployment(deployment *appsv1.Deployment) bool

HasLocalStorageInDeployment returns true if deployment has any local storage.

func IsKubernetesDefaultToleration added in v0.6.0

func IsKubernetesDefaultToleration(toleration v1.Toleration) bool

func IsKubernetesVersionAtLeast added in v0.8.0

func IsKubernetesVersionAtLeast(kubeClient clientset.Interface, vers string) (bool, error)

func LimitToPeriod

func LimitToPeriod(p, t [2]time.Time) [2]time.Time

func MinInt added in v1.1.1

func MinInt(a, b int) int

func Now

func Now() string

func ParseLabels

func ParseLabels(labels []string) (map[string]string, error)

ParseLabels parses the provided Labels based on longhorn-engine's implementation: https://github.com/longhorn/longhorn-engine/blob/master/util/util.go

func ParseLocalTime

func ParseLocalTime(ts string, loc *time.Location) (time.Time, error)

func ParsePeriod

func ParsePeriod(s string, loc *time.Location) ([2]time.Time, error)

func ParseTime

func ParseTime(t string) (time.Time, error)

func ParseTimeZ

func ParseTimeZ(s string) (time.Time, error)

func RandomID

func RandomID() string

func RegisterShutdownChannel

func RegisterShutdownChannel(done chan struct{})

func RemoveFinalizer

func RemoveFinalizer(name string, obj runtime.Object) error

func RemoveHostDirectoryContent added in v0.3.3

func RemoveHostDirectoryContent(directory string) (err error)

func RetryOnConflictCause

func RetryOnConflictCause(fn func() (interface{}, error)) (interface{}, error)

func RetryOnErrorCondition added in v1.2.0

func RetryOnErrorCondition(fn func() (interface{}, error), predicate func(error) bool) (interface{}, error)

func RetryOnNotFoundCause added in v1.2.0

func RetryOnNotFoundCause(fn func() (interface{}, error)) (interface{}, error)

func RoundUpSize

func RoundUpSize(size int64) int64

func RunAsync added in v0.3.1

func RunAsync(wg *sync.WaitGroup, f func())

func SetAnnotation added in v1.1.0

func SetAnnotation(obj runtime.Object, annotationKey, annotationValue string) error

func SortKeys added in v1.4.0

func SortKeys(mapObj interface{}) ([]string, error)

SortKeys accepts a map with string keys and returns a sorted slice of keys

func SplitStringToMap

func SplitStringToMap(str, separator string) map[string]struct{}

func TimestampAfterTimeout

func TimestampAfterTimeout(ts string, timeout time.Duration) bool

func TimestampWithinLimit added in v0.8.0

func TimestampWithinLimit(latest time.Time, ts string, limit time.Duration) bool

func TolerationListToMap added in v0.6.0

func TolerationListToMap(tolerationList []v1.Toleration) map[string]v1.Toleration

func TrimFilesystem added in v1.4.0

func TrimFilesystem(volumeName string, isEncryptedDevice bool) error

func UUID

func UUID() string

func ValidateChecksumSHA512 added in v1.2.3

func ValidateChecksumSHA512(checksum string) bool

func ValidateName

func ValidateName(name string) bool

func ValidateRandomID added in v1.3.0

func ValidateRandomID(id string) bool

func ValidateSnapshotLabels added in v0.6.0

func ValidateSnapshotLabels(labels map[string]string) (map[string]string, error)

func ValidateTags added in v0.6.0

func ValidateTags(inputTags []string) ([]string, error)

func WaitForAPI

func WaitForAPI(url string, timeout int) error

WaitForAPI timeout in second

func WaitForDevice

func WaitForDevice(dev string, timeout int) error

WaitForDevice timeout in second

Types

type AtomicCounter added in v1.3.0

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

func (*AtomicCounter) DecreaseCount added in v1.3.0

func (ac *AtomicCounter) DecreaseCount()

func (*AtomicCounter) GetCount added in v1.3.0

func (ac *AtomicCounter) GetCount() int32

func (*AtomicCounter) IncreaseCount added in v1.3.0

func (ac *AtomicCounter) IncreaseCount()

func (*AtomicCounter) ResetCount added in v1.3.0

func (ac *AtomicCounter) ResetCount()

type Counter added in v1.3.0

type Counter interface {
	GetCount() int32
	IncreaseCount()
	DecreaseCount()
	ResetCount()
}

func NewAtomicCounter added in v1.3.0

func NewAtomicCounter() Counter

type DiskConfig added in v0.8.1

type DiskConfig struct {
	DiskUUID string `json:"diskUUID"`
}

func GenerateDiskConfig added in v0.8.1

func GenerateDiskConfig(path string) (*DiskConfig, error)

func GetDiskConfig added in v0.8.1

func GetDiskConfig(path string) (*DiskConfig, error)

type DiskStat added in v1.3.0

type DiskStat struct {
	Fsid             string
	Path             string
	Type             string
	FreeBlock        int64
	TotalBlock       int64
	BlockSize        int64
	StorageMaximum   int64
	StorageAvailable int64
}

func GetDiskStat added in v1.3.0

func GetDiskStat(directory string) (stat *DiskStat, err error)

type MetadataConfig

type MetadataConfig struct {
	DriverName          string
	Image               string
	OrcImage            string
	DriverContainerName string
}

type MultiError added in v1.2.5

type MultiError map[string]struct{}

func NewMultiError added in v1.2.5

func NewMultiError(errs ...string) MultiError

func (MultiError) Append added in v1.2.5

func (me MultiError) Append(errs MultiError)

func (MultiError) Join added in v1.2.5

func (me MultiError) Join() string

func (MultiError) Reset added in v1.4.0

func (me MultiError) Reset()

type VolumeMeta added in v1.3.0

type VolumeMeta struct {
	Size            int64
	Head            string
	Dirty           bool
	Rebuilding      bool
	Error           string
	Parent          string
	SectorSize      int64
	BackingFilePath string
	BackingFile     interface{}
}

func GetVolumeMeta added in v1.3.0

func GetVolumeMeta(path string) (*VolumeMeta, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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