...

Package filters

import "sigs.k8s.io/kustomize/kyaml/kio/filters"
Overview
Index
Subdirectories

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 DefaultGVKNNMatcher
    func (dm *DefaultGVKNNMatcher) IsSameResource(node1, node2 *yaml.RNode) bool
type DefaultResourceHandler
    func (*DefaultResourceHandler) Handle(original, updated, dest *yaml.RNode) (ResourceMergeStrategy, error)
type FileSetter
    func (f *FileSetter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)
type FilenameFmtVerb
type FormatFilter
    func (f FormatFilter) Filter(slice []*yaml.RNode) ([]*yaml.RNode, error)
type FormattingStrategy
type GrepFilter
    func (f GrepFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)
type GrepType
type IsLocalConfig
    func (c *IsLocalConfig) Filter(inputs []*yaml.RNode) ([]*yaml.RNode, error)
type KFilter
    func (t KFilter) MarshalYAML() (interface{}, error)
    func (t *KFilter) UnmarshalYAML(unmarshal func(interface{}) error) error
type MatchFilter
    func (f MatchFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)
type MatchModifyFilter
    func (f MatchModifyFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)
type Merge3
    func (m Merge3) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)
    func (m Merge3) Merge() error
type MergeFilter
    func (c MergeFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)
type Modifier
    func (f Modifier) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)
type ResourceHandler
type ResourceMatcher
type ResourceMergeStrategy
type StripCommentsFilter
    func (f StripCommentsFilter) Filter(slice []*yaml.RNode) ([]*yaml.RNode, error)

Package files

filters.go fmtr.go grep.go local.go merge.go merge3.go modify.go stripcomments.go

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

Filters are the list of known filters for unmarshalling a filter into a concrete implementation.

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{} },
}

func FormatFileOrDirectory

func FormatFileOrDirectory(path string) error

FormatFileOrDirectory reads the file or directory and formats each file's contents by writing it back to the file.

func FormatInput

func FormatInput(input io.Reader) (*bytes.Buffer, error)

FormatInput returns the formatted input.

type DefaultGVKNNMatcher

DefaultGVKNNMatcher holds the default matching of resources implementation based on Group, Version, Kind, Name and Namespace of the resource

type DefaultGVKNNMatcher struct {
    // 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
}

func (*DefaultGVKNNMatcher) IsSameResource

func (dm *DefaultGVKNNMatcher) IsSameResource(node1, node2 *yaml.RNode) bool

IsSameResource returns true if metadata of node1 and metadata of node2 belongs to same logical resource

type DefaultResourceHandler

DefaultResourceHandler is the default implementation of the ResourceHandler interface. It uses the following rules: * Keep dest if resource only exists in dest. * Keep updated if resource added in updated. * Delete dest if updated has been deleted. * Don't add the resource back if removed from dest. * Otherwise merge.

type DefaultResourceHandler struct{}

func (*DefaultResourceHandler) Handle

func (*DefaultResourceHandler) Handle(original, updated, dest *yaml.RNode) (ResourceMergeStrategy, error)

type FileSetter

FileSetter sets the file name and mode annotations on Resources.

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"`
}

func (*FileSetter) Filter

func (f *FileSetter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

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 FormatFilter struct {
    Process   func(n *yaml.Node) error
    UseSchema bool
}

func (FormatFilter) Filter

func (f FormatFilter) Filter(slice []*yaml.RNode) ([]*yaml.RNode, error)

type FormattingStrategy

type FormattingStrategy = string

type GrepFilter

GrepFilter filters RNodes with a matching field

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)
}

func (GrepFilter) Filter

func (f GrepFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

type GrepType

type GrepType int
const (
    Regexp GrepType = 1 << iota
    GreaterThanEq
    GreaterThan
    LessThan
    LessThanEq
)

type IsLocalConfig

IsLocalConfig filters Resources using the config.kubernetes.io/local-config annotation

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"`
}

func (*IsLocalConfig) Filter

