utils

package
v0.0.35-0...-fad7822 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr returns a pointer to a bool with value v

func DropInDir

func DropInDir(unit string) string

DropInDir returns the name of the directory for the specified unit

func ExitStatusFromError

func ExitStatusFromError(err error) *int

ExitStatusFromError returns the exit status from the specified error. If the error is not exit status error, return nil

func GetRegion

func GetRegion() (string, error)

GetRegion returns the region the instance is running in.

func Int32Ptr

func Int32Ptr(v int32) *int32

Int32Ptr returns a pointer to an int64 with value v

func NewUnlimitedExponentialBackOff

func NewUnlimitedExponentialBackOff() backoff.BackOff

NewUnlimitedExponentialBackOff returns a backoff interval without time restriction

func Retry

func Retry(ctx context.Context, times int, period time.Duration, fn func() error) error

Retry retries 'times' attempts with retry period 'period' calling function fn until it returns nil, or until the context gets cancelled or the retries get exceeded the times number of attempts

func RetryWithInterval

func RetryWithInterval(ctx context.Context, interval backoff.BackOff, fn func() error) error

RetryWithInterval retries the specified operation fn using the specified backoff interval. fn should return backoff.PermanentError if the error should not be retried and returned directly. Returns nil on success or the last received error upon exhausting the interval.

func SafeWriteFile

func SafeWriteFile(filename string, data []byte, perm os.FileMode) error

SafeWriteFile is similar to ioutil.WriteFile, but operates by writing to a temporary file first and then relinking the file into the filename which should be an atomic operation. This should be safer, that if the destination file is being replaced, it won't be left in a partial written state.

func ToJSON

func ToJSON(data []byte) ([]byte, error)

ToJSON converts a single YAML document into a JSON document or returns an error. If the document appears to be JSON the YAML decoding path is not used (so that error messages are JSON specific). Creds to: k8s.io for the code

func WriteDropIn

func WriteDropIn(dropInDir, dropInFile string, contents []byte) error

WriteDropIn creates the file specified with dropInPath in directory specified with dropInDir with given contents

func WriteHosts

func WriteHosts(writer io.Writer, entries []HostEntry) error

WriteHosts formats entries in hosts file format to writer

Types

type Continue

type Continue string

Continue is an artificial error value that indicates that a retry loop should be re-executed with the specified message

func (Continue) Error

func (r Continue) Error() string

Error returns the contents of this value. Implements error

type DNSConfig

type DNSConfig struct {
	Servers    []string // servers to use
	Domain     string   // Domain parameter
	Search     []string // suffixes to append to local name
	Ndots      int      // number of dots in name to trigger absolute lookup
	Timeout    int      // seconds before giving up on packet
	Attempts   int      // lost packets before giving up on server
	Rotate     bool     // round robin among servers
	UnknownOpt bool     // anything unknown was encountered
	Lookup     []string // OpenBSD top-level database "lookup" order
}

func DNSReadConfig

func DNSReadConfig(rdr io.Reader, noDefaultNameservers bool) (*DNSConfig, error)

See resolv.conf(5) on a Linux machine. TODO(rsc): Supposed to call uname() and chop the beginning of the host name to get the default search domain. noDefaultNameservers indicates we should not emulate libc behaviour and include a localhost resolver.

func (*DNSConfig) String

func (d *DNSConfig) String() string

String returns resolv.conf serialized version of config

type HostEntry

type HostEntry struct {
	// Hostnames is a list of space separated hostnames
	Hostnames string
	// IP is the IP the hostnames should resolve to
	IP string
}

HostEntry maps a list of hostnames to an IP

Jump to

Keyboard shortcuts

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