Documentation ¶
Overview ¶
Package fsslice contains a yaml.Filter to modify a resource using an FsSlice to identify fields to be updated within the resource.
Copyright 2019 The Kubernetes Authors. SPDX-License-Identifier: Apache-2.0
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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 uses an FsSlice to modify fields on a single object
Example ¶
package main import ( "bytes" "log" "os" "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: fsslice.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.