package annotations

import "sigs.k8s.io/kustomize/api/filters/annotations"

Package annotations contains a kio.Filter implementation of the kustomize annotations transformer.

Index

Examples

Types

type Filter

type Filter struct {
	// Annotations is the set of annotations to apply to the inputs
	Annotations annoMap `yaml:"annotations,omitempty"`

	// FsSlice contains the FieldSpecs to locate the namespace field
	FsSlice types.FsSlice
	// contains filtered or unexported fields
}
Example

Code:

{
	fss := builtinconfig.MakeDefaultConfig().CommonAnnotations
	err := kio.Pipeline{
		Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo
metadata:
  name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
`)}},
		Filters: []kio.Filter{Filter{
			Annotations: map[string]string{
				"foo":          "bar",
				"booleanValue": "true",
				"numberValue":  "42",
			},
			FsSlice: fss,
		}},
		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
	//   annotations:
	//     booleanValue: "true"
	//     foo: bar
	//     numberValue: "42"
	// ---
	// apiVersion: example.com/v1
	// kind: Bar
	// metadata:
	//   name: instance
	//   annotations:
	//     booleanValue: "true"
	//     foo: bar
	//     numberValue: "42"
}

Output:

apiVersion: example.com/v1
kind: Foo
metadata:
  name: instance
  annotations:
    booleanValue: "true"
    foo: bar
    numberValue: "42"
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
  annotations:
    booleanValue: "true"
    foo: bar
    numberValue: "42"

func (Filter) Filter

func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)

func (*Filter) WithMutationTracker

func (f *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode))

WithMutationTracker registers a callback which will be invoked each time a field is mutated

Source Files

annotations.go doc.go

Version
v0.20.0 (latest)
Published
Jun 28, 2025
Platform
linux/amd64
Imports
5 packages
Last checked
3 days ago

Tools for package owners.