util

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NameMaxLen is the maximum length for a kubernetes name.
	NameMaxLen = 63
)

Variables

This section is empty.

Functions

func AnyBoolTrue

func AnyBoolTrue(values ...bool) bool

AnyBoolTrue returns True if any of the provided bool values is True.

func BoolToPointer

func BoolToPointer(b bool) *bool

BoolToPointer returns a pointer to b.

func CreateCertificateAuthority

func CreateCertificateAuthority() *x509.Certificate

CreateCertificateAuthority generates a certificate authority x509.Certificate.

func CreateClientCertificate

func CreateClientCertificate(name string) *x509.Certificate

CreateClientCertificate generates a client x509.Certificate with the common name provided.

func CurrentNamespace

func CurrentNamespace() (string, error)

CurrentNamespace returns the current kubernetes namespace as read from the KUBE_NAMESPACE env var, or the serviceaccount/namespace file on the instance.

func GetEnvBoolOrDefault

func GetEnvBoolOrDefault(k string, d bool) bool

GetEnvBoolOrDefault returns true if the environment variable is set, or the default d if it is unset.

func GetEnvFloat64OrDefault

func GetEnvFloat64OrDefault(k string, d float64) float64

GetEnvFloat64OrDefault returns the value of the environment variable k as a float *or* the default d if casting fails or the environment variable is not set.

func GetEnvIntOrDefault

func GetEnvIntOrDefault(k string, d int) int

GetEnvIntOrDefault returns the value of the environment variable k as an int *or* the default d if casting fails or the environment variable is not set.

func GetEnvStrOrDefault

func GetEnvStrOrDefault(k, d string) string

GetEnvStrOrDefault returns the value of the environment variable k as a string *or* the default d if casting fails or the environment variable is not set.

func HashBytes

func HashBytes(b []byte) string

HashBytes accepts a bytes object and returns a string sha256 hash representing that object.

func Indent

func Indent(s string, n int) string

Indent indents all lines of a given string n spaces.

func Int32ToPointer

func Int32ToPointer(i int32) *int32

Int32ToPointer returns i as a pointer.

func Int64ToPointer

func Int64ToPointer(i int64) *int64

Int64ToPointer returns i as a pointer.

func MustCreateDirectory

func MustCreateDirectory(directory string, permissions fs.FileMode)

MustCreateDirectory creates a directory at path `directory` with provided permissions, it panics if an error is encountered.

func MustCurrentNamespace

func MustCurrentNamespace() string

MustCurrentNamespace returns the current kubernetes namespace or panics.

func MustFileExists

func MustFileExists(f string) bool

MustFileExists returns true if a given file exists, otherwise false, it panics if any error is encountered.

func MustGeneratePrivateKey

func MustGeneratePrivateKey(keySize int) *rsa.PrivateKey

MustGeneratePrivateKey generates a rsa private key of keySize or panics.

func MustNewManager

func MustNewManager(scheme *apimachineryruntime.Scheme) ctrlruntime.Manager

MustNewManager returns a new controller-runtime Manager or panics.

func MustSetupWithManager

func MustSetupWithManager(setup func(mgr ctrlruntime.Manager) error, mgr ctrlruntime.Manager)

MustSetupWithManager simply panics if registering a controller to the manager fails.

func Panic

func Panic(msg string)

Panic tries to panic "nicely" but will send a second sigint to really kill the process if the first does not succeed within a second, and if for some reason that one does not kill it, we try a sigkill, and finally if that still didn't work, we will simply panic outright.

func RandomString

func RandomString(length int) string

RandomString returns a string of random alphabet characters `length` long.

func RegexStringSubMatchToMap

func RegexStringSubMatchToMap(p *regexp.Regexp, s string) map[string]string

RegexStringSubMatchToMap accepts a regexp pattern and a string and returns a mapping of named capture groups to their found value. Obviously this only works with named capture groups.

func ResolveAtFileOrURL

func ResolveAtFileOrURL(path string) ([]byte, error)

ResolveAtFileOrURL returns the bytes from `path` where path is either a filepath or URL.

func SafeConcatNameKubernetes

func SafeConcatNameKubernetes(name ...string) string

SafeConcatNameKubernetes concats all provided strings into a string joined by "-" - if the final string is greater than 63 characters, the string will be shortened, and a hash will be used at the end of the string to keep it unique, but safely within allowed lengths.

func SafeConcatNameMax

func SafeConcatNameMax(name []string, max int) string

SafeConcatNameMax concats all provided strings into a string joined by "-" - if the final string is greater than max characters, the string will be shortened, and a hash will be used at the end of the string to keep it unique, but safely within allowed lengths.

func SignalHandledContext

func SignalHandledContext(logf func(f string, a ...interface{})) context.Context

SignalHandledContext returns a context that will be canceled if a SIGINT or SIGTERM is received.

func StringSliceContains

func StringSliceContains(ss []string, val string) bool

StringSliceContains returns true if the value val is in the string slice ss, otherwise false.

func StringSliceDifference

func StringSliceDifference(a, b []string) []string

StringSliceDifference returns the difference between a and b string slices. Items that exist in slice "b" but are missing in slice "a" will be returned.

func StringToPointer added in v0.0.7

func StringToPointer(s string) *string

StringToPointer returns a pointer to s.

Types

type CertData

type CertData struct {
	TLS []byte
	CRT []byte
	Key []byte
}

CertData is a struct that holds certificate information.

func GenerateCertificateData

func GenerateCertificateData(certBytes, caBytes []byte, key *rsa.PrivateKey) (*CertData, error)

GenerateCertificateData generates certificate data (ready to be written to disk) from the given cert/ca bytes and key.

func (*CertData) Write

func (c *CertData) Write(directory string) error

Write dumps the tls.crt, ca.crt, and tls.key data to disk in the given directory.

type StringSet

type StringSet interface {
	Add(s string)
	Extend(sSlice []string)
	Remove(s string)
	Contains(s string) bool
	Len() int
	Items() []string
}

StringSet defines a simple string set interface.

func NewStringSet

func NewStringSet() StringSet

NewStringSet returns an object satisfying the StringSet interface.

func NewStringSetWithValues

func NewStringSetWithValues(vals ...string) StringSet

NewStringSetWithValues returns an object satisfying the StringSet interface with the given values pre-loaded to the set.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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