Documentation ¶
Overview ¶
Package yamlfmt contains libraries for formatting yaml files containing Kubernetes Resource configuration.
Yaml files are formatted by: - Sorting fields and map values - Sorting unordered lists for whitelisted types - Applying a canonical yaml Style
Fields are ordered using a relative ordering applied to commonly encountered Resource fields. All Resources, including non-builtin Resources such as CRDs, share the same field precedence.
Fields that do not appear in the explicit ordering are ordered lexicographically.
A subset of well known known unordered lists are sorted by element field values.
Package merge contains libraries for merging Resources and Patches
Index ¶
- Constants
- Variables
- func FormatFileOrDirectory(path string) error
- func FormatInput(input io.Reader) (*bytes.Buffer, error)
- type FileSetter
- type FilenameFmtVerb
- type FormatFilter
- type FormattingStrategy
- type GrepFilter
- type GrepType
- type IsLocalConfig
- type KFilter
- type MatchFilter
- type MatchModifyFilter
- type Merge3
- type MergeFilter
- type Modifier
- type StripCommentsFilter
Constants ¶
const ( // NoFmtAnnotation determines if the resource should be formatted. FmtAnnotation string = "config.kubernetes.io/formatting" // FmtStrategyStandard means the resource will be formatted according // to the default rules. FmtStrategyStandard FormattingStrategy = "standard" // FmtStrategyNone means the resource will not be formatted. FmtStrategyNone FormattingStrategy = "none" )
const DefaultFilenamePattern = "%n_%k.yaml"
const LocalConfigAnnotation = "config.kubernetes.io/local-config"
Variables ¶
var Filters = map[string]func() kio.Filter{ "FileSetter": func() kio.Filter { return &FileSetter{} }, "FormatFilter": func() kio.Filter { return &FormatFilter{} }, "GrepFilter": func() kio.Filter { return GrepFilter{} }, "MatchModifier": func() kio.Filter { return &MatchModifyFilter{} }, "Modifier": func() kio.Filter { return &Modifier{} }, }
Filters are the list of known filters for unmarshalling a filter into a concrete implementation.
Functions ¶
func FormatFileOrDirectory ¶
FormatFileOrDirectory reads the file or directory and formats each file's contents by writing it back to the file.
Types ¶
type FileSetter ¶
type FileSetter struct { Kind string `yaml:"kind,omitempty"` // FilenamePattern is the pattern to use for generating filenames. FilenameFmtVerb // FielnameFmtVerbs may be specified to substitute Resource metadata into the filename. FilenamePattern string `yaml:"filenamePattern,omitempty"` // Mode is the filemode to write. Mode string `yaml:"mode,omitempty"` // Override will override the existing filename if it is set on the pattern. // Otherwise the existing filename is kept. Override bool `yaml:"override,omitempty"` }
FileSetter sets the file name and mode annotations on Resources.
type FilenameFmtVerb ¶
type FilenameFmtVerb string
const ( // KindFmt substitutes kind KindFmt FilenameFmtVerb = "%k" // NameFmt substitutes metadata.name NameFmt FilenameFmtVerb = "%n" // NamespaceFmt substitutes metdata.namespace NamespaceFmt FilenameFmtVerb = "%s" )
type FormatFilter ¶
type FormattingStrategy ¶ added in v0.1.12
type FormattingStrategy = string
type GrepFilter ¶
type GrepFilter struct { Path []string `yaml:"path,omitempty"` Value string `yaml:"value,omitempty"` MatchType GrepType `yaml:"matchType,omitempty"` InvertMatch bool `yaml:"invertMatch,omitempty"` Compare func(a, b string) (int, error) }
GrepFilter filters RNodes with a matching field
type IsLocalConfig ¶
type IsLocalConfig struct { // IncludeLocalConfig will include local-config if set to true IncludeLocalConfig bool `yaml:"includeLocalConfig,omitempty"` // ExcludeNonLocalConfig will exclude non local-config if set to true ExcludeNonLocalConfig bool `yaml:"excludeNonLocalConfig,omitempty"` }
IsLocalConfig filters Resources using the config.kubernetes.io/local-config annotation
type KFilter ¶
filter wraps a kio.filter so that it can be unmarshalled from yaml.
func (KFilter) MarshalYAML ¶
func (*KFilter) UnmarshalYAML ¶
type MatchFilter ¶
type MatchModifyFilter ¶
type Merge3 ¶
type Merge3 struct { OriginalPath string UpdatedPath string DestPath string MatchFilesGlob []string // MergeOnPath will use the relative filepath as part of the merge key. // This may be necessary if the directory contains multiple copies of // the same resource, or resources patches. MergeOnPath bool }
Merge3 performs a 3-way merge on the original, updated, and destination packages.
type MergeFilter ¶
type MergeFilter struct {
Reverse bool
}
MergeFilter merges Resources with the Group/Version/Kind/Namespace/Name together using a 2-way merge strategy.
- Fields set to null in the source will be cleared from the destination - Fields with matching keys will be merged recursively - Lists with an associative key (e.g. name) will have their elements merged using the key - List without an associative key will have the dest list replaced by the source list
type Modifier ¶
type Modifier struct { Kind string `yaml:"kind,omitempty"` Filters yaml.YFilters `yaml:"pipeline,omitempty"` }
Modifier modifies the input Resources by invoking the provided pipeline. Modifier will return any Resources for which the pipeline does not return an error.
type StripCommentsFilter ¶
type StripCommentsFilter struct{}