Skip to content

Configuration Paths

Functions name the fields of a resource by path, as in set-int-path, get-string-path and WhereResource, and many functions find the fields they act on in the Path Registry rather than taking a path at all. This page describes the path syntax and the registry.

Configuration path syntax

Resource paths sometimes need to be specified, such as in the set-*-path and get-*-path functions.

Configuration paths are dot-separated, including for array indices. For example: spec.template.spec.containers.0.image. Dots are escaped with ~1. (That syntax comes from the JSON Pointer RFC.)

The Kubernetes API and cloud APIs contain a number of associative lists, such as container lists and environment variable lists, where the keys identifying the array elements are map elements of the array element, such as name. The syntax for an associative list path matching is .?<map key>=<map value> in place of the array index, as in spec.template.spec.containers.?name=main.image.

Wildcards are also supported for array indices and/or map keys by some functions. For example, spec.template.spec.containers.*.image and metadata.annotations.confighub~1com/RevisionNum.

Getters and setters, attributes, and the path registry

To change a specific configuration value, you could use a function like set-int-path and specify the configuration path as a function argument, but if you operate on the same path(s) frequently, it can be worthwhile to define a function so that your users don't need to type or remember the paths and the associative matching syntax.

A number of functions, primarily those of type PathVisitor, work by registering the appropriate configuration paths of the relevant resource types for the values they operate on, using an approach similar to kustomize.

The Function Executor maintains a Path Registry that associates a set of paths and path metadata with a named Attribute used to identify that set of semantically related paths. Simple getter and setter functions like get-replicas and set-replicas operate on a single attribute, replicas in this case, which is reported by the function metadata displayed by cub function explain. There's a universal getter, get-attribute, which can be used to get values for an Attribute by name.

An Attribute entity registers paths, and getters and setters for them, of your own; its page has examples. Automate Validation, Changes, and Analysis with Functions describes finding and invoking functions.