utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: GPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxAttempts is the max attempts
	MaxAttempts = 99999999
)

Variables

View Source
var (
	// ErrCancelled indicates the operation was cancelled
	ErrCancelled = errors.New("operation cancelled")
	// ErrReachMaxAttempts indicates we hit the limit
	ErrReachMaxAttempts = errors.New("reached max attempts")
)

Functions

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI returns the number of bytes in the given number of SI units.

func Contains

func Contains(v string, l []string) bool

Contains checks a list has a value in it

func ContainsList

func ContainsList(v []string, l []string) bool

ContainsList checks a list has a value in it

func DirExists

func DirExists(path string) (bool, error)

DirExists checks if the directory exists

func DirSize

func DirSize(path string) (int64, error)

DirSize returns the size of the directory

func FileExists

func FileExists(filename string) (bool, error)

FileExists checks if a file exists

func GetTxtFunc

func GetTxtFunc() map[string]any

GetTxtFunc returns a defaults list of methods for text templating

func IsLabelSelectorMatch

func IsLabelSelectorMatch(source map[string]string, selector metav1.LabelSelector) (bool, error)

IsLabelSelectorMatch is used to check if the selectors matches the labels.

func IsSelectorMatch

func IsSelectorMatch(
	selector terraformv1alphav1.Selector,
	resourceLabels, namespaceLabels map[string]string) (bool, error)

IsSelectorMatch is used to check if the resource matches the selectors.

func Prefix

func Prefix(prefix string, e interface{}) string

Prefix is a hack to get prefixes to fix

func Retry

func Retry(ctx context.Context, attempts int, jitter bool, minInterval time.Duration, retryFn RetryFunc) error

Retry is used to retry an operation multiple times under a context. If the retryFn returns false with no error, the operation will be retried.

func RetryWithTimeout

func RetryWithTimeout(ctx context.Context, timeout, interval time.Duration, retryFn RetryFunc) error

RetryWithTimeout creates a retry with a specific timeout

func Sleep

func Sleep(ctx context.Context, sleep time.Duration) bool

Sleep provides a default sleep but with a cancellable context

func TouchFile

func TouchFile(path string) error

TouchFile is used to create a file

func WaitForFile

func WaitForFile(ctx context.Context, path string, timeout time.Duration) error

WaitForFile waits for a file to exist or times out

func YAMLDocuments

func YAMLDocuments(reader io.Reader) ([]string, error)

YAMLDocuments returns a collection of documents from the reader

Types

type RetryFunc

type RetryFunc func() (bool, error)

RetryFunc performs the operation. It should return true if the operation is complete, false if it should be retried, and an error if an error which should NOT be retried has occurred.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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