func (c *IsLocalConfig) Filter(inputs []*yaml.RNode) ([]*yaml.RNode, error)

Filter implements kio.Filter

type KFilter

filter wraps a kio.filter so that it can be unmarshalled from yaml.

type KFilter struct {
    kio.Filter
}

func (KFilter) MarshalYAML

func (t KFilter) MarshalYAML() (interface{}, error)

func (*KFilter) UnmarshalYAML

func (t *KFilter) UnmarshalYAML(unmarshal func(interface{}) error) error

type MatchFilter

type MatchFilter struct {
    Kind string `yaml:"kind,omitempty"`

    Filters yaml.YFilters `yaml:"pipeline,omitempty"`
}

func (MatchFilter) Filter

func (f MatchFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

type MatchModifyFilter

type MatchModifyFilter struct {
    Kind string `yaml:"kind,omitempty"`

    MatchFilters []yaml.YFilters `yaml:"match,omitempty"`

    ModifyFilters yaml.YFilters `yaml:"modify,omitempty"`
}

func (MatchModifyFilter) Filter

func (f MatchModifyFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

type Merge3

Merge3 performs a 3-way merge on the original, updated, and destination packages.

type Merge3 struct {
    OriginalPath   string
    UpdatedPath    string
    DestPath       string
    MatchFilesGlob []string
    Matcher        ResourceMatcher
    Handler        ResourceHandler
}

func (Merge3) Filter

func (m Merge3) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)

Filter combines Resources with the same GVK + N + NS into tuples, and then merges them

func (Merge3) Merge

func (m Merge3) Merge() error

type MergeFilter

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 MergeFilter struct {
    Reverse bool
}

func (MergeFilter) Filter

func (c MergeFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

MergeFilter implements kio.Filter by merging Resources with the same G/V/K/NS/N

type Modifier

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 Modifier struct {
    Kind string `yaml:"kind,omitempty"`

    Filters yaml.YFilters `yaml:"pipeline,omitempty"`
}

func (Modifier) Filter

func (f Modifier) Filter(input []*yaml.RNode) ([]*yaml.RNode, error)

type ResourceHandler

ResourceHandler interface is used to determine what should be done for a resource once the versions in original, updated and dest has been identified based on the ResourceMatcher. This allows users to customize what should be the result in dest if a resource has been deleted from upstream.

type ResourceHandler interface {
    Handle(original, updated, dest *yaml.RNode) (ResourceMergeStrategy, error)
}

type ResourceMatcher

ResourceMatcher interface is used to match two resources based on IsSameResource implementation This is the way to group same logical resources in upstream, local and origin for merge The default way to group them is using GVKNN similar to how kubernetes server identifies resources Users of this library might have their own interpretation of grouping similar resources for e.g. if consumer adds a name-prefix to local resource, it should not be treated as new resource for updates etc. Hence, the callers of this library may pass different implementation for IsSameResource

type ResourceMatcher interface {
    IsSameResource(node1, node2 *yaml.RNode) bool
}

type ResourceMergeStrategy

ResourceMergeStrategy is the return type from the Handle function in the ResourceHandler interface. It determines which version of a resource should be included in the output (if any).

type ResourceMergeStrategy int
const (
    // Merge means the output to dest should be the 3-way merge of original,
    // updated and dest.
    Merge ResourceMergeStrategy = iota
    // KeepDest means the version of the resource in dest should be the output.
    KeepDest
    // KeepUpdated means the version of the resource in updated should be the
    // output.
    KeepUpdated
    // KeepOriginal means the version of the resource in original should be the
    // output.
    KeepOriginal
    // Skip means the resource should not be included in the output.
    Skip
)

type StripCommentsFilter

type StripCommentsFilter struct{}

func (StripCommentsFilter) Filter

func (f StripCommentsFilter) Filter(slice []*yaml.RNode) ([]*yaml.RNode, error)

Subdirectories

Name Synopsis
..
testyaml Package testyaml contains test data and libraries for formatting Kubernetes configuration