utils

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Murmur3Partitioner = Partitioner{
	RingOffset: new(big.Int).Lsh(newBigInt(-1), 63),
	RingRange:  new(big.Int).Lsh(one, 64),
}
View Source
var RandomPartitioner = Partitioner{
	RingOffset: new(big.Int),
	RingRange:  new(big.Int).Lsh(one, 127),
}

Functions

func ComputeTokens added in v1.4.0

func ComputeTokens(dcCounts []int, partitioner Partitioner) [][]string

ComputeTokens takes a list of numbers indicating the number of nodes in each datacenter, and returns a recommended list of tokens for the given partitioner (one token per node, grouped by datacenter).

func ContainerHasEnvVar added in v1.6.0

func ContainerHasEnvVar(container *corev1.Container, name, value string) bool

func ContainsVolume added in v1.6.0

func ContainsVolume(volumes []corev1.Volume, name string) (int, bool)

func CopyFile added in v1.1.0

func CopyFile(src, dest string) error

CopyFile copies file src to file dest. File src must exist. File dest doesn't need to exist nor its parent directories, they will be created if required. Existing dest file will be overwritten.

func CopyFileToDir added in v1.1.0

func CopyFileToDir(src, destDir string) (string, error)

CopyFileToDir copies file src to directory destDir. File src must exist. Directory destDir doesn't need exist nor its parent directories, they will be created if required. The destination file will have the same name as src. If that file already exists, it will be overwritten.

func DeepHashObject added in v1.3.0

func DeepHashObject(hasher hash.Hash, objectToWrite interface{})

DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.

func DeepHashString

func DeepHashString(obj interface{}) string

func FindAndGetContainer added in v1.5.0

func FindAndGetContainer(deployment *appsv1.Deployment, name string) *corev1.Container

func FindAndGetVolume added in v1.5.0

func FindAndGetVolume(deployment *appsv1.Deployment, name string) *corev1.Volume

func FindContainer added in v1.5.0

func FindContainer(deployment *appsv1.Deployment, name string) (int, bool)

func FindEnvVar added in v1.2.0

func FindEnvVar(envVars []corev1.EnvVar, name string) *corev1.EnvVar

func FindEnvVarInContainer added in v1.2.0

func FindEnvVarInContainer(container *corev1.Container, name string) *corev1.EnvVar

func FindVolume added in v1.5.0

func FindVolume(deployment *appsv1.Deployment, name string) (int, bool)

func FindVolumeMount added in v1.5.0

func FindVolumeMount(container *corev1.Container, name string) *corev1.VolumeMount

func FirstNonEmptyString added in v1.4.0

func FirstNonEmptyString(strs ...string) string

FirstNonEmptyString returns the first non-empty string in the provided list of strings. If all strings are empty, an empty string is returned.

func GetEnvVarIndex added in v1.6.0

func GetEnvVarIndex(name string, envVars []corev1.EnvVar) int

func GetKey

func GetKey(obj metav1.Object) client.ObjectKey

func GetMapNested added in v1.1.0

func GetMapNested(m map[string]interface{}, key string, keys ...string) (interface{}, bool)

GetMapNested gets the value at the given keys in the given map. It returns nil and false if the map does not contain all the keys.

func ListFiles added in v1.1.0

func ListFiles(root, pattern string) ([]string, error)

ListFiles lists all files whose names match pattern in root directory and its subdirectories.

func MergeMap

func MergeMap(sources ...map[string]string) map[string]string

MergeMap will take two or more maps, merging the entries of the sources map into a destination map. If both maps share the same key then destination's value for that key will be overwritten with what's in source.

func MergeMapNested added in v1.1.0

func MergeMapNested(allowOverwrite bool, sources ...map[string]interface{}) (map[string]interface{}, error)

MergeMapNested will take two or more maps, merging the entries of the sources map into a destination map. If both maps share the same key then destination's value for that key will be merged with what's in source. The source maps are not modified. If allowOverwrite is false, an error is returned if the key already exists and its value is not nil.

func PutMapNested added in v1.1.0

func PutMapNested(allowOverwrite bool, m map[string]interface{}, val interface{}, key string, keys ...string) error

PutMapNested puts the given value in the given map at the given keys. When a key is not present, the entry is created on the fly; nested entries are always of type map[string]interface{} to allow for nested entries to be further inserted. If allowOverwrite is false, an error is returned if the key already exists and its value is not nil.

func ReadLines added in v1.1.0

func ReadLines(file string) ([]string, error)

ReadLines reads all lines in the given file.

func RemoveValue

func RemoveValue(slice []string, value string) []string

func SliceContains

func SliceContains(slice []string, s string) bool

func UnmarshalToMap

func UnmarshalToMap(data []byte) (map[string]interface{}, error)

Types

type Partitioner added in v1.4.0

type Partitioner struct {
	RingOffset *big.Int
	RingRange  *big.Int
}

Jump to

Keyboard shortcuts

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