Documentation ¶
Overview ¶
Package fieldpath provides utilities for working with field paths.
Field paths reference a field within a Kubernetes object via a simple string. API conventions describe the syntax as "standard JavaScript syntax for accessing that field, assuming the JSON object was transformed into a JavaScript object, without the leading dot, such as metadata.name".
Valid examples:
* metadata.name * spec.containers[0].name * data[.config.yml] * metadata.annotations['crossplane.io/external-name'] * spec.items[0][8] * apiVersion * [42]
Invalid examples:
* .metadata.name - Leading period. * metadata..name - Double period. * metadata.name. - Trailing period. * spec.containers[] - Empty brackets. * spec.containers.[0].name - Period before open bracket.
Index ¶
- func IsNotFound(err error) bool
- type Paved
- func (p *Paved) DeleteField(path string) error
- func (p *Paved) ExpandWildcards(path string) ([]string, error)
- func (p *Paved) GetBool(path string) (bool, error)
- func (p *Paved) GetInteger(path string) (int64, error)
- func (p *Paved) GetNumber(path string) (float64, error)
- func (p *Paved) GetString(path string) (string, error)
- func (p *Paved) GetStringArray(path string) ([]string, error)
- func (p *Paved) GetStringObject(path string) (map[string]string, error)
- func (p *Paved) GetValue(path string) (any, error)
- func (p *Paved) GetValueInto(path string, out any) error
- func (p Paved) MarshalJSON() ([]byte, error)
- func (p *Paved) MergeValue(path string, value any, mo *xpv1.MergeOptions) error
- func (p *Paved) SetBool(path string, value bool) error
- func (p *Paved) SetNumber(path string, value float64) error
- func (p *Paved) SetString(path, value string) error
- func (p *Paved) SetUnstructuredContent(content map[string]any)
- func (p *Paved) SetValue(path string, value any) error
- func (p *Paved) UnmarshalJSON(data []byte) error
- func (p *Paved) UnstructuredContent() map[string]any
- type Segment
- type SegmentType
- type Segments
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶ added in v0.8.0
IsNotFound returns true if the supplied error indicates a field path was not found, for example because a field did not exist within an object or an index was out of bounds in an array.
Types ¶
type Paved ¶
type Paved struct {
// contains filtered or unexported fields
}
A Paved JSON object supports getting and setting values by their field path.
func PaveObject ¶ added in v0.8.0
PaveObject paves a runtime.Object, making it possible to get and set values by field path. o must be a non-nil pointer to an object.
func (*Paved) DeleteField ¶ added in v0.18.0
DeleteField deletes the field from the object. If the path points to an entry in an array, the element on that index is removed and the next ones are pulled back. If it is a field on a map, the field is removed from the map.
func (*Paved) ExpandWildcards ¶ added in v0.16.0
ExpandWildcards expands wildcards for a given field path. It returns an array of field paths with expanded values. Please note that expanded paths depend on the input data which is paved.object.
Example:
For a Paved object with the following data: []byte(`{"spec":{"containers":[{"name":"cool", "image": "latest", "args": ["start", "now", "debug"]}]}}`), ExpandWildcards("spec.containers[*].args[*]") returns: []string{"spec.containers[0].args[0]", "spec.containers[0].args[1]", "spec.containers[0].args[2]"},
func (*Paved) GetInteger ¶ added in v0.10.0
GetInteger value of the supplied field path.
func (*Paved) GetNumber ¶
GetNumber value of the supplied field path. Deprecated: Use of float64 is discouraged. Please use GetInteger. See https://github.com/kubernetes/community/blob/c9ae475/contributors/devel/sig-architecture/api-conventions.md#primitive-types
func (*Paved) GetStringArray ¶
GetStringArray value of the supplied field path.
func (*Paved) GetStringObject ¶
GetStringObject value of the supplied field path.
func (*Paved) GetValueInto ¶ added in v0.8.0
GetValueInto the supplied type.
func (Paved) MarshalJSON ¶
MarshalJSON to the underlying object.
func (*Paved) MergeValue ¶ added in v0.15.0
MergeValue of the receiver p at the specified field path with the supplied value according to supplied merge options
func (*Paved) SetUnstructuredContent ¶
SetUnstructuredContent sets the JSON serialisable content of this Paved.
func (*Paved) UnmarshalJSON ¶
UnmarshalJSON from the underlying object.
func (*Paved) UnstructuredContent ¶
UnstructuredContent returns the JSON serialisable content of this Paved.
type Segment ¶
type Segment struct { Type SegmentType Field string Index uint }
A Segment of a field path.
func Field ¶
Field produces a new segment from the supplied string. The segment is always considered to be an object field name.
func FieldOrIndex ¶
FieldOrIndex produces a new segment from the supplied string. The segment is considered to be an array index if the string can be interpreted as an unsigned 32 bit integer. Anything else is interpreted as an object field name.
type SegmentType ¶
type SegmentType int
A SegmentType within a field path; either a field within an object, or an index within an array.
const ( SegmentField SegmentType SegmentIndex )
Segment types.