fieldspec

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: Apache-2.0 Imports: 6 Imported by: 7

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

func GetGVK

func GetGVK(meta yaml.ResourceMeta) resid.Gvk

GetGVK parses the metadata into a GVK

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

func (Filter) Filter

func (fltr Filter) Filter(obj *yaml.RNode) (*yaml.RNode, error)

Jump to

Keyboard shortcuts

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