filters

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2020 License: Apache-2.0 Imports: 13 Imported by: 42

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

View Source
const DefaultFilenamePattern = "%n_%k.yaml"
View Source
const LocalConfigAnnotation = "config.kubernetes.io/local-config"

Variables

View Source
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

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.

func GetContainerName

func GetContainerName(n *yaml.RNode) (string, string)

GetContainerName returns the container image for an API if one exists

Types

type ContainerFilter

type ContainerFilter struct {

	// Image is the container image to use to create a container.
	Image string `yaml:"image,omitempty"`

	// Network is the container network to use.
	Network string `yaml:"network,omitempty"`

	// StorageMounts is a list of storage options that the container will have mounted.
	StorageMounts []StorageMount

	// Config is the API configuration for the container and passed through the
	// API_CONFIG env var to the container.
	// Typically a Kubernetes style Resource Config.
	Config *yaml.RNode `yaml:"config,omitempty"`
	// contains filtered or unexported fields
}

ContainerFilter filters Resources using a container image. The container must start a process that reads the list of input Resources from stdin, reads the Configuration from the env API_CONFIG, and writes the filtered Resources to stdout. If there is a error or validation failure, the process must exit non-zero. The full set of environment variables from the parent process are passed to the container.

func (*ContainerFilter) Filter

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

GrepFilter implements kio.GrepFilter

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.

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

func (FormatFilter) Filter

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

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

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

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

func (*IsLocalConfig) Filter

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

Filter implements kio.Filter

type IsReconcilerFilter

type IsReconcilerFilter struct {
	// ExcludeReconcilers if set to true, then Reconcilers will be excluded -- e.g.
	// Resources with a reconcile container through the apiVersion (gcr.io prefix) or
	// through the annotations
	ExcludeReconcilers bool `yaml:"excludeReconcilers,omitempty"`

	// IncludeNonReconcilers if set to true, the NonReconciler will be included.
	IncludeNonReconcilers bool `yaml:"includeNonReconcilers,omitempty"`
}

IsReconcilerFilter filters Resources based on whether or not they are Reconciler Resource. Resources with an apiVersion starting with '*.gcr.io', 'gcr.io' or 'docker.io' are considered Reconciler Resources.

func (*IsReconcilerFilter) Filter

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

Filter implements kio.Filter

type KFilter

type KFilter struct {
	kio.Filter
}

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

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

type Merge3 struct {
	OriginalPath   string
	UpdatedPath    string
	DestPath       string
	MatchFilesGlob []string
}

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

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

type MergeFilter struct {
	Reverse bool
}

GrepFilter 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

func (MergeFilter) Filter

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

GrepFilter implements kio.GrepFilter by merge Resources with the same G/V/K/NS/N

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.

func (Modifier) Filter

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

type StorageMount

type StorageMount struct {
	// Type of mount e.g. bind mount, local volume, etc.
	MountType string

	// Source for the storage to be mounted.
	// For named volumes, this is the name of the volume.
	// For anonymous volumes, this field is omitted (empty string).
	// For bind mounts, this is the path to the file or directory on the host.
	Src string

	// The path where the file or directory is mounted in the container.
	DstPath string
}

StorageMount represents a container's mounted storage option(s)

func (*StorageMount) String

func (s *StorageMount) String() string

type StripCommentsFilter

type StripCommentsFilter struct{}

func (StripCommentsFilter) Filter

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

Directories

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL