const ( ResourceListKind = "ResourceList" ResourceListAPIVersion = "config.kubernetes.io/v1" )
var DefaultMatch = []string{"*.yaml", "*.yml"}
var GraphStructures = []string{string(TreeStructureGraph), string(TreeStructurePackage)}
var JSONMatch = []string{"*.json"}
var MatchAll = append(DefaultMatch, JSONMatch...)
func FromBytes(bs []byte) ([]*yaml.RNode, error)
FromBytes reads from a byte slice.
func ParseAll(inputs ...string) ([]*yaml.RNode, error)
ParseAll reads all of the inputs into resources
func PreprocessResourcesForInternalAnnotationMigration(result []*yaml.RNode) (map[string]map[string]string, error)
PreprocessResourcesForInternalAnnotationMigration returns a mapping from id to all internal annotations, so that we can use it to reconcile the annotations later. This is necessary because currently both internal-prefixed annotations and legacy annotations are currently supported, and a change to one must be reflected in the other if needed.
func ReconcileInternalAnnotations(result []*yaml.RNode, nodeAnnosMap map[string]map[string]string) error
ReconcileInternalAnnotations reconciles the annotation format for path, index and id annotations. It will ensure the output annotation format matches the format in the input. e.g. if the input format uses the legacy format and the output will be converted to the legacy format if it's not.
func StringAll(resources []*yaml.RNode) (string, error)
StringAll writes all of the resources to a string
ByteReadWriter reads from an input and writes to an output.
type ByteReadWriter struct { // Reader is where ResourceNodes are decoded from. Reader io.Reader // Writer is where ResourceNodes are encoded. Writer io.Writer // OmitReaderAnnotations will configures Read to skip setting the config.kubernetes.io/index // annotation on Resources as they are Read. OmitReaderAnnotations bool // KeepReaderAnnotations if set will keep the Reader specific annotations when writing // the Resources, otherwise they will be cleared. KeepReaderAnnotations bool // PreserveSeqIndent if true adds kioutil.SeqIndentAnnotation to each resource PreserveSeqIndent bool // Style is a style that is set on the Resource Node Document. Style yaml.Style // WrapBareSeqNode wraps the bare sequence node document with map node, // kyaml uses reader annotations to track resources, it is not possible to // add them to bare sequence nodes, this option enables wrapping such bare // sequence nodes into map node with key yaml.BareSeqNodeWrappingKey // note that this wrapping is different and not related to ResourceList wrapping WrapBareSeqNode bool FunctionConfig *yaml.RNode Results *yaml.RNode NoWrap bool WrappingAPIVersion string WrappingKind string }
func (rw *ByteReadWriter) Read() ([]*yaml.RNode, error)
func (rw *ByteReadWriter) Write(nodes []*yaml.RNode) error
ByteReader decodes ResourceNodes from bytes. By default, Read will set the config.kubernetes.io/index annotation on each RNode as it is read so they can be written back in the same order.
type ByteReader struct { // Reader is where ResourceNodes are decoded from. Reader io.Reader // OmitReaderAnnotations will configures Read to skip setting the config.kubernetes.io/index // and internal.config.kubernetes.io/seqindent annotations on Resources as they are Read. OmitReaderAnnotations bool // PreserveSeqIndent if true adds kioutil.SeqIndentAnnotation to each resource PreserveSeqIndent bool // SetAnnotations is a map of caller specified annotations to set on resources as they are read // These are independent of the annotations controlled by OmitReaderAnnotations SetAnnotations map[string]string FunctionConfig *yaml.RNode Results *yaml.RNode // DisableUnwrapping prevents Resources in Lists and ResourceLists from being unwrapped DisableUnwrapping bool // WrappingAPIVersion is set by Read(), and is the apiVersion of the object that // the read objects were originally wrapped in. WrappingAPIVersion string // WrappingKind is set by Read(), and is the kind of the object that // the read objects were originally wrapped in. WrappingKind string // WrapBareSeqNode wraps the bare sequence node document with map node, // kyaml uses reader annotations to track resources, it is not possible to // add them to bare sequence nodes, this option enables wrapping such bare // sequence nodes into map node with key yaml.BareSeqNodeWrappingKey // note that this wrapping is different and not related to ResourceList wrapping WrapBareSeqNode bool // AnchorsAweigh set to true attempts to replace all YAML anchor aliases // with their definitions (anchor values) immediately after the read. AnchorsAweigh bool }
func (r *ByteReader) Read() ([]*yaml.RNode, error)
ByteWriter writes ResourceNodes to bytes. Generally YAML encoding will be used but in the special case of writing a single, bare yaml.RNode that has a kioutil.PathAnnotation indicating that the target is a JSON file JSON encoding is used. See shouldJSONEncodeSingleBareNode below for more information.
type ByteWriter struct { // Writer is where ResourceNodes are encoded. Writer io.Writer // KeepReaderAnnotations if set will keep the Reader specific annotations when writing // the Resources, otherwise they will be cleared. KeepReaderAnnotations bool // ClearAnnotations is a list of annotations to clear when writing the Resources. ClearAnnotations []string // Style is a style that is set on the Resource Node Document. Style yaml.Style // FunctionConfig is the function config for an ResourceList. If non-nil // wrap the results in an ResourceList. FunctionConfig *yaml.RNode Results *yaml.RNode // WrappingKind if set will cause ByteWriter to wrap the Resources in // an 'items' field in this kind. e.g. if WrappingKind is 'List', // ByteWriter will wrap the Resources in a List .items field. WrappingKind string // WrappingAPIVersion is the apiVersion for WrappingKind WrappingAPIVersion string // Sort if set, will cause ByteWriter to sort the nodes before writing them. Sort bool }
func (w ByteWriter) Write(inputNodes []*yaml.RNode) error
Filter modifies a collection of Resource Configuration by returning the modified slice. When possible, Filters should be serializable to yaml so that they can be described as either data or code.
Analogous to http://www.linfo.org/filters.html
type Filter interface { Filter([]*yaml.RNode) ([]*yaml.RNode, error) }
func FilterAll(filter yaml.Filter) Filter
FilterAll runs the yaml.Filter against all inputs
FilterFunc implements a Filter as a function.
type FilterFunc func([]*yaml.RNode) ([]*yaml.RNode, error)
func (fn FilterFunc) Filter(o []*yaml.RNode) ([]*yaml.RNode, error)
LocalPackageReadWriter reads and writes Resources from / to a local directory. When writing, LocalPackageReadWriter will delete files if all of the Resources from that file have been removed from the output.
type LocalPackageReadWriter struct { Kind string `yaml:"kind,omitempty"` KeepReaderAnnotations bool `yaml:"keepReaderAnnotations,omitempty"` // PreserveSeqIndent if true adds kioutil.SeqIndentAnnotation to each resource PreserveSeqIndent bool // PackagePath is the path to the package directory. PackagePath string `yaml:"path,omitempty"` // PackageFileName is the name of file containing package metadata. // It will be used to identify package. PackageFileName string `yaml:"packageFileName,omitempty"` // MatchFilesGlob configures Read to only read Resources from files matching any of the // provided patterns. // Defaults to ["*.yaml", "*.yml"] if empty. To match all files specify ["*"]. MatchFilesGlob []string `yaml:"matchFilesGlob,omitempty"` // IncludeSubpackages will configure Read to read Resources from subpackages. // Subpackages are identified by presence of PackageFileName. IncludeSubpackages bool `yaml:"includeSubpackages,omitempty"` // ErrorIfNonResources will configure Read to throw an error if yaml missing missing // apiVersion or kind is read. ErrorIfNonResources bool `yaml:"errorIfNonResources,omitempty"` // OmitReaderAnnotations will cause the reader to skip annotating Resources with the file // path and mode. OmitReaderAnnotations bool `yaml:"omitReaderAnnotations,omitempty"` // SetAnnotations are annotations to set on the Resources as they are read. SetAnnotations map[string]string `yaml:"setAnnotations,omitempty"` // NoDeleteFiles if set to true, LocalPackageReadWriter won't delete any files NoDeleteFiles bool `yaml:"noDeleteFiles,omitempty"` // FileSkipFunc is a function which returns true if reader should ignore // the file FileSkipFunc LocalPackageSkipFileFunc // FileSystem can be used to mock the disk file system. FileSystem filesys.FileSystemOrOnDisk // WrapBareSeqNode wraps the bare sequence node document with map node, // kyaml uses reader annotations to track resources, it is not possible to // add them to bare sequence nodes, this option enables wrapping such bare // sequence nodes into map node with key yaml.BareSeqNodeWrappingKey // note that this wrapping is different and not related to ResourceList wrapping WrapBareSeqNode bool // contains filtered or unexported fields }
func (r *LocalPackageReadWriter) Read() ([]*yaml.RNode, error)
func (r *LocalPackageReadWriter) Write(nodes []*yaml.RNode) error
LocalPackageReader reads ResourceNodes from a local package.
type LocalPackageReader struct { Kind string `yaml:"kind,omitempty"` // PackagePath is the path to the package directory. PackagePath string `yaml:"path,omitempty"` // PackageFileName is the name of file containing package metadata. // It will be used to identify package. PackageFileName string `yaml:"packageFileName,omitempty"` // MatchFilesGlob configures Read to only read Resources from files matching any of the // provided patterns. // Defaults to ["*.yaml", "*.yml"] if empty. To match all files specify ["*"]. MatchFilesGlob []string `yaml:"matchFilesGlob,omitempty"` // IncludeSubpackages will configure Read to read Resources from subpackages. // Subpackages are identified by presence of PackageFileName. IncludeSubpackages bool `yaml:"includeSubpackages,omitempty"` // ErrorIfNonResources will configure Read to throw an error if yaml missing missing // apiVersion or kind is read. ErrorIfNonResources bool `yaml:"errorIfNonResources,omitempty"` // OmitReaderAnnotations will cause the reader to skip annotating Resources with the file // path and mode. OmitReaderAnnotations bool `yaml:"omitReaderAnnotations,omitempty"` // SetAnnotations are annotations to set on the Resources as they are read. SetAnnotations map[string]string `yaml:"setAnnotations,omitempty"` // FileSkipFunc is a function which returns true if reader should ignore // the file FileSkipFunc LocalPackageSkipFileFunc // PreserveSeqIndent if true adds kioutil.SeqIndentAnnotation to each resource PreserveSeqIndent bool // FileSystem can be used to mock the disk file system. FileSystem filesys.FileSystemOrOnDisk // WrapBareSeqNode wraps the bare sequence node document with map node, // kyaml uses reader annotations to track resources, it is not possible to // add them to bare sequence nodes, this option enables wrapping such bare // sequence nodes into map node with key yaml.BareSeqNodeWrappingKey // note that this wrapping is different and not related to ResourceList wrapping WrapBareSeqNode bool }
func (r LocalPackageReader) Read() ([]*yaml.RNode, error)
Read reads the Resources.
LocalPackageSkipFileFunc is a function which returns true if the file in the package should be ignored by reader. relPath is an OS specific relative path
type LocalPackageSkipFileFunc func(relPath string) bool
LocalPackageWriter writes ResourceNodes to a filesystem
type LocalPackageWriter struct { Kind string `yaml:"kind,omitempty"` // PackagePath is the path to the package directory. PackagePath string `yaml:"path,omitempty"` // KeepReaderAnnotations if set will retain the annotations set by LocalPackageReader KeepReaderAnnotations bool `yaml:"keepReaderAnnotations,omitempty"` // ClearAnnotations will clear annotations before writing the resources ClearAnnotations []string `yaml:"clearAnnotations,omitempty"` // FileSystem can be used to mock the disk file system. FileSystem filesys.FileSystemOrOnDisk }
func (r LocalPackageWriter) Write(nodes []*yaml.RNode) error
PackageBuffer implements Reader and Writer, storing Resources in a local field.
type PackageBuffer struct { Nodes []*yaml.RNode }
func (r *PackageBuffer) Read() ([]*yaml.RNode, error)
func (r *PackageBuffer) Write(nodes []*yaml.RNode) error
Pipeline reads Resource Configuration from a set of Inputs, applies some transformation filters, and writes the results to a set of Outputs.
Analogous to http://www.linfo.org/pipes.html
type Pipeline struct { // Inputs provide sources for Resource Configuration to be read. Inputs []Reader `yaml:"inputs,omitempty"` // Filters are transformations applied to the Resource Configuration. // They are applied in the order they are specified. // Analogous to http://www.linfo.org/filters.html Filters []Filter `yaml:"filters,omitempty"` // Outputs are where the transformed Resource Configuration is written. Outputs []Writer `yaml:"outputs,omitempty"` // ContinueOnEmptyResult configures what happens when a filter in the pipeline // returns an empty result. // If it is false (default), subsequent filters will be skipped and the result // will be returned immediately. This is useful as an optimization when you // know that subsequent filters will not alter the empty result. // If it is true, the empty result will be provided as input to the next // filter in the list. This is useful when subsequent functions in the // pipeline may generate new resources. ContinueOnEmptyResult bool `yaml:"continueOnEmptyResult,omitempty"` }
func (p Pipeline) Execute() error
Execute executes each step in the sequence, returning immediately after encountering any error as part of the Pipeline.
func (p Pipeline) ExecuteWithCallback(callback PipelineExecuteCallbackFunc) error
ExecuteWithCallback executes each step in the sequence, returning immediately after encountering any error as part of the Pipeline. The callback will be called each time a step succeeds.
PipelineExecuteCallbackFunc defines a callback function that will be called each time a step in the pipeline succeeds.
type PipelineExecuteCallbackFunc = func(op Filter)
Reader reads ResourceNodes. Analogous to io.Reader.
type Reader interface { Read() ([]*yaml.RNode, error) }
ReaderWriter implements both Reader and Writer interfaces
type ReaderWriter interface { Reader Writer }
ResourceNodeSlice is a collection of ResourceNodes. While ResourceNodeSlice has no inherent constraints on ordering or uniqueness, specific Readers, Filters or Writers may have constraints.
type ResourceNodeSlice []*yaml.RNode
func (o ResourceNodeSlice) Read() ([]*yaml.RNode, error)
TrackableFilter is an extension of Filter which is also capable of tracking which fields were mutated by the filter.
type TrackableFilter interface { Filter WithMutationTracker(func(key, value, tag string, node *yaml.RNode)) }
type TreeStructure string
const ( // TreeStructurePackage configures TreeWriter to generate the tree structure off of the // Resources packages. TreeStructurePackage TreeStructure = "directory" // TreeStructureOwners configures TreeWriter to generate the tree structure off of the // Resource owners. TreeStructureGraph TreeStructure = "owners" )
TreeWriter prints the package structured as a tree. TODO(pwittrock): test this package better. it is lower-risk since it is only
used for printing rather than updating or editing.
type TreeWriter struct { Writer io.Writer Root string Fields []TreeWriterField Structure TreeStructure OpenAPIFileName string }
func (p TreeWriter) Write(nodes []*yaml.RNode) error
Write writes the ascii tree to p.Writer
TreeWriterField configures a Resource field to be included in the tree
type TreeWriterField struct { yaml.PathMatcher Name string SubName string }
Writer writes ResourceNodes. Analogous to io.Writer.
type Writer interface { Write([]*yaml.RNode) error }
WriterFunc implements a Writer as a function.
type WriterFunc func([]*yaml.RNode) error
func (fn WriterFunc) Write(o []*yaml.RNode) error