Documentation
¶
Overview ¶
Package util provides general utilities. It is deprecated per https://github.com/crossplaneio/crossplane-runtime/issues/1
Index ¶
- Constants
- Variables
- func ConditionalStringFormat(format string, value string) string
- func GenerateHex(dataLen int) (string, error)
- func GeneratePassword(dataLen int) (string, error)
- func GetContainerImage(pod *v1.Pod, name string) (string, error)
- func GetMatchingContainer(containers []v1.Container, name string) (v1.Container, error)
- func GetRunningPod(ctx context.Context, kube client.Client) (*v1.Pod, error)
- func GetSpecContainerImage(spec v1.PodSpec, name string, initContainer bool) (string, error)
- func ParseBool(s string) bool
- func ParseMap(s string) map[string]string
- func Split(s, sep string) []string
- func String(v string) *string
- func StringValue(v *string) string
- func ToLowerRemoveSpaces(input string) string
Constants ¶
const ( // PodNameEnvVar is the env variable for getting the pod name via downward api PodNameEnvVar = "POD_NAME" // PodNamespaceEnvVar is the env variable for getting the pod namespace via downward api PodNamespaceEnvVar = "POD_NAMESPACE" )
Variables ¶
var DefaultUpdateRetry = wait.Backoff{ Steps: 10, Duration: 500 * time.Millisecond, Factor: 1.0, Jitter: 0.1, }
DefaultUpdateRetry is the recommended retry for a failure to update a resource or ensuring that the changes from an update have been committed and have become consistent.
Functions ¶
func ConditionalStringFormat ¶
ConditionalStringFormat returns based on the format string and substitution value. If format is not provided, substitution value is returned If format is provided with '%s' substitution symbol, fmt.Sprintf(fmt, val) is returned.
NOTE: only single %s substitution is supported
If name format does not contain '%s' substitution, i.e. a constant string, the constant string value is returned back
Examples:
For all examples assume "value" = "test-value" 1. format = "", ContainerName = "test-value" 2. format = "foo", ContainerName = "foo" 3. format = "foo-%s", ContainerName = "foo-test-value" 4. format = "foo-%s-bar-%s", ContainerName = "foo-test-value-bar-%!s(MISSING)"
func GenerateHex ¶
GenerateHex generates a hex string using random data of the given length.
func GeneratePassword ¶
GeneratePassword generates a password using random data of the given length, then encodes to a base64 string.
func GetContainerImage ¶
GetContainerImage will get the container image for the container with the given name in the given pod.
func GetMatchingContainer ¶
GetMatchingContainer returns the container from the given set of containers that matches the given name. If the given container list has only 1 item then the name field is ignored and that container is returned.
func GetRunningPod ¶
GetRunningPod will get the pod object for the currently running pod. This assumes that the downward API has been used to inject the pod name and namespace as env vars.
func GetSpecContainerImage ¶
GetSpecContainerImage will get the container image for the container with the given name in the given pod spec.
func ParseMap ¶
ParseMap string encoded map values example: "foo:bar,one:two" -> map[string]string{"foo":"bar","one":"two"}
func Split ¶
Split function helper will return an empty slice on empty string and removing empty entries and trimming leading and trailing spaces Example: Split("a ,, b") results in []string{"a","b"}
func StringValue ¶
StringValue returns the value of the string pointer passed in or "" if the pointer is nil.
func ToLowerRemoveSpaces ¶
ToLowerRemoveSpaces returns the supplied string in lowercase with all spaces (not all whitespace) removed.
Types ¶
This section is empty.