util

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 25 Imported by: 4

Documentation

Index

Constants

View Source
const (
	BlockSizeLinux = 512
)
View Source
const DNS1123SubdomainMaxLength int = 253

DNS1123SubdomainMaxLength is a subdomain's max length in DNS (RFC 1123)

View Source
const (
	DevicePathPrefix = longhorndev.DevPath
)

Variables

View Source
var (
	MaximumVolumeNameSize = 64
)

Functions

func CheckBackupType

func CheckBackupType(backupTarget string) (string, error)

func DuplicateDevice

func DuplicateDevice(src, dest string) error

func EmptyError

func EmptyError() string

EmptyError returns a string explanation of a "must not be empty" validation failure.

func Filter

func Filter(list []string, check func(string) bool) []string

func FilteredLoggingHandler

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

func FreezeFilesystem added in v1.7.0

func FreezeFilesystem(freezePoint string, exec lhexec.ExecuteInterface) error

FreezeFilesystem attempts to freeze the filesystem mounted at freezePoint.

func GetAddresses added in v1.4.0

func GetAddresses(volumeName, address string, dataServerProtocol types.DataServerProtocol) (string, string, string, int, error)

func GetDevicePathFromVolumeName added in v1.7.0

func GetDevicePathFromVolumeName(volumeName string) string

GetDevicePathFromVolumeName mirrors longhorndev.getDev. It returns the device path that go-iscsi-helper will use.

func GetFileActualSize

func GetFileActualSize(file string) int64

func GetFreezePointFromDevicePath added in v1.7.0

func GetFreezePointFromDevicePath(devicePath string) string

GetFreezePointFromDevicePath returns the absolute path to the canonical location we will try to mount a filesystem to before freezeing it.

func GetFreezePointFromVolumeName added in v1.7.0

func GetFreezePointFromVolumeName(volumeName string) string

GetFreezePointFromVolumeName returns the absolute path to the canonical location we will try to mount a filesystem to before freezeing it.

func GetGRPCAddress

func GetGRPCAddress(address string) string

func GetHeadFileModifyTimeAndSize added in v1.1.0

func GetHeadFileModifyTimeAndSize(file string) (int64, int64, error)

func GetPortFromAddress

func GetPortFromAddress(address string) (int, error)

func IsDNS1123Subdomain

func IsDNS1123Subdomain(value string) []string

IsDNS1123Subdomain tests for a string that conforms to the definition of a subdomain in DNS (RFC 1123).

func IsQualifiedName

func IsQualifiedName(value string) []string

IsQualifiedName tests whether the value passed is what Kubernetes calls a "qualified name". This is a format used in various places throughout the system. If the value is not valid, a list of error strings is returned. Otherwise an empty list (or nil) is returned.

func MaxLenError

func MaxLenError(length int) string

MaxLenError returns a string explanation of a "string too long" validation failure.

func Now

func Now() string

func ParseAddresses

func ParseAddresses(name string) (string, string, string, int, error)

func ParseLabels

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

func RandomID added in v1.4.0

func RandomID() string

func RegexError

func RegexError(msg string, fmt string, examples ...string) string

RegexError returns a string explanation of a regex validation failure.

func RemoveDevice

func RemoveDevice(dev string) error

func ResolveBackingFilepath

func ResolveBackingFilepath(fileOrDirpath string) (string, error)

func UUID

func UUID() string

func UnescapeURL

func UnescapeURL(url string) string

func UnfreezeAndUnmountFilesystem added in v1.7.0

func UnfreezeAndUnmountFilesystem(freezePoint string, exec lhexec.ExecuteInterface,
	mounter mount.Interface) (bool, error)

UnfreezeAndUnmountFilesystem attempts to unfreeze the filesystem mounted at freezePoint.

func UnfreezeFilesystem added in v1.7.0

func UnfreezeFilesystem(freezePoint string, exec lhexec.ExecuteInterface) (bool, error)

UnfreezeFilesystem attempts to unfreeze the filesystem mounted at freezePoint. It returns true if it successfully unfreezes a filesystem, false if there is no need to unfreeze a filesystem, and an error otherwise.

func UnfreezeFilesystemForDevice added in v1.7.0

func UnfreezeFilesystemForDevice(devicePath string) error

UnfreezeFilesystemForDevice attempts to identify a mountPoint for the Longhorn volume and unfreeze it. Under normal conditions, it will not find a filesystem, and if it finds a filesystem, it will not be frozen. UnfreezeFilesystemForDevice does not return an error if there is nothing to do. UnfreezeFilesystemForDevice is only relevant for volumes run with a tgt-blockdev frontend, as only these volumes have a Longhorn device on the node to format and mount.

func ValidVolumeName

func ValidVolumeName(name string) bool

func Volume2ISCSIName

func Volume2ISCSIName(name string) string

Types

type Once added in v1.1.3

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

Once is modification of sync.Once to only set done once Do has run f() once successfully A Once must not be copied after first use.

func (*Once) Do added in v1.1.3

func (o *Once) Do(f func() error) error

Do execute f() only if it has never been run successfully before if f() encounters an error it will be returned to the caller

type SharedTimeouts added in v1.7.1

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

SharedTimeouts has the following use case: - Multiple goroutines may need to time out eventually. - Only the goroutines themselves know if the conditions for a timeout have been met. - It is fine for some of the goroutines to time out quickly. - The last goroutine should time out more slowly. SharedTimeouts implements the types.SharedTimeouts instead of directly defining the concrete type to avoid an import loop.

func NewSharedTimeouts added in v1.7.1

func NewSharedTimeouts(shortTimeout, longTimeout time.Duration) *SharedTimeouts

func (*SharedTimeouts) CheckAndDecrement added in v1.7.1

func (t *SharedTimeouts) CheckAndDecrement(duration time.Duration) time.Duration

CheckAndDecrement checks if duration exceeds longTimeout or shortTimeout, returns the timeout exceeded (if applicable) and decrements numConsumers. - shortTimeout is only considered exceeded if there is still one other consumer to wait for longTimeout. - The caller MUST take whatever action is required for a timeout if a value > 0 is returned.

func (*SharedTimeouts) Decrement added in v1.7.1

func (t *SharedTimeouts) Decrement()

func (*SharedTimeouts) Increment added in v1.7.1

func (t *SharedTimeouts) Increment()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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