// MakeNullNode returns an RNode that represents an empty document. func MakeNullNode() *RNode { … } // MakePersistentNullNode returns an RNode that should be persisted, // even when merging func MakePersistentNullNode(value string) *RNode { … } // IsMissingOrNull is true if the RNode is nil or explicitly tagged null. // TODO: make this a method on RNode. func IsMissingOrNull(node *RNode) bool { … } // IsEmptyMap returns true if the RNode is an empty node or an empty map. // TODO: make this a method on RNode. func IsEmptyMap(node *RNode) bool { … } // GetValue returns underlying yaml.Node Value field func GetValue(node *RNode) string { … } // Parse parses a yaml string into an *RNode. // To parse multiple resources, consider a kio.ByteReader func Parse(value string) (*RNode, error) { … } // ReadFile parses a single Resource from a yaml file. // To parse multiple resources, consider a kio.ByteReader func ReadFile(path string) (*RNode, error) { … } // WriteFile writes a single Resource to a yaml file func WriteFile(node *RNode, path string) error { … } // UpdateFile reads the file at path, applies the filter to it, and write the result back. // path must contain a exactly 1 resource (YAML). func UpdateFile(filter Filter, path string) error { … } // MustParse parses a yaml string into an *RNode and panics if there is an error func MustParse(value string) *RNode { … } // NewScalarRNode returns a new Scalar *RNode containing the provided scalar value. func NewScalarRNode(value string) *RNode { … } // NewStringRNode returns a new Scalar *RNode containing the provided string. // If the string is non-utf8, it will be base64 encoded, and the tag // will indicate binary data. func NewStringRNode(value string) *RNode { … } // NewListRNode returns a new List *RNode containing the provided scalar values. func NewListRNode(values ...string) *RNode { … } // NewMapRNode returns a new Map *RNode containing the provided values func NewMapRNode(values *map[string]string) *RNode { … } // SyncMapNodesOrder sorts the map node keys in 'to' node to match the order of // map node keys in 'from' node, additional keys are moved to the end func SyncMapNodesOrder(from, to *RNode) { … } // NewRNode returns a new RNode pointer containing the provided Node. func NewRNode(value *yaml.Node) *RNode { … } type RNode … // Copy returns a distinct copy. func (rn *RNode) Copy() *RNode { … } var ErrMissingMetadata … // IsNil is true if the node is nil, or its underlying YNode is nil. func (rn *RNode) IsNil() bool { … } // IsTaggedNull is true if a non-nil node is explicitly tagged Null. func (rn *RNode) IsTaggedNull() bool { … } // IsNilOrEmpty is true if the node is nil, // has no YNode, or has YNode that appears empty. func (rn *RNode) IsNilOrEmpty() bool { … } // IsStringValue is true if the RNode is not nil and is scalar string node func (rn *RNode) IsStringValue() bool { … } // GetMeta returns the ResourceMeta for an RNode func (rn *RNode) GetMeta() (ResourceMeta, error) { … } // Pipe sequentially invokes each Filter, and passes the result to the next // Filter. // // Analogous to http://www.linfo.org/pipes.html // // * rn is provided as input to the first Filter. // * if any Filter returns an error, immediately return the error // * if any Filter returns a nil RNode, immediately return nil, nil // * if all Filters succeed with non-empty results, return the final result func (rn *RNode) Pipe(functions ...Filter) (*RNode, error) { … } // PipeE runs Pipe, dropping the *RNode return value. // Useful for directly returning the Pipe error value from functions. func (rn *RNode) PipeE(functions ...Filter) error { … } // Document returns the Node for the value. func (rn *RNode) Document() *yaml.Node { … } // YNode returns the yaml.Node value. If the yaml.Node value is a DocumentNode, // YNode will return the DocumentNode Content entry instead of the DocumentNode. func (rn *RNode) YNode() *yaml.Node { … } // SetYNode sets the yaml.Node value on an RNode. func (rn *RNode) SetYNode(node *yaml.Node) { … } // GetKind returns the kind, if it exists, else empty string. func (rn *RNode) GetKind() string { … } // SetKind sets the kind. func (rn *RNode) SetKind(k string) { … } // GetApiVersion returns the apiversion, if it exists, else empty string. func (rn *RNode) GetApiVersion() string { … } // SetApiVersion sets the apiVersion. func (rn *RNode) SetApiVersion(av string) { … } // getMapFieldValue returns the value (*yaml.Node) of a mapping field. // The value might be nil. Also, the function returns nil, not an error, // if this node is not a mapping node, or if this node does not have the // given field, so this function cannot be used to make distinctions // between these cases. func (rn *RNode) getMapFieldValue(field string) *yaml.Node { … } // GetName returns the name, or empty string if // field not found. The setter is more restrictive. func (rn *RNode) GetName() string { … } // getMetaStringField returns the value of a string field in metadata. func (rn *RNode) getMetaStringField(fName string) string { … } // getMetaData returns the *yaml.Node of the metadata field. // Return nil if field not found (no error). func (rn *RNode) getMetaData() *yaml.Node { … } // SetName sets the metadata name field. func (rn *RNode) SetName(name string) error { … } // GetNamespace gets the metadata namespace field, or empty string if // field not found. The setter is more restrictive. func (rn *RNode) GetNamespace() string { … } // SetNamespace tries to set the metadata namespace field. If the argument // is empty, the field is dropped. func (rn *RNode) SetNamespace(ns string) error { … } // GetAnnotations gets the metadata annotations field. // If the annotations field is missing, returns an empty map. // Use another method to check for missing metadata. // If specific annotations are provided, then the map is // restricted to only those entries with keys that match // one of the specific annotations. If no annotations are // provided, then the map will contain all entries. func (rn *RNode) GetAnnotations(annotations ...string) map[string]string { … } // SetAnnotations tries to set the metadata annotations field. func (rn *RNode) SetAnnotations(m map[string]string) error { … } // GetLabels gets the metadata labels field. // If the labels field is missing, returns an empty map. // Use another method to check for missing metadata. // If specific labels are provided, then the map is // restricted to only those entries with keys that match // one of the specific labels. If no labels are // provided, then the map will contain all entries. func (rn *RNode) GetLabels(labels ...string) map[string]string { … } // getMapFromMeta returns a map, sometimes empty, from the fName // field in the node's metadata field. // If specific fields are provided, then the map is // restricted to only those entries with keys that match // one of the specific fields. If no fields are // provided, then the map will contain all entries. func (rn *RNode) getMapFromMeta(fName string, fields ...string) map[string]string { … } // SetLabels sets the metadata labels field. func (rn *RNode) SetLabels(m map[string]string) error { … } // This established proper quoting on string values, and sorts by key. func (rn *RNode) setMapInMetadata(m map[string]string, field string) error { … } func (rn *RNode) SetMapField(value *RNode, path ...string) error { … } func (rn *RNode) GetDataMap() map[string]string { … } func (rn *RNode) GetBinaryDataMap() map[string]string { … } // GetValidatedDataMap retrieves the data map and returns an error if the data // map contains entries which are not included in the expectedKeys set. func (rn *RNode) GetValidatedDataMap(expectedKeys []string) (map[string]string, error) { … } func (rn *RNode) validateDataMap(dataMap map[string]string, expectedKeys []string) error { … } func (rn *RNode) SetDataMap(m map[string]string) { … } func (rn *RNode) SetBinaryDataMap(m map[string]string) { … } // AppendToFieldPath appends a field name to the FieldPath. func (rn *RNode) AppendToFieldPath(parts ...string) { … } // FieldPath returns the field path from the Resource root node, to rn. // Does not include list indexes. func (rn *RNode) FieldPath() []string { … } // String returns string representation of the RNode func (rn *RNode) String() (string, error) { … } // MustString returns string representation of the RNode or panics if there is an error func (rn *RNode) MustString() string { … } // Content returns Node Content field. func (rn *RNode) Content() []*yaml.Node { … } // Fields returns the list of field names for a MappingNode. // Returns an error for non-MappingNodes. func (rn *RNode) Fields() ([]string, error) { … } // FieldRNodes returns the list of field key RNodes for a MappingNode. // Returns an error for non-MappingNodes. func (rn *RNode) FieldRNodes() ([]*RNode, error) { … } // Field returns a fieldName, fieldValue pair for MappingNodes. // Returns nil for non-MappingNodes. func (rn *RNode) Field(field string) *MapNode { … } // VisitFields calls fn for each field in the RNode. // Returns an error for non-MappingNodes. func (rn *RNode) VisitFields(fn func(node *MapNode) error) error { … } // visitMappingNodeFields calls fn for fields in the content, in content order. // The caller is responsible to ensure the node is a mapping node. If fieldNames // are specified, then fn is called only for the fields that match the given // fieldNames. func visitMappingNodeFields(content []*yaml.Node, fn func(key, value *yaml.Node), fieldNames ...string) { … } // visitFieldsWhileTrue calls fn for the fields in content, in content order, // until either fn returns false or all fields have been visited. The caller // should ensure that content is from a mapping node, or fits the same expected // pattern (consecutive key/value entries in the slice). func visitFieldsWhileTrue(content []*yaml.Node, fn func(key, value *yaml.Node, keyIndex int) bool) { … } // Elements returns the list of elements in the RNode. // Returns an error for non-SequenceNodes. func (rn *RNode) Elements() ([]*RNode, error) { … } // ElementValues returns a list of all observed values for a given field name // in a list of elements. // Returns error for non-SequenceNodes. func (rn *RNode) ElementValues(key string) ([]string, error) { … } // ElementValuesList returns a list of lists, where each list is a set of // values corresponding to each key in keys. // Returns error for non-SequenceNodes. func (rn *RNode) ElementValuesList(keys []string) ([][]string, error) { … } // Element returns the element in the list which contains the field matching the value. // Returns nil for non-SequenceNodes or if no Element matches. func (rn *RNode) Element(key, value string) *RNode { … } // ElementList returns the element in the list in which all fields keys[i] matches all // corresponding values[i]. // Returns nil for non-SequenceNodes or if no Element matches. func (rn *RNode) ElementList(keys []string, values []string) *RNode { … } // VisitElements calls fn for each element in a SequenceNode. // Returns an error for non-SequenceNodes func (rn *RNode) VisitElements(fn func(node *RNode) error) error { … } var AssociativeSequenceKeys … // IsAssociative returns true if the RNode contains an AssociativeSequenceKey as a field. func (rn *RNode) IsAssociative() bool { … } // GetAssociativeKey returns the AssociativeSequenceKey used to merge the elements in the // SequenceNode, or "" if the list is not associative. func (rn *RNode) GetAssociativeKey() string { … } // MarshalJSON creates a byte slice from the RNode. func (rn *RNode) MarshalJSON() ([]byte, error) { … } // UnmarshalJSON overwrites this RNode with data from []byte. func (rn *RNode) UnmarshalJSON(b []byte) error { … } // DeAnchor inflates all YAML aliases with their anchor values. // All YAML anchor data is permanently removed (feel free to call Copy first). func (rn *RNode) DeAnchor() (err error) { … } // deAnchor removes all AliasNodes from the yaml.Node's tree, replacing // them with what they point to. All Anchor fields (these are used to mark // anchor definitions) are cleared. func deAnchor(yn *yaml.Node) (res *yaml.Node, err error) { … } // isMerge returns if the node is tagged with !!merge func isMerge(yn *yaml.Node) bool { … } // findMergeValues receives either a MappingNode, a AliasNode or a potentially // mixed list of MappingNodes and AliasNodes. It returns a list of MappingNodes. func findMergeValues(yn *yaml.Node) ([]*yaml.Node, error) { … } // getMergeTagValue receives a MappingNode yaml node, and it searches for // merge tagged keys and return its value yaml node. If the key is duplicated, // it fails. func getMergeTagValue(yn *yaml.Node) (*yaml.Node, error) { … } // removeMergeTags removes all merge tags and returns a ordered list of yaml // nodes to merge and a error func removeMergeTags(yn *yaml.Node) ([]*yaml.Node, error) { … } func mergeAll(yn *yaml.Node, toMerge []*yaml.Node) error { … } // GetValidatedMetadata returns metadata after subjecting it to some tests. func (rn *RNode) GetValidatedMetadata() (ResourceMeta, error) { … } // MatchesAnnotationSelector returns true on a selector match to annotations. func (rn *RNode) MatchesAnnotationSelector(selector string) (bool, error) { … } // MatchesLabelSelector returns true on a selector match to labels. func (rn *RNode) MatchesLabelSelector(selector string) (bool, error) { … } // HasNilEntryInList returns true if the RNode contains a list which has // a nil item, along with the path to the missing item. // TODO(broken): This doesn't do what it claims to do. // (see TODO in unit test and pr 1513). func (rn *RNode) HasNilEntryInList() (bool, string) { … } func hasNilEntryInList(in interface{ … } func FromMap(m map[string]interface{ … } func (rn *RNode) Map() (map[string]interface{ … } // ConvertJSONToYamlNode parses input json string and returns equivalent yaml node func ConvertJSONToYamlNode(jsonStr string) (*RNode, error) { … } // checkKey returns true if all elems have the key func checkKey(key string, elems []*Node) bool { … } // GetSlice returns the contents of the slice field at the given path. func (rn *RNode) GetSlice(path string) ([]interface{ … } // GetString returns the contents of the string field at the given path. func (rn *RNode) GetString(path string) (string, error) { … } // GetFieldValue finds period delimited fields. // TODO: When doing kustomize var replacement, which is likely a // a primary use of this function and the reason it returns interface{} // rather than string, we do conversion from Nodes to Go types and back // to nodes. We should figure out how to do replacement using raw nodes, // assuming we keep the var feature in kustomize. // The other end of this is: refvar.go:updateNodeValue. func (rn *RNode) GetFieldValue(path string) (interface{ … } // convertSliceIndex traverses the items in `fields` and find // if there is a slice index in the item and change it to a // valid Lookup field path. For example, 'ports[0]' will be // converted to 'ports' and '0'. func convertSliceIndex(fields []string) []string { … } type NoFieldError … func (e NoFieldError) Error() string { … }