The following template functions are available, with some functions having aliases for convenience:
Converts the value to string as stated in String conversion, then lowercases it.
Converts the value to string as stated in String conversion, then uppercases it.
Converts the value to string as stated in String conversion, then capitalize the first character of each word.
While available, it's use is discouraged for file names.
Alias of Go's fmt.Sprintf
.
Converts the value to string as stated in String conversion, then removes any whitespace at the beginning or end of the string.
Converts the value to string as stated in String conversion, then removes either the prefix or the suffix.
Do note that the parameters are flipped from Go's strings.TrimPrefix
and strings.TrimSuffix
: here, the first parameter is the prefix, rather than being the last parameter. This is to allow piping one output to another:
If the value is set, return it, otherwise, a default value is used.
If the argument renders to an empty string, the application fails and exits with non-zero status code.
Fetch an environment variable to be printed. If the environment variable is mandatory, consider using required
. If the environment variable might be empty, consider using default
.
env
allows the key to be case-insensitive: it will be uppercased internally.
Renders a sha1sum
or sha256sum
of a given value. The value is converted first to their YAML representation, with comments removed, then the sum
is performed. This is to ensure that the "behavior" can stay the same, even when the file might have multiple comments that might change.
Primitives such as string
, bool
and float64
are converted as-is.
While not recommended, you can use this to always generate a new name if the YAML declaration drifts. The following snippet uses .
, which represents the entire YAML file -- on a multi-YAML file, each .
represents a single file:
Converts any primitive as stated in String conversion, to string:
Converts the value to a string as stated in String conversion, then replaces all ocurrences of a string with another:
Converts the value to a string as stated in String conversion, and keeps from the original string only alphanumeric characters -- for alphanumify
-- or alphanumeric plus dashes and underscores -- like URLs, for alphanumdash
:
Converts the value to a string as stated in String conversion, and replaces all dots to either dashes or underscores:
Particularly useful for Kubernetes FQDNs needed to be used as filenames.
For certain resources where YAML indexes are not alphanumeric, but contain special characters such as labels or annotations, index
allows you to retrieve those resources. Consider the following YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
labels:
app.kubernetes.io/name: patrickdap-deployment
It's not possible to access the value patrickdap-deployment
using dot notation like this: {{ .metadata.labels.app.kubernetes.io/name }}
: the Go Template engine will throw an error. Instead, you can use index
:
The reason the parameters are flipped is to allow piping one output to another: