fsslice

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 5 Imported by: 12

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

func GetGVK

func GetGVK(meta yaml.ResourceMeta) resid.Gvk

GetGVK parses the metadata into a GVK

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

func (Filter) Filter

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

type SetFn

type SetFn func(*yaml.RNode) error

SetFn sets a value

func SetEntry

func SetEntry(key, value, tag string) SetFn

SetEntry returns a SetFn to set an entry in a map

func SetScalar

func SetScalar(value string) SetFn

SetScalar returns a SetFn to set a scalar value

Jump to

Keyboard shortcuts

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