Documentation ¶
Overview ¶
Package fieldspec contains a yaml.Filter to modify a resource that matches the FieldSpec.
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 { // FieldSpec contains the path to the value to set. FieldSpec types.FieldSpec `yaml:"fieldSpec"` // Set the field using this function SetValue filtersutil.SetFn // CreateKind defines the type of node to create if the field is not found CreateKind yaml.Kind CreateTag string // contains filtered or unexported fields }
Filter applies a single fieldSpec to a single object Filter stores internal state and should not be reused
Example ¶
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 := Filter{ CreateKind: yaml.ScalarNode, SetValue: filtersutil.SetScalar("green"), FieldSpec: 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.