Documentation ¶
Overview ¶
Package fsslice contains a yaml.Filter to modify a resource if it matches one or more FieldSpec entries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct { // FieldSpecList list of FieldSpecs to set FsSlice types.FsSlice `yaml:"fsSlice"` // SetValue is called on each field that matches one of the FieldSpecs SetValue filtersutil.SetFn // CreateKind is used to create fields that do not exist CreateKind yaml.Kind // CreateTag is used to set the tag if encountering a null field CreateTag string }
Filter ranges over an FsSlice to modify fields on a single object. An FsSlice is a range of FieldSpecs. A FieldSpec is a GVK plus a path.
Example ¶
package main import ( "bytes" "log" "os" "sigs.k8s.io/kustomize/api/filters/filtersutil" "sigs.k8s.io/kustomize/api/filters/fsslice" "sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/yaml" ) func main() { in := &kio.ByteReader{ Reader: bytes.NewBufferString(` apiVersion: example.com/v1 kind: Foo metadata: name: instance --- apiVersion: example.com/v1 kind: Bar metadata: name: instance `), } fltr := fsslice.Filter{ CreateKind: yaml.ScalarNode, SetValue: filtersutil.SetScalar("green"), FsSlice: []types.FieldSpec{ {Path: "a/b", CreateIfNotPresent: true}, }, } err := kio.Pipeline{ Inputs: []kio.Reader{in}, Filters: []kio.Filter{kio.FilterAll(fltr)}, Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}}, }.Execute() if err != nil { log.Fatal(err) } }
Output: apiVersion: example.com/v1 kind: Foo metadata: name: instance a: b: green --- apiVersion: example.com/v1 kind: Bar metadata: name: instance a: b: green
Click to show internal directories.
Click to hide internal directories.