Skip to content

Functions

Experimental functions

Experimental functions are denoted by the x_ prefix.

These are functions that are subject to signature change in a future version.

built-in functions

Name Description
abs Returns the absolute value of the provided argument.
avg Returns the average of the elements in the provided array. An empty array will produce a return value of null.
ceil Returns the next highest integer value by rounding up if necessary.
contains Returns true if the given subject contains the provided search value. If the subject is an array, this function returns true if one of the elements in the array is equal to the provided search value. If the provided subject is a string, this function returns true if the string contains the provided search argument.
ends_with Reports whether the given string ends with the provided suffix argument.
find_first Returns the zero-based index of the first occurence where the substring appears in a string or null if it does not appear.
find_last Returns the zero-based index of the last occurence where the substring appears in a string or null if it does not appear.
floor Returns the next lowest integer value by rounding down if necessary.
from_items Returns an object from the provided array of key value pairs. This function is the inversed of the items() function.
group_by Groups an array of objects using an expression as the group key.
items Converts a given object into an array of key-value pairs.
join Returns all of the elements from the provided array joined together using the glue argument as a separator between each.
keys Returns an array containing the keys of the provided object.
length Returns the length of the given argument. If the argument is a string this function returns the number of code points in the string. If the argument is an array this function returns the number of elements in the array. If the argument is an object this function returns the number of key-value pairs in the object.
lower Returns the given string with all Unicode letters mapped to their lower case.
map Transforms elements in a given array and returns the result.
max Returns the highest found element in the provided array argument. An empty array will produce a return value of null.
max_by Returns the highest found element using a custom expression to compute the associated value for each element in the input array.
merge Meges a list of objects together and returns the result.
min Returns the lowest found element in the provided array argument.
min_by Returns the lowest found element using a custom expression to compute the associated value for each element in the input array.
not_null Returns the first non null element in the input array.
pad_left Adds characters to the beginning of a string.
pad_right Adds characters to the end of a string.
replace Returns a copy of the input string with instances of old string argument replaced by new string argument.
reverse Reverses the input string or array and returns the result.
sort This function accepts an array argument and returns the sorted elements as an array.
sort_by This function accepts an array argument and returns the sorted elements as an array using a custom expression to compute the associated value for each element.
split Slices input string into substrings separated by a string argument and returns an array of the substrings between those separators.
starts_with Reports whether the input string begins with the provided string prefix argument.
sum Returns the sum of all numbers contained in the provided array.
to_array Returns a one element array containing the passed in argument, or the passed in value if it's an array.
to_number Returns the parsed number.
to_string The JSON encoded value of the given argument.
trim Removes the leading and trailing characters found in the passed in string argument.
trim_left Removes the leading characters found in the passed in string argument.
trim_right Removes the trailing characters found in the passed in string argument.
type Returns the JavaScript type of the given argument as a string value.
upper Returns the given string with all Unicode letters mapped to their upper case.
values Returns the values of the provided object.
zip Accepts one or more arrays as arguments and returns an array of arrays in which the i-th array contains the i-th element from each of the argument arrays. The returned array is truncated to the length of the shortest argument array.

kyverno-json functions

Name Description
at Returns the element in an array at the given index.
concat Concatenates two strings together and returns the result.
json_parse Parses a given JSON string into an object.
wildcard Compares a wildcard pattern with a given string and returns if they match or not.

kyverno functions

Name Description
compare Compares two strings lexicographically.
equal_fold Allows comparing two strings for equivalency where the only differences are letter cases.
replace Replaces a specified number of instances of the source string with the replacement string in a parent.
replace_all Replace all instances of one string with another in an overall parent string.
to_upper Takes in a string and outputs the same string with all upper-case letters.
to_lower Takes in a string and outputs the same string with all lower-case letters.
trim Trims both ends of the source string by characters appearing in the second string.
trim_prefix Trims the second string prefix from the first string if the first string starts with the prefix.
split Splits the first string when the second string is found and converts it into an array.
regex_replace_all Converts all parameters to string.
regex_replace_all_literal Converts all parameters to string.
regex_match First string is the regular exression which is compared with second input which can be a number or string.
pattern_match '*' matches zero or more alphanumeric characters, '?' matches a single alphanumeric character.
label_match Object arguments must be enclosed in backticks; ex. {{request.object.spec.template.metadata.labels}}.
to_boolean It returns true or false for any string, such as 'True', 'TruE', 'False', 'FAlse', 'faLSE', etc.
add Does arithmetic addition of two specified values of numbers, quantities, and durations.
sum Does arithmetic addition of specified array of values of numbers, quantities, and durations.
subtract Does arithmetic subtraction of two specified values of numbers, quantities, and durations.
multiply Does arithmetic multiplication of two specified values of numbers, quantities, and durations.
divide Divisor must be non zero.
modulo Divisor must be non-zero, arguments must be integers.
round Does roundoff to upto the given decimal places.
base64_decode Decodes a base 64 string.
base64_encode Encodes a regular, plaintext and unencoded string to base64.
time_since Calculate the difference between a start and end period of time where the end may either be a static definition or the then-current time.
time_now Returns current time in RFC 3339 format.
time_now_utc Returns current UTC time in RFC 3339 format.
path_canonicalize Normalizes or canonicalizes a given path by removing excess slashes.
truncate Length argument must be enclosed in backticks; ex. "{{request.object.metadata.name
semver_compare Compares two strings which comply with the semantic versioning schema and outputs a boolean response as to the position of the second relative to the first.
parse_json Decodes a valid JSON encoded string to the appropriate type. Opposite of to_string function.
parse_yaml Decodes a valid YAML encoded string to the appropriate type provided it can be represented as JSON.
lookup Returns the value corresponding to the given key/index in the given object/array.
items Converts a map or array to an array of objects where each key:value is an item in the array.
object_from_lists Converts a pair of lists containing keys and values to an object.
random Generates a random sequence of characters.
x509_decode Decodes an x.509 certificate to an object. you may also use this in conjunction with base64_decode jmespath function to decode a base64-encoded certificate.
time_to_cron Converts a time (RFC 3339) to a cron expression (string).
time_add Adds duration (second string) to a time value (first string).
time_parse Changes a time value of a given layout to RFC 3339.
time_utc Calcutes time in UTC from a given time in RFC 3339 format.
time_diff Calculate the difference between a start and end date in RFC3339 format.
time_before Checks if a time is before another time, both in RFC3339 format.
time_after Checks if a time is after another time, both in RFC3339 format.
time_between Checks if a time is between a start and end time, all in RFC3339 format.
time_truncate Returns the result of rounding time down to a multiple of duration.

chainsaw functions

Name Description
env Returns the value of the environment variable passed in argument.
x_k8s_get Gets a resource from a Kubernetes cluster.
x_k8s_list Lists resources from a Kubernetes cluster.
x_k8s_exists Checks if a given resource exists in a Kubernetes cluster.
x_k8s_resource_exists Checks if a given resource type is available in a Kubernetes cluster.
x_k8s_server_version Returns the version of a Kubernetes cluster.
x_metrics_decode Decodes metrics in the Prometheus text format.
trim_space Trims leading and trailing spaces from the string passed in argument.
as_string Returns the passed in argument converted into a string